From 2505957034692871ce6f103bd6f2086a16c64379 Mon Sep 17 00:00:00 2001 From: Maksim Beliaev Date: Fri, 18 Nov 2022 20:41:10 +0100 Subject: [PATCH 1/3] move has_metric --- tests/integration/helpers.py | 10 ++++++++++ tests/integration/test_remote_write_grafana_agent.py | 11 +---------- tests/integration/test_remote_write_with_zinc.py | 12 +----------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index 4366a59b..b6bf9fe2 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -234,3 +234,13 @@ 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: + # 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 diff --git a/tests/integration/test_remote_write_grafana_agent.py b/tests/integration/test_remote_write_grafana_agent.py index 508a51d5..cfc110be 100644 --- a/tests/integration/test_remote_write_grafana_agent.py +++ b/tests/integration/test_remote_write_grafana_agent.py @@ -10,6 +10,7 @@ check_prometheus_is_ready, get_prometheus_rules, get_rules_for, + has_metric, oci_image, run_promql, ) @@ -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 diff --git a/tests/integration/test_remote_write_with_zinc.py b/tests/integration/test_remote_write_with_zinc.py index 7b53fce5..fc17098b 100644 --- a/tests/integration/test_remote_write_with_zinc.py +++ b/tests/integration/test_remote_write_with_zinc.py @@ -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, run_promql from juju.controller import Controller # type: ignore logger = logging.getLogger(__name__) @@ -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 From 3b1b8f2057193ad63e75739a00703304b3ee8f2f Mon Sep 17 00:00:00 2001 From: Maksim Beliaev Date: Tue, 29 Nov 2022 14:40:38 +0100 Subject: [PATCH 2/3] exclude all venvs in tox.ini --- tests/integration/test_remote_write_with_zinc.py | 2 +- tox.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_remote_write_with_zinc.py b/tests/integration/test_remote_write_with_zinc.py index fc17098b..cd5a346d 100644 --- a/tests/integration/test_remote_write_with_zinc.py +++ b/tests/integration/test_remote_write_with_zinc.py @@ -6,7 +6,7 @@ import logging import pytest -from helpers import check_prometheus_is_ready, has_metric, 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__) diff --git a/tox.ini b/tox.ini index ef880bfa..27401ced 100644 --- a/tox.ini +++ b/tox.ini @@ -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 # pflake8 wrapper supports config from pyproject.toml pflake8 {[vars]all_path} isort --check-only --diff {[vars]all_path} From 27d99957b1914395ec479f677a8a557a4815eaa0 Mon Sep 17 00:00:00 2001 From: Maksim Beliaev Date: Wed, 30 Nov 2022 16:52:20 +0100 Subject: [PATCH 3/3] Update tests/integration/helpers.py Co-authored-by: Leon <82407168+sed-i@users.noreply.github.com> --- tests/integration/helpers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index b6bf9fe2..91535420 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -237,8 +237,7 @@ def get_podspec(ops_test: OpsTest, app_name: str, container_name: str): 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 + """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