Skip to content

Commit

Permalink
Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juditnovak committed Nov 24, 2023
1 parent 6a2af77 commit b24661b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/integration/helpers_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import subprocess
from datetime import datetime, timedelta
from dateutil.parser import parse
from typing import Any, Dict, List, Optional, Union
from uuid import uuid4

Expand All @@ -22,7 +23,7 @@ class Status:

def __init__(self, value: str, since: str, message: Optional[str] = None):
self.value = value
self.since = datetime.strptime(since, "%d %b %Y %H:%M:%SZ")
self.since = parse(since)
self.message = message


Expand Down
51 changes: 49 additions & 2 deletions tests/integration/plugins/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
MODEL_CONFIG,
SERIES,
check_cluster_formation_successful,
http_request,
get_application_unit_ids_ips,
get_application_unit_names,
get_leader_unit_ip,
Expand All @@ -30,6 +31,7 @@
)
from tests.integration.tls.test_tls import TLS_CERTIFICATES_APP_NAME

COS_APP_NAME = "grafana-agent"

@pytest.mark.abort_on_fail
@pytest.mark.skip_if_deployed
Expand All @@ -46,7 +48,7 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None:
await asyncio.gather(
ops_test.model.deploy(TLS_CERTIFICATES_APP_NAME, channel="stable", config=config),
ops_test.model.deploy(
my_charm, num_units=3, series=SERIES, config={"plugin_opensearch_knn": True}
my_charm, num_units=1, series=SERIES, config={"plugin_opensearch_knn": True}
),
)

Expand All @@ -58,7 +60,7 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None:
timeout=1400,
idle_period=IDLE_PERIOD,
)
assert len(ops_test.model.applications[APP_NAME].units) == 3
assert len(ops_test.model.applications[APP_NAME].units) == 1


@pytest.mark.abort_on_fail
Expand Down Expand Up @@ -236,3 +238,48 @@ async def test_knn_training_search(ops_test: OpsTest) -> None:
except RetryError:
# The search should fail if knn_enabled is false
assert not knn_enabled


async def test_prometheus_exporter_enabled(ops_test):
await ops_test.model.deploy(COS_APP_NAME, channel="edge"),
await ops_test.model.relate(APP_NAME, COS_APP_NAME)
# NOTE: As for now, COS agent remains blocked, as we only have a partial config
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="active",
timeout=1400,
idle_period=IDLE_PERIOD,
)
config = await ops_test.model.applications[APP_NAME].get_config()
assert config['prometheus_exporter_plugin_url']['default'].startswith("https://")


async def test_prometheus_exporter_works(ops_test):
leader_unit_ip = await get_leader_unit_ip(ops_test, app=APP_NAME)
endpoint = f"https://{leader_unit_ip}:9200/_prometheus/metrics"
response = await http_request(ops_test, "get", endpoint, app=APP_NAME, json_resp=False)

response_str = response.content.decode('utf-8')
assert response_str.count("opensearch_") > 500
assert len(response_str.split("\n")) > 500


@pytest.mark.xfail(reason="Doesn't work yet")
async def test_prometheus_exporter_disabled(ops_test):
await ops_test.juju("remove-relation", APP_NAME, COS_APP_NAME)
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="active",
timeout=1400,
idle_period=IDLE_PERIOD,
)

leader_unit_ip = await get_leader_unit_ip(ops_test, app=APP_NAME)
endpoint = f"https://{leader_unit_ip}:9200/_prometheus/metrics"
response = await http_request(ops_test, "get", endpoint, app=APP_NAME, json_resp=False)
assert response.content.decode('utf-8') == {
"error": "no handler found for uri [/_prometheus/metrics] and method [GET]"
}

config = await ops_test.model.applications[APP_NAME].get_config()
assert not config['prometheus_exporter_plugin_url']

0 comments on commit b24661b

Please sign in to comment.