Skip to content

Commit

Permalink
Merge pull request #492 from averevki/prometheus-tweaks
Browse files Browse the repository at this point in the history
Remove namespace from prometheus queries
  • Loading branch information
jsmolar authored Jul 25, 2024
2 parents 99e645b + 16ba9db commit aff3df9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
7 changes: 1 addition & 6 deletions testsuite/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def values(self) -> list[float]:
class Prometheus:
"""Interface to the Prometheus client"""

def __init__(self, client: Client, namespace: str = None):
self.namespace = namespace
def __init__(self, client: Client):
self.client = ApyProxy(str(client.base_url), session=client).api.v1

def get_active_targets(self) -> dict:
Expand All @@ -57,10 +56,6 @@ def get_active_targets(self) -> dict:

def get_metrics(self, key: str = "", labels: dict[str, str] = None) -> Metrics:
"""Get metrics by key or labels"""
if self.namespace:
labels = labels or {}
labels.setdefault("namespace", self.namespace)

params = _params(key, labels)
response = self.client.query.get(params=params)

Expand Down
12 changes: 6 additions & 6 deletions testsuite/tests/singlecluster/authorino/metrics/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from testsuite.prometheus import Prometheus


@pytest.fixture(scope="module")
@pytest.fixture(scope="package")
def prometheus(cluster):
"""
Return an instance of Thanos metrics client
Expand All @@ -31,12 +31,12 @@ def prometheus(cluster):
# this route allows to query metrics

routes = openshift_monitoring.get_routes_for_service("thanos-querier")
if len(routes) > 0:
url = ("https://" if "tls" in routes[0].model.spec else "http://") + routes[0].model.spec.host
with KuadrantClient(headers={"Authorization": f"Bearer {cluster.token}"}, base_url=url, verify=False) as client:
yield Prometheus(client, cluster.project)
if len(routes) == 0:
pytest.skip("Skipping metrics tests as query route is not properly configured")

pytest.skip("Skipping metrics tests as query route is not properly configured")
url = ("https://" if "tls" in routes[0].model.spec else "http://") + routes[0].model.spec.host
with KuadrantClient(headers={"Authorization": f"Bearer {cluster.token}"}, base_url=url, verify=False) as client:
yield Prometheus(client)


@pytest.fixture(scope="module")
Expand Down

0 comments on commit aff3df9

Please sign in to comment.