Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move has_metric #406

Merged
merged 3 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,12 @@ def get_podspec(ops_test: OpsTest, app_name: str, container_name: str):
pod = client.get(Pod, name=f"{app_name}-0", namespace=ops_test.model_name)
podspec = next(iter(filter(lambda ctr: ctr.name == container_name, pod.spec.containers)))
return podspec


async def has_metric(ops_test, query: str, app_name: str) -> bool:
"""Returns True if the query returns any time series; False otherwise."""
for timeseries in await run_promql(ops_test, query, app_name):
if timeseries.get("metric"):
return True

return False
11 changes: 1 addition & 10 deletions tests/integration/test_remote_write_grafana_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
check_prometheus_is_ready,
get_prometheus_rules,
get_rules_for,
has_metric,
oci_image,
run_promql,
)
Expand Down Expand Up @@ -171,13 +172,3 @@ async def test_check_data_not_persist_on_scale_0(ops_test, prometheus_charm):
total1 = await run_promql(ops_test, query, prometheus_app_name)
num_head_chunks_after = int(total1[0]["value"][1])
assert num_head_chunks_before <= num_head_chunks_after


async def has_metric(ops_test, query: str, app_name: str) -> bool:
# Throws if the query does not return any time series within 5 minutes,
# and as a consequence, fails the test
for timeseries in await run_promql(ops_test, query, app_name):
if timeseries.get("metric"):
return True

return False
12 changes: 1 addition & 11 deletions tests/integration/test_remote_write_with_zinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging

import pytest
from helpers import check_prometheus_is_ready, oci_image, run_promql
from helpers import check_prometheus_is_ready, has_metric, oci_image
from juju.controller import Controller # type: ignore

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -145,13 +145,3 @@ async def test_offer_and_consume_remote_write_with_zinc(ops_test):
await consumer.model.remove_application(agent_remote_name, block_until_done=True)
await consumer.model.remove_saas("prom")
await controller.disconnect()


async def has_metric(ops_test, query: str, app_name: str) -> bool:
# Throws if the query does not return any time series within 5 minutes,
# and as a consequence, fails the test
for timeseries in await run_promql(ops_test, query, app_name):
if timeseries.get("metric"):
return True

return False
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ deps =
isort
commands =
codespell {[vars]lib_path}
codespell . --skip .git --skip .tox --skip build --skip lib --skip venv --skip .mypy_cache
codespell . --skip .git --skip .tox --skip build --skip lib --skip venv* --skip .mypy_cache
beliaev-maksim marked this conversation as resolved.
Show resolved Hide resolved
# pflake8 wrapper supports config from pyproject.toml
pflake8 {[vars]all_path}
isort --check-only --diff {[vars]all_path}
Expand Down