-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:robusta-dev/krr
- Loading branch information
Showing
4 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
robusta_krr/core/integrations/prometheus/metrics_service/mimir_metrics_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Optional | ||
|
||
from kubernetes.client import ApiClient | ||
from prometrix import MetricsNotFound | ||
|
||
from robusta_krr.utils.service_discovery import MetricsServiceDiscovery | ||
|
||
from .prometheus_metrics_service import PrometheusMetricsService | ||
|
||
class MimirMetricsDiscovery(MetricsServiceDiscovery): | ||
def find_metrics_url(self, *, api_client: Optional[ApiClient] = None) -> Optional[str]: | ||
""" | ||
Finds the Mimir Metrics URL using selectors. | ||
Args: | ||
api_client (Optional[ApiClient]): A Kubernetes API client. Defaults to None. | ||
Returns: | ||
Optional[str]: The discovered Mimir Metrics URL, or None if not found. | ||
""" | ||
return super().find_url( | ||
selectors=[ | ||
"app.kubernetes.io/name=mimir,app.kubernetes.io/component=query-frontend", | ||
] | ||
) | ||
|
||
|
||
class MimirMetricsService(PrometheusMetricsService): | ||
""" | ||
A class for fetching metrics from Mimir Metrics. | ||
""" | ||
|
||
service_discovery = MimirMetricsDiscovery | ||
url_postfix = "/prometheus" | ||
additional_headers = {"X-Scope-OrgID": "anonymous"} | ||
|
||
def check_connection(self): | ||
""" | ||
Checks the connection to Prometheus. | ||
Raises: | ||
MimirMetricsNotFound: If the connection to Mimir Metrics cannot be established. | ||
""" | ||
try: | ||
super().check_connection() | ||
except MetricsNotFound as e: | ||
# This is to clarify which metrics service had the issue and not say its a prometheus issue | ||
raise MetricsNotFound( | ||
f"Couldn't connect to Mimir Metrics found under {self.prometheus.url}\nCaused by {e.__class__.__name__}: {e})" | ||
) from e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters