From 84f9f58973f00a804b6c11ad6e3c8ec3ae5d48b5 Mon Sep 17 00:00:00 2001 From: avi robusta Date: Wed, 14 Jun 2023 12:30:54 +0300 Subject: support custom label name the standard is cluster --- README.md | 6 ++++++ robusta_krr/core/integrations/prometheus/metrics/base_metric.py | 2 +- robusta_krr/core/models/config.py | 1 + robusta_krr/main.py | 7 +++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dc5c278..57f9ce8 100644 --- a/README.md +++ b/README.md @@ -334,6 +334,12 @@ For example, if your cluster has the Prometheus label `cluster: "my-cluster-name krr.py simple -p http://my-centralized-prometheus:9090 -l my-cluster-name ``` +If you are using a label 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 +``` +

(back to top)

diff --git a/robusta_krr/core/integrations/prometheus/metrics/base_metric.py b/robusta_krr/core/integrations/prometheus/metrics/base_metric.py index aea633c..47d33d2 100644 --- a/robusta_krr/core/integrations/prometheus/metrics/base_metric.py +++ b/robusta_krr/core/integrations/prometheus/metrics/base_metric.py @@ -39,7 +39,7 @@ class BaseMetricLoader(Configurable, abc.ABC): """ if self.config.prometheus_cluster_label is None: return "" - return f', cluster="{self.config.prometheus_cluster_label}"' + return f', {self.config.prometheus_label}="{self.config.prometheus_cluster_label}"' @abc.abstractmethod def get_query(self, object: K8sObjectData) -> str: diff --git a/robusta_krr/core/models/config.py b/robusta_krr/core/models/config.py index 72cf4d8..22a5d41 100644 --- a/robusta_krr/core/models/config.py +++ b/robusta_krr/core/models/config.py @@ -26,6 +26,7 @@ class Config(pd.BaseSettings): prometheus_auth_header: Optional[str] = pd.Field(None) prometheus_ssl_enabled: bool = pd.Field(False) prometheus_cluster_label: Optional[str] = pd.Field(None) + prometheus_label: Optional[str] = pd.Field(None) # Logging Settings format: str diff --git a/robusta_krr/main.py b/robusta_krr/main.py index 33480e9..968557a 100644 --- a/robusta_krr/main.py +++ b/robusta_krr/main.py @@ -98,6 +98,12 @@ def load_commands() -> None: help="The label in prometheus for your cluster.(Only relevant for centralized prometheus)", rich_help_panel="Prometheus Settings", ), + prometheus_label: Optional[str] = typer.Option( + 'cluster', + "--prometheus-label", + help="The label in prometheus used to differentiate clusters. (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"), @@ -114,6 +120,7 @@ def load_commands() -> None: prometheus_auth_header=prometheus_auth_header, prometheus_ssl_enabled=prometheus_ssl_enabled, prometheus_cluster_label=prometheus_cluster_label, + prometheus_label=prometheus_label, format=format, verbose=verbose, quiet=quiet, -- cgit v1.2.3