From 06f7f960672618f4cc76bf7f7213e310861ac06e Mon Sep 17 00:00:00 2001 From: chengzw <40051120+cr7258@users.noreply.github.com> Date: Tue, 18 Jul 2023 19:01:48 +0800 Subject: Set default value of prometheus_label to None (#101) * set default value of prometheus_label to None * update doc * optimize validate_cluster_name check logic --- README.md | 8 +------- .../prometheus/metrics_service/prometheus_metrics_service.py | 3 +++ robusta_krr/core/models/config.py | 2 +- robusta_krr/main.py | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a465f6b..677354c 100644 --- a/README.md +++ b/README.md @@ -357,13 +357,7 @@ If your Prometheus monitors multiple clusters we require the label you defined f 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 -``` - -If you are using a label for your cluster other than `cluster` for example the label `env: "dev-tests"` you can specify it by running: - -```sh -krr.py simple -p http://my-centralized-prometheus:9090 --prometheus-label env -l dev-tests +krr.py simple -p http://my-centralized-prometheus:9090 --prometheus-label cluster -l my-cluster-name ```
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 ecc3e5d..5b22472 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 @@ -117,6 +117,9 @@ class PrometheusMetricsService(MetricsService): return await loop.run_in_executor(self.executor, lambda: self.prometheus.custom_query(query=query)) def validate_cluster_name(self): + if not self.config.prometheus_cluster_label and not self.config.prometheus_label: + return + cluster_label = self.config.prometheus_cluster_label cluster_names = self.get_cluster_names() diff --git a/robusta_krr/core/models/config.py b/robusta_krr/core/models/config.py index 61c8b4f..36eb152 100644 --- a/robusta_krr/core/models/config.py +++ b/robusta_krr/core/models/config.py @@ -28,7 +28,7 @@ class Config(pd.BaseSettings): prometheus_other_headers: dict[str, str] = pd.Field(default_factory=dict) prometheus_ssl_enabled: bool = pd.Field(False) prometheus_cluster_label: Optional[str] = pd.Field(None) - prometheus_label: str = pd.Field("cluster") + prometheus_label: Optional[str] = pd.Field(None) # Threading settings max_workers: int = pd.Field(6, ge=1) diff --git a/robusta_krr/main.py b/robusta_krr/main.py index 05966ee..db97433 100644 --- a/robusta_krr/main.py +++ b/robusta_krr/main.py @@ -113,7 +113,7 @@ def load_commands() -> None: rich_help_panel="Prometheus Settings", ), prometheus_label: str = typer.Option( - 'cluster', + None, "--prometheus-label", help="The label in prometheus used to differentiate clusters. (Only relevant for centralized prometheus)", rich_help_panel="Prometheus Settings", -- cgit v1.2.3