async def test_prometheus_scrape_relation_with_prometheus_tester( ops_test, prometheus_charm, prometheus_tester_charm ): """Test basic functionality of prometheus_scrape relation interface.""" tester_resources = { "prometheus-tester-image": oci_image( "./tests/integration/prometheus-tester/metadata.yaml", "prometheus-tester-image" ) } prometheus_resources = {"prometheus-image": oci_image("./metadata.yaml", "prometheus-image")} prometheus_app_name = "prometheus" tester_app_name = "prometheus-tester" await ops_test.model.deploy( prometheus_charm, resources=prometheus_resources, application_name=prometheus_app_name ) await ops_test.model.deploy( prometheus_tester_charm, resources=tester_resources, application_name=tester_app_name ) await ops_test.model.wait_for_idle(apps=[prometheus_app_name], status="active") await ops_test.model.wait_for_idle(apps=[tester_app_name], status="active") await ops_test.model.block_until( lambda: len(ops_test.model.applications[prometheus_app_name].units) > 0 ) await ops_test.model.block_until( lambda: len(ops_test.model.applications[tester_app_name].units) > 0 ) assert ops_test.model.applications[prometheus_app_name].units[0].workload_status == "active" assert ops_test.model.applications[tester_app_name].units[0].workload_status == "active" await check_prometheus_is_ready(ops_test, prometheus_app_name, 0) initial_config = await get_prometheus_config(ops_test, prometheus_app_name, 0) initial_rules = await get_prometheus_rules(ops_test, prometheus_app_name, 0) await ops_test.model.add_relation(prometheus_app_name, tester_app_name) await ops_test.model.wait_for_idle(apps=[prometheus_app_name], status="active") config_with_relation = await get_prometheus_config(ops_test, prometheus_app_name, 0) tester_job = get_job_config_for(tester_app_name, config_with_relation) assert tester_job != {} rules_with_relation = await get_prometheus_rules(ops_test, prometheus_app_name, 0) tester_rules = get_rules_for(tester_app_name, rules_with_relation) assert tester_rules != {} await ops_test.model.applications[tester_app_name].remove() await ops_test.model.wait_for_idle(apps=[prometheus_app_name], status="active") relation_removed_config = await get_prometheus_config(ops_test, prometheus_app_name, 0) assert initial_config == relation_removed_config relation_removed_rules = await get_prometheus_rules(ops_test, prometheus_app_name, 0) assert initial_rules == relation_removed_rules await ops_test.model.applications[prometheus_app_name].remove() await ops_test.model.reset()
async def test_remote_write_with_grafana_agent(ops_test, prometheus_charm): """Test that Prometheus can be related with the Grafana Agent over remote_write.""" prometheus_name = "prometheus" agent_name = "grafana-agent" await asyncio.gather( ops_test.model.deploy( prometheus_charm, resources={ "prometheus-image": oci_image("./metadata.yaml", "prometheus-image") }, application_name=prometheus_name, ), ops_test.model.deploy( "grafana-agent-k8s", application_name=agent_name, channel="edge", ), ) await ops_test.model.add_relation(prometheus_name, agent_name) apps = [prometheus_name, agent_name] await ops_test.model.wait_for_idle(apps=apps, status="active") assert initial_workload_is_ready(ops_test, apps) await check_prometheus_is_ready(ops_test, prometheus_name, 0) await has_metric( ops_test, f'up{{juju_model="{ops_test.model_name}",juju_application="{agent_name}"}}', prometheus_name, )
async def test_build_and_deploy_with_alternative_images(ops_test, prometheus_charm): """Test that the Prometheus charm can be deployed successfully.""" resources = {"prometheus-image": oci_image("./metadata.yaml", "prometheus-image")} app_name = "prometheus-ubuntu" await ops_test.model.deploy(prometheus_charm, resources=resources, application_name=app_name) await ops_test.model.wait_for_idle(apps=[app_name], status="active") await ops_test.model.block_until(lambda: len(ops_test.model.applications[app_name].units) > 0) assert ops_test.model.applications[app_name].units[0].workload_status == "active" await check_prometheus_is_ready(ops_test, app_name, 0) await ops_test.model.applications[app_name].remove() await ops_test.model.reset()
async def test_build_and_deploy_prometheus_tester(ops_test, prometheus_tester_charm): """Test that Prometheus tester charm can be deployed successfully.""" resources = { "prometheus-tester-image": oci_image( "./tests/integration/prometheus-tester/metadata.yaml", "prometheus-tester-image" ) } app_name = "prometheus-tester" await ops_test.model.deploy( prometheus_tester_charm, resources=resources, application_name=app_name ) await ops_test.model.wait_for_idle(apps=[app_name], status="active") await ops_test.model.block_until(lambda: len(ops_test.model.applications[app_name].units) > 0) assert ops_test.model.applications[app_name].units[0].workload_status == "active" await ops_test.model.applications[app_name].remove() await ops_test.model.reset()
async def test_ingress_traefik_k8s(ops_test, prometheus_charm): """Test that Prometheus can be related with the Grafana Agent over remote_write.""" prometheus_name = "prometheus" traefik_name = "traefik-ingress" await asyncio.gather( ops_test.model.deploy( prometheus_charm, resources={ "prometheus-image": oci_image("./metadata.yaml", "prometheus-image") }, application_name=prometheus_name, ), ops_test.model.deploy( "traefik-k8s", application_name=traefik_name, channel="edge", config={ "routing_mode": "path", "external_hostname": "foo.bar", }, ), ) apps = [prometheus_name, traefik_name] await ops_test.model.wait_for_idle(apps=apps, status="active") assert initial_workload_is_ready(ops_test, apps) await check_prometheus_is_ready(ops_test, prometheus_name, 0) await ops_test.model.add_relation(traefik_name, f"{prometheus_name}:ingress") # Wait a little more than usual, there are various rounds of relation_changed # to be processed. await ops_test.model.wait_for_idle(apps=apps, status="active") result = await _retrieve_proxied_endpoints(ops_test, traefik_name) assert f"{prometheus_name}/0" in result assert result[f"{prometheus_name}/0"] == { "url": f"http://foo.bar:80/{ops_test.model_name}-{prometheus_name}-0" }
#!/usr/bin/env python3 # Copyright 2021 Canonical Ltd. # See LICENSE file for licensing details. import pytest from helpers import check_prometheus_is_ready, oci_image tester_resources = { "prometheus-tester-image": oci_image("./tests/integration/prometheus-tester/metadata.yaml", "prometheus-tester-image") } prometheus_resources = { "prometheus-image": oci_image("./metadata.yaml", "prometheus-image") } @pytest.mark.abort_on_fail async def test_build_and_deploy_with_alternative_images( ops_test, prometheus_charm): """Test that the Prometheus charm can be deployed successfully.""" app_name = "prometheus-ubuntu" await ops_test.model.deploy(prometheus_charm, resources=prometheus_resources, application_name=app_name) await ops_test.model.wait_for_idle(apps=[app_name], status="active") await ops_test.model.block_until( lambda: len(ops_test.model.applications[app_name].units) > 0) assert ops_test.model.applications[app_name].units[
import logging import pytest from helpers import ( check_grafana_is_ready, get_datasource_for, get_grafana_datasources, oci_image, ) logger = logging.getLogger(__name__) tester_resources = { "grafana-tester-image": oci_image("./tests/integration/grafana-tester/metadata.yaml", "grafana-tester-image") } grafana_resources = { "grafana-image": oci_image("./metadata.yaml", "grafana-image") } @pytest.mark.abort_on_fail async def test_grafana_source_relation_data_with_grafana_tester( ops_test, grafana_charm, grafana_tester_charm): """Test basic functionality of grafana-source relation interface.""" grafana_app_name = "grafana" tester_app_name = "grafana-tester" await ops_test.model.deploy(grafana_charm, resources=grafana_resources,
async def test_prometheus_scrape_relation_with_prometheus_tester( ops_test: OpsTest, prometheus_charm, prometheus_tester_charm): """Test basic functionality of prometheus_scrape relation interface.""" prometheus_app_name = "prometheus" tester_app_name = "prometheus-tester" app_names = [prometheus_app_name, tester_app_name] await asyncio.gather( ops_test.model.deploy( prometheus_charm, resources={ "prometheus-image": oci_image("./metadata.yaml", "prometheus-image") }, application_name=prometheus_app_name, ), ops_test.model.deploy( prometheus_tester_charm, resources={ "prometheus-tester-image": oci_image( "./tests/integration/prometheus-tester/metadata.yaml", "prometheus-tester-image", ) }, application_name=tester_app_name, ), ) await ops_test.model.wait_for_idle(apps=app_names, status="active") # TODO: Should not be needed. # Drop once https://github.com/juju/python-libjuju/issues/574 is resolved # - SA 2021-11-23 await ops_test.model.block_until(lambda: (len(ops_test.model.applications[ prometheus_app_name].units) > 0 and len(ops_test.model.applications[ tester_app_name].units) > 0)) assert initial_workload_is_ready(ops_test, app_names) await check_prometheus_is_ready(ops_test, prometheus_app_name, 0) initial_config, initial_rules = await asyncio.gather( get_prometheus_config(ops_test, prometheus_app_name, 0), get_prometheus_rules(ops_test, prometheus_app_name, 0), ) await ops_test.model.add_relation(prometheus_app_name, tester_app_name) await ops_test.model.wait_for_idle(apps=[prometheus_app_name], status="active") config_with_relation = await get_prometheus_config(ops_test, prometheus_app_name, 0) tester_job = get_job_config_for(tester_app_name, config_with_relation) assert tester_job != {} rules_with_relation = await get_prometheus_rules(ops_test, prometheus_app_name, 0) tester_rules = get_rules_for(tester_app_name, rules_with_relation) assert len(tester_rules) == 1 await ops_test.model.applications[tester_app_name].remove() await ops_test.model.wait_for_idle(apps=[prometheus_app_name], status="active") relation_removed_config, relation_removed_rules = await asyncio.gather( get_prometheus_config(ops_test, prometheus_app_name, 0), get_prometheus_rules(ops_test, prometheus_app_name, 0), ) assert initial_config == relation_removed_config assert initial_rules == relation_removed_rules
#!/usr/bin/env python3 # Copyright 2021 Canonical Ltd. # See LICENSE file for licensing details. import pytest from helpers import check_grafana_is_ready, oci_image grafana_resources = {"grafana-image": oci_image("./metadata.yaml", "grafana-image")} @pytest.mark.abort_on_fail async def test_build_and_deploy_with_alternative_images(ops_test, grafana_charm): """Test that the Prometheus charm can be deployed successfully.""" app_name = "prometheus-ubuntu" await ops_test.model.deploy( grafana_charm, resources=grafana_resources, application_name=app_name ) await ops_test.model.wait_for_idle(apps=[app_name], status="active") await ops_test.model.block_until(lambda: len(ops_test.model.applications[app_name].units) > 0) assert ops_test.model.applications[app_name].units[0].workload_status == "active" await check_grafana_is_ready(ops_test, app_name, 0) await ops_test.model.applications[app_name].remove() await ops_test.model.block_until(lambda: app_name not in ops_test.model.applications) await ops_test.model.reset()