From 31f04aca0b88fbc5d8f1f66a16a4bfc45c0722b0 Mon Sep 17 00:00:00 2001 From: avi robusta Date: Tue, 13 Jun 2023 16:33:40 +0300 Subject: added cluster name param for centralized support --- .../core/integrations/prometheus/metrics/base_metric.py | 11 +++++++++++ .../core/integrations/prometheus/metrics/cpu_metric.py | 2 ++ .../core/integrations/prometheus/metrics/memory_metric.py | 2 ++ .../prometheus/metrics_service/base_metric_service.py | 6 +++++- .../prometheus/metrics_service/prometheus_metrics_service.py | 5 ++++- robusta_krr/core/models/config.py | 1 + robusta_krr/core/runner.py | 11 +++++++++++ robusta_krr/main.py | 8 ++++++++ 8 files changed, 44 insertions(+), 2 deletions(-) diff --git a/robusta_krr/core/integrations/prometheus/metrics/base_metric.py b/robusta_krr/core/integrations/prometheus/metrics/base_metric.py index 7118d8c..b036218 100644 --- a/robusta_krr/core/integrations/prometheus/metrics/base_metric.py +++ b/robusta_krr/core/integrations/prometheus/metrics/base_metric.py @@ -30,6 +30,17 @@ class BaseMetricLoader(Configurable, abc.ABC): super().__init__(config) self.prometheus = prometheus + def get_prometheus_cluster_label(self) -> str: + """ + Generates the cluster label for querying a centralized Prometheus + + Returns: + str: a promql safe label string for querying the cluster. + """ + if self.config.prometheus_cluster_label is None: + return '' + return f', cluster="{self.config.prometheus_cluster_label}"' + @abc.abstractmethod def get_query(self, object: K8sObjectData) -> str: """ diff --git a/robusta_krr/core/integrations/prometheus/metrics/cpu_metric.py b/robusta_krr/core/integrations/prometheus/metrics/cpu_metric.py index 67ec98a..c00047a 100644 --- a/robusta_krr/core/integrations/prometheus/metrics/cpu_metric.py +++ b/robusta_krr/core/integrations/prometheus/metrics/cpu_metric.py @@ -9,10 +9,12 @@ from .base_metric import bind_metric class CPUMetricLoader(BaseFilteredMetricLoader): def get_query(self, object: K8sObjectData) -> str: pods_selector = "|".join(pod.name for pod in object.pods) + cluster_label = self.get_prometheus_cluster_label() return ( "sum(irate(container_cpu_usage_seconds_total{" f'namespace="{object.namespace}", ' f'pod=~"{pods_selector}", ' f'container="{object.container}"' + f'{cluster_label}' "}[5m])) by (container, pod, job)" ) diff --git a/robusta_krr/core/integrations/prometheus/metrics/memory_metric.py b/robusta_krr/core/integrations/prometheus/metrics/memory_metric.py index ddb056a..dfbbc08 100644 --- a/robusta_krr/core/integrations/prometheus/metrics/memory_metric.py +++ b/robusta_krr/core/integrations/prometheus/metrics/memory_metric.py @@ -9,10 +9,12 @@ from .base_metric import bind_metric class MemoryMetricLoader(BaseFilteredMetricLoader): def get_query(self, object: K8sObjectData) -> str: pods_selector = "|".join(pod.name for pod in object.pods) + cluster_label = self.get_prometheus_cluster_label() return ( "sum(container_memory_working_set_bytes{" f'namespace="{object.namespace}", ' f'pod=~"{pods_selector}", ' f'container="{object.container}"' + f'{cluster_label}' "}) by (container, pod, job)" ) diff --git a/robusta_krr/core/integrations/prometheus/metrics_service/base_metric_service.py b/robusta_krr/core/integrations/prometheus/metrics_service/base_metric_service.py index 21b3706..0b41f84 100644 --- a/robusta_krr/core/integrations/prometheus/metrics_service/base_metric_service.py +++ b/robusta_krr/core/integrations/prometheus/metrics_service/base_metric_service.py @@ -1,6 +1,6 @@ import abc import datetime -from typing import Optional +from typing import Optional, List from kubernetes.client.api_client import ApiClient @@ -38,6 +38,10 @@ class MetricsService(Configurable, abc.ABC): classname = self.__class__.__name__ return classname.replace("MetricsService", "") if classname != MetricsService.__name__ else classname + @abc.abstractmethod + async def get_cluster_names(self) -> Optional[List[str]]: + ... + @abc.abstractmethod async def gather_data( self, diff --git a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py index c5d42ef..7ceb766 100644 --- a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py +++ b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py @@ -1,6 +1,6 @@ import asyncio import datetime -from typing import Optional, no_type_check +from typing import Optional, no_type_check, List import requests from kubernetes.client import ApiClient @@ -134,6 +134,9 @@ class PrometheusMetricsService(MetricsService): async def query(self, query: str) -> dict: return await asyncio.to_thread(self.prometheus.custom_query, query=query) + async def get_cluster_names(self) -> Optional[List[str]]: + return await asyncio.to_thread(self.prometheus.get_label_values, label_name="cluster") + async def gather_data( self, object: K8sObjectData, diff --git a/robusta_krr/core/models/config.py b/robusta_krr/core/models/config.py index 6cd0b56..72cf4d8 100644 --- a/robusta_krr/core/models/config.py +++ b/robusta_krr/core/models/config.py @@ -25,6 +25,7 @@ class Config(pd.BaseSettings): prometheus_url: Optional[str] = pd.Field(None) prometheus_auth_header: Optional[str] = pd.Field(None) prometheus_ssl_enabled: bool = pd.Field(False) + prometheus_cluster_label: Optional[str] = pd.Field(None) # Logging Settings format: str diff --git a/robusta_krr/core/runner.py b/robusta_krr/core/runner.py index 7a64bfb..28fd898 100644 --- a/robusta_krr/core/runner.py +++ b/robusta_krr/core/runner.py @@ -13,6 +13,12 @@ from robusta_krr.utils.logo import ASCII_LOGO from robusta_krr.utils.progress_bar import ProgressBar from robusta_krr.utils.version import get_version +class ClusterNotSpecifiedException(Exception): + """ + An exception raised when a cluster is not specified. + """ + pass + class Runner(Configurable): EXPECTED_EXCEPTIONS = (KeyboardInterrupt, PrometheusNotFound) @@ -139,6 +145,11 @@ class Runner(Configurable): async def _collect_result(self) -> Result: clusters = await self._k8s_loader.list_clusters() + if len(clusters) > 1 and self.config.prometheus_url: + # this can only happen for multi-cluster querying a single centeralized prometheus + # In this scenario we dont yet support determining which metrics belong to which cluster so the reccomendation can be incorrect + raise ClusterNotSpecifiedException(f"Must specify only one cluster from {clusters} to for prometheus at {self.config.prometheus_url}") + self.info(f'Using clusters: {clusters if clusters is not None else "inner cluster"}') objects = await self._k8s_loader.list_scannable_objects(clusters) diff --git a/robusta_krr/main.py b/robusta_krr/main.py index dbf12d8..33480e9 100644 --- a/robusta_krr/main.py +++ b/robusta_krr/main.py @@ -91,6 +91,13 @@ def load_commands() -> None: help="Enable SSL for Prometheus requests.", rich_help_panel="Prometheus Settings", ), + prometheus_cluster_label: Optional[str] = typer.Option( + None, + "--prometheus-cluster-label", + "-l", + help="The label in prometheus for your cluster.(Only relevant for centralized prometheus)", + rich_help_panel="Prometheus Settings", + ), format: str = typer.Option("table", "--formatter", "-f", help="Output formatter ({formatters})", rich_help_panel="Logging Settings"), verbose: bool = typer.Option(False, "--verbose", "-v", help="Enable verbose mode", rich_help_panel="Logging Settings"), quiet: bool = typer.Option(False, "--quiet", "-q", help="Enable quiet mode", rich_help_panel="Logging Settings"), @@ -106,6 +113,7 @@ def load_commands() -> None: prometheus_url=prometheus_url, prometheus_auth_header=prometheus_auth_header, prometheus_ssl_enabled=prometheus_ssl_enabled, + prometheus_cluster_label=prometheus_cluster_label, format=format, verbose=verbose, quiet=quiet, -- cgit v1.2.3 From d3b8da1cfb74ee2d28f0617b349a7be5cec2f26e Mon Sep 17 00:00:00 2001 From: avi robusta Date: Tue, 13 Jun 2023 18:17:07 +0300 Subject: Bad cluster label exception --- .../core/integrations/prometheus/__init__.py | 2 +- robusta_krr/core/integrations/prometheus/loader.py | 1 + .../metrics_service/prometheus_metrics_service.py | 28 ++++++++++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/robusta_krr/core/integrations/prometheus/__init__.py b/robusta_krr/core/integrations/prometheus/__init__.py index 3d298c6..aac0103 100644 --- a/robusta_krr/core/integrations/prometheus/__init__.py +++ b/robusta_krr/core/integrations/prometheus/__init__.py @@ -1,2 +1,2 @@ from .loader import MetricsLoader -from .metrics_service.prometheus_metrics_service import CustomPrometheusConnect, PrometheusDiscovery, PrometheusNotFound +from .metrics_service.prometheus_metrics_service import CustomPrometheusConnect, PrometheusDiscovery, PrometheusNotFound, ClusterNotSpecifiedException diff --git a/robusta_krr/core/integrations/prometheus/loader.py b/robusta_krr/core/integrations/prometheus/loader.py index 773e8b7..cb33a4e 100644 --- a/robusta_krr/core/integrations/prometheus/loader.py +++ b/robusta_krr/core/integrations/prometheus/loader.py @@ -62,6 +62,7 @@ class MetricsLoader(Configurable): loader = metric_service_class(config, api_client=api_client, cluster=cluster) loader.check_connection() self.echo(f"{service_name} found") + loader.validate_cluster_name() return loader except MetricsNotFound as e: self.debug(f"{service_name} not found") diff --git a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py index 7ceb766..ed1d65d 100644 --- a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py +++ b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py @@ -49,6 +49,12 @@ class PrometheusNotFound(MetricsNotFound): pass +class ClusterNotSpecifiedException(Exception): + """ + An exception raised when a prometheus requires a cluster label but an invalid one is provided. + """ + + pass class CustomPrometheusConnect(PrometheusConnect): """ @@ -131,11 +137,29 @@ class PrometheusMetricsService(MetricsService): f"Couldn't connect to Prometheus found under {self.prometheus.url}\nCaused by {e.__class__.__name__}: {e})" ) from e + async def query(self, query: str) -> dict: return await asyncio.to_thread(self.prometheus.custom_query, query=query) - async def get_cluster_names(self) -> Optional[List[str]]: - return await asyncio.to_thread(self.prometheus.get_label_values, label_name="cluster") + def validate_cluster_name(self): + cluster_label = self.config.prometheus_cluster_label + cluster_names = self.get_cluster_names() + + if len(cluster_names) <= 1: + # there is only one cluster of metrics in this prometheus + return + + if not cluster_label: + raise ClusterNotSpecifiedException( + f"KRR requires a prometheus_cluster_label to run your query, please select one of the following clusters {cluster_names}" + ) + if cluster_label not in cluster_names: + raise ClusterNotSpecifiedException( + f"prometheus_cluster_label {cluster_label} does not exist, please use one of the following {cluster_names}" + ) + + def get_cluster_names(self) -> Optional[List[str]]: + return self.prometheus.get_label_values(label_name="cluster") async def gather_data( self, -- cgit v1.2.3 From 3d83cf527ba103e3362404217d0361f6ad86047a Mon Sep 17 00:00:00 2001 From: avi robusta Date: Tue, 13 Jun 2023 19:05:07 +0300 Subject: removed stack trace for ClusterNotSpecifiedException --- robusta_krr/core/runner.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/robusta_krr/core/runner.py b/robusta_krr/core/runner.py index 28fd898..48afbd1 100644 --- a/robusta_krr/core/runner.py +++ b/robusta_krr/core/runner.py @@ -4,7 +4,7 @@ from typing import Optional, Union from robusta_krr.core.abstract.strategies import ResourceRecommendation, RunResult from robusta_krr.core.integrations.kubernetes import KubernetesLoader -from robusta_krr.core.integrations.prometheus import MetricsLoader, PrometheusNotFound +from robusta_krr.core.integrations.prometheus import MetricsLoader, PrometheusNotFound, ClusterNotSpecifiedException from robusta_krr.core.models.config import Config from robusta_krr.core.models.objects import K8sObjectData from robusta_krr.core.models.result import MetricsData, ResourceAllocations, ResourceScan, ResourceType, Result @@ -13,13 +13,6 @@ from robusta_krr.utils.logo import ASCII_LOGO from robusta_krr.utils.progress_bar import ProgressBar from robusta_krr.utils.version import get_version -class ClusterNotSpecifiedException(Exception): - """ - An exception raised when a cluster is not specified. - """ - pass - - class Runner(Configurable): EXPECTED_EXCEPTIONS = (KeyboardInterrupt, PrometheusNotFound) @@ -184,5 +177,7 @@ class Runner(Configurable): try: result = await self._collect_result() self._process_result(result) - except Exception: + except ClusterNotSpecifiedException as e: + self.error(e) + except Exception as e: self.console.print_exception(extra_lines=1, max_frames=10) -- cgit v1.2.3 From 6ddb66aa1f3da4ec8821448bae0e45927b9eed20 Mon Sep 17 00:00:00 2001 From: avi robusta Date: Wed, 14 Jun 2023 11:32:47 +0300 Subject: updated the docs --- README.md | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bc1ede3..dc5c278 100644 --- a/README.md +++ b/README.md @@ -274,9 +274,10 @@ krr simple --help -## Prometheus auto-discovery +## Prometheus, Victoria Metrics and Thanos auto-discovery -By default, KRR will try to auto-discover the running Prometheus by scanning those labels: +By default, KRR will try to auto-discover the running Prometheus Victoria Metrics and Thanos. +For discovering prometheus it scan services for those labels: ```python "app=kube-prometheus-stack-prometheus" "app=prometheus,component=server" @@ -286,8 +287,22 @@ By default, KRR will try to auto-discover the running Prometheus by scanning tho "app=rancher-monitoring-prometheus" "app=prometheus-prometheus" ``` +For Thanos its these labels: +```python +"app.kubernetes.io/component=query,app.kubernetes.io/name=thanos", +"app.kubernetes.io/name=thanos-query", +"app=thanos-query", +"app=thanos-querier", +``` +And for Victoria Metrics its the following labels: +```python +"app.kubernetes.io/name=vmsingle", +"app.kubernetes.io/name=victoria-metrics-single", +"app.kubernetes.io/name=vmselect", +"app=vmselect", +``` -If none of those labels result in finding Prometheus, you will get an error and will have to pass the working url explicitly (using the `-p` flag). +If none of those labels result in finding Prometheus, Victoria Metrics or Thanos, you will get an error and will have to pass the working url explicitly (using the `-p` flag).

(back to top)

@@ -309,6 +324,18 @@ krr simple -p http://127.0.0.1:9090

(back to top)

+## Scanning with a centralized Prometheus + +If your Prometheus monitors multiple clusters you we require the label you defined for your cluster in Prometheus. + +For example, if your cluster has the Prometheus label `cluster: "my-cluster-name"` and your prometheus is at url `http://my-centralized-prometheus:9090`, then run this command: + +```sh +krr.py simple -p http://my-centralized-prometheus:9090 -l my-cluster-name +``` + +

(back to top)

+ ## Available formatters -- cgit v1.2.3 From 9584a5d639ed54ad67ea83491b1ef1a82f671b6c Mon Sep 17 00:00:00 2001 From: avi robusta Date: Wed, 14 Jun 2023 12:00:12 +0300 Subject: Better Error messages --- .../prometheus/metrics_service/prometheus_metrics_service.py | 4 ++-- robusta_krr/core/runner.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py index ed1d65d..17b94e0 100644 --- a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py +++ b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py @@ -151,11 +151,11 @@ class PrometheusMetricsService(MetricsService): if not cluster_label: raise ClusterNotSpecifiedException( - f"KRR requires a prometheus_cluster_label to run your query, please select one of the following clusters {cluster_names}" + f"No label specified, Rerun krr with the flag `-l ` where is one of {cluster_names}" ) if cluster_label not in cluster_names: raise ClusterNotSpecifiedException( - f"prometheus_cluster_label {cluster_label} does not exist, please use one of the following {cluster_names}" + f"Label {cluster_label} does not exist, Rerun krr with the flag `-l ` where is one of {cluster_names}" ) def get_cluster_names(self) -> Optional[List[str]]: diff --git a/robusta_krr/core/runner.py b/robusta_krr/core/runner.py index 48afbd1..2c88235 100644 --- a/robusta_krr/core/runner.py +++ b/robusta_krr/core/runner.py @@ -141,7 +141,7 @@ class Runner(Configurable): if len(clusters) > 1 and self.config.prometheus_url: # this can only happen for multi-cluster querying a single centeralized prometheus # In this scenario we dont yet support determining which metrics belong to which cluster so the reccomendation can be incorrect - raise ClusterNotSpecifiedException(f"Must specify only one cluster from {clusters} to for prometheus at {self.config.prometheus_url}") + raise ClusterNotSpecifiedException(f"Cannot scan multiple clusters for this prometheus, Rerun with the flag `-c ` where is one of {clusters}") self.info(f'Using clusters: {clusters if clusters is not None else "inner cluster"}') objects = await self._k8s_loader.list_scannable_objects(clusters) -- cgit v1.2.3 From c7d5dbe0dba5617bf7b97b5ec40a87a09b0b1e44 Mon Sep 17 00:00:00 2001 From: avi robusta Date: Wed, 14 Jun 2023 12:03:17 +0300 Subject: black --- robusta_krr/core/integrations/prometheus/__init__.py | 7 ++++++- .../core/integrations/prometheus/metrics/base_metric.py | 2 +- .../core/integrations/prometheus/metrics/cpu_metric.py | 2 +- .../core/integrations/prometheus/metrics/memory_metric.py | 2 +- .../prometheus/metrics_service/prometheus_metrics_service.py | 11 ++++++----- robusta_krr/core/runner.py | 7 +++++-- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/robusta_krr/core/integrations/prometheus/__init__.py b/robusta_krr/core/integrations/prometheus/__init__.py index aac0103..4b61b1b 100644 --- a/robusta_krr/core/integrations/prometheus/__init__.py +++ b/robusta_krr/core/integrations/prometheus/__init__.py @@ -1,2 +1,7 @@ from .loader import MetricsLoader -from .metrics_service.prometheus_metrics_service import CustomPrometheusConnect, PrometheusDiscovery, PrometheusNotFound, ClusterNotSpecifiedException +from .metrics_service.prometheus_metrics_service import ( + CustomPrometheusConnect, + PrometheusDiscovery, + PrometheusNotFound, + ClusterNotSpecifiedException, +) diff --git a/robusta_krr/core/integrations/prometheus/metrics/base_metric.py b/robusta_krr/core/integrations/prometheus/metrics/base_metric.py index b036218..aea633c 100644 --- a/robusta_krr/core/integrations/prometheus/metrics/base_metric.py +++ b/robusta_krr/core/integrations/prometheus/metrics/base_metric.py @@ -38,7 +38,7 @@ class BaseMetricLoader(Configurable, abc.ABC): str: a promql safe label string for querying the cluster. """ if self.config.prometheus_cluster_label is None: - return '' + return "" return f', cluster="{self.config.prometheus_cluster_label}"' @abc.abstractmethod diff --git a/robusta_krr/core/integrations/prometheus/metrics/cpu_metric.py b/robusta_krr/core/integrations/prometheus/metrics/cpu_metric.py index c00047a..e2d364b 100644 --- a/robusta_krr/core/integrations/prometheus/metrics/cpu_metric.py +++ b/robusta_krr/core/integrations/prometheus/metrics/cpu_metric.py @@ -15,6 +15,6 @@ class CPUMetricLoader(BaseFilteredMetricLoader): f'namespace="{object.namespace}", ' f'pod=~"{pods_selector}", ' f'container="{object.container}"' - f'{cluster_label}' + f"{cluster_label}" "}[5m])) by (container, pod, job)" ) diff --git a/robusta_krr/core/integrations/prometheus/metrics/memory_metric.py b/robusta_krr/core/integrations/prometheus/metrics/memory_metric.py index dfbbc08..5942ec1 100644 --- a/robusta_krr/core/integrations/prometheus/metrics/memory_metric.py +++ b/robusta_krr/core/integrations/prometheus/metrics/memory_metric.py @@ -15,6 +15,6 @@ class MemoryMetricLoader(BaseFilteredMetricLoader): f'namespace="{object.namespace}", ' f'pod=~"{pods_selector}", ' f'container="{object.container}"' - f'{cluster_label}' + f"{cluster_label}" "}) by (container, pod, job)" ) diff --git a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py index 17b94e0..0c31ee6 100644 --- a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py +++ b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py @@ -49,6 +49,7 @@ class PrometheusNotFound(MetricsNotFound): pass + class ClusterNotSpecifiedException(Exception): """ An exception raised when a prometheus requires a cluster label but an invalid one is provided. @@ -56,6 +57,7 @@ class ClusterNotSpecifiedException(Exception): pass + class CustomPrometheusConnect(PrometheusConnect): """ Custom PrometheusConnect class to handle retries. @@ -137,14 +139,13 @@ class PrometheusMetricsService(MetricsService): f"Couldn't connect to Prometheus found under {self.prometheus.url}\nCaused by {e.__class__.__name__}: {e})" ) from e - async def query(self, query: str) -> dict: return await asyncio.to_thread(self.prometheus.custom_query, query=query) def validate_cluster_name(self): cluster_label = self.config.prometheus_cluster_label cluster_names = self.get_cluster_names() - + if len(cluster_names) <= 1: # there is only one cluster of metrics in this prometheus return @@ -152,11 +153,11 @@ class PrometheusMetricsService(MetricsService): if not cluster_label: raise ClusterNotSpecifiedException( f"No label specified, Rerun krr with the flag `-l ` where is one of {cluster_names}" - ) - if cluster_label not in cluster_names: + ) + if cluster_label not in cluster_names: raise ClusterNotSpecifiedException( f"Label {cluster_label} does not exist, Rerun krr with the flag `-l ` where is one of {cluster_names}" - ) + ) def get_cluster_names(self) -> Optional[List[str]]: return self.prometheus.get_label_values(label_name="cluster") diff --git a/robusta_krr/core/runner.py b/robusta_krr/core/runner.py index 2c88235..0cf01fd 100644 --- a/robusta_krr/core/runner.py +++ b/robusta_krr/core/runner.py @@ -13,6 +13,7 @@ from robusta_krr.utils.logo import ASCII_LOGO from robusta_krr.utils.progress_bar import ProgressBar from robusta_krr.utils.version import get_version + class Runner(Configurable): EXPECTED_EXCEPTIONS = (KeyboardInterrupt, PrometheusNotFound) @@ -141,8 +142,10 @@ class Runner(Configurable): if len(clusters) > 1 and self.config.prometheus_url: # this can only happen for multi-cluster querying a single centeralized prometheus # In this scenario we dont yet support determining which metrics belong to which cluster so the reccomendation can be incorrect - raise ClusterNotSpecifiedException(f"Cannot scan multiple clusters for this prometheus, Rerun with the flag `-c ` where is one of {clusters}") - + raise ClusterNotSpecifiedException( + f"Cannot scan multiple clusters for this prometheus, Rerun with the flag `-c ` where is one of {clusters}" + ) + self.info(f'Using clusters: {clusters if clusters is not None else "inner cluster"}') objects = await self._k8s_loader.list_scannable_objects(clusters) -- cgit v1.2.3 From 142b6ac3d310a187cae40e88f1c0c5a7b11b0fe3 Mon Sep 17 00:00:00 2001 From: avi robusta Date: Wed, 14 Jun 2023 12:04:08 +0300 Subject: osort flake8 --- robusta_krr/core/integrations/prometheus/__init__.py | 2 +- .../integrations/prometheus/metrics_service/base_metric_service.py | 2 +- .../prometheus/metrics_service/prometheus_metrics_service.py | 2 +- robusta_krr/core/models/objects.py | 3 ++- robusta_krr/core/runner.py | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/robusta_krr/core/integrations/prometheus/__init__.py b/robusta_krr/core/integrations/prometheus/__init__.py index 4b61b1b..6cec9a6 100644 --- a/robusta_krr/core/integrations/prometheus/__init__.py +++ b/robusta_krr/core/integrations/prometheus/__init__.py @@ -1,7 +1,7 @@ from .loader import MetricsLoader from .metrics_service.prometheus_metrics_service import ( + ClusterNotSpecifiedException, CustomPrometheusConnect, PrometheusDiscovery, PrometheusNotFound, - ClusterNotSpecifiedException, ) diff --git a/robusta_krr/core/integrations/prometheus/metrics_service/base_metric_service.py b/robusta_krr/core/integrations/prometheus/metrics_service/base_metric_service.py index 0b41f84..9ac308b 100644 --- a/robusta_krr/core/integrations/prometheus/metrics_service/base_metric_service.py +++ b/robusta_krr/core/integrations/prometheus/metrics_service/base_metric_service.py @@ -1,6 +1,6 @@ import abc import datetime -from typing import Optional, List +from typing import List, Optional from kubernetes.client.api_client import ApiClient diff --git a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py index 0c31ee6..4f1c6f2 100644 --- a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py +++ b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py @@ -1,6 +1,6 @@ import asyncio import datetime -from typing import Optional, no_type_check, List +from typing import List, Optional, no_type_check import requests from kubernetes.client import ApiClient diff --git a/robusta_krr/core/models/objects.py b/robusta_krr/core/models/objects.py index 72694fd..3fbbc9c 100644 --- a/robusta_krr/core/models/objects.py +++ b/robusta_krr/core/models/objects.py @@ -1,6 +1,7 @@ +from typing import Optional + import pydantic as pd -from typing import Optional from robusta_krr.core.models.allocations import ResourceAllocations diff --git a/robusta_krr/core/runner.py b/robusta_krr/core/runner.py index 0cf01fd..02c505b 100644 --- a/robusta_krr/core/runner.py +++ b/robusta_krr/core/runner.py @@ -4,7 +4,7 @@ from typing import Optional, Union from robusta_krr.core.abstract.strategies import ResourceRecommendation, RunResult from robusta_krr.core.integrations.kubernetes import KubernetesLoader -from robusta_krr.core.integrations.prometheus import MetricsLoader, PrometheusNotFound, ClusterNotSpecifiedException +from robusta_krr.core.integrations.prometheus import ClusterNotSpecifiedException, MetricsLoader, PrometheusNotFound from robusta_krr.core.models.config import Config from robusta_krr.core.models.objects import K8sObjectData from robusta_krr.core.models.result import MetricsData, ResourceAllocations, ResourceScan, ResourceType, Result -- cgit v1.2.3