-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workers self monitoring (metrics and alert rules) (#50)
* sync alert rules with mimir repo: https://github.com/grafana/mimir/blob/main/operations/mimir-mixin-compiled/alerts.yaml * sync rules with mimir repo: https://github.com/grafana/mimir/blob/main/operations/mimir-mixin-compiled/rules.yaml * fix typo * add nginx-prometheus-exporter * int to str ports * move mimir rules to specific directory * add nginx rules and a new relation for nginx metrics * add nginx-prometheus-exporter-image to itest * fixing test_tls * add scheme and avoid ssl verification in nginx-prometheus-exporter * move pebble layer setup to workload's managers * add explicit nginx prometheus exporter port * improve tls handling * let do tls mre robust * update lisbs * cos-tool render rules * refactor alert rules renderization * upate prometheus scrape lib * merge both metrics_endpoint relation into one * remove missing breakpoint() * remove missing cos_tool * change relation name * add missing nginx pebble ready configuration * refactor/remove _ensure_consolidated_rules_dir * add cos-tool-* to .gitignore * add set_can_connect * add itest to check scrape jobs and rules * linting * fix test_charm.py itest * update loki_push_api lib * add some debug logging * add con_connect guard * modify some logging * add logging and supress progress bar in curl * missing -sS in curl command
- Loading branch information
1 parent
8c194d5
commit 937f48d
Showing
10 changed files
with
228 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ __pycache__/ | |
.idea | ||
.vscode/ | ||
*.egg-info/ | ||
cos-tool-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2024 Ubuntu | ||
# See LICENSE file for licensing details. | ||
|
||
import json | ||
import logging | ||
from pathlib import Path | ||
from textwrap import dedent | ||
from types import SimpleNamespace | ||
|
||
import pytest | ||
import yaml | ||
from helpers import deploy_literal_bundle, run_command | ||
from pytest_operator.plugin import OpsTest | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text()) | ||
coord = SimpleNamespace(name="coord") | ||
apps = ["coord", "write", "read", "prom"] | ||
|
||
|
||
@pytest.mark.abort_on_fail | ||
async def test_build_and_deploy(ops_test: OpsTest): | ||
"""Build the charm-under-test and deploy it together with related charms.""" | ||
charm = await ops_test.build_charm(".") | ||
|
||
test_bundle = dedent( | ||
f""" | ||
--- | ||
bundle: kubernetes | ||
name: test-charm | ||
applications: | ||
{coord.name}: | ||
charm: {charm} | ||
trust: true | ||
resources: | ||
nginx-image: {METADATA["resources"]["nginx-image"]["upstream-source"]} | ||
nginx-prometheus-exporter-image: {METADATA["resources"]["nginx-prometheus-exporter-image"]["upstream-source"]} | ||
scale: 1 | ||
prom: | ||
charm: prometheus-k8s | ||
channel: edge | ||
scale: 1 | ||
trust: true | ||
read: | ||
charm: mimir-worker-k8s | ||
channel: edge | ||
scale: 1 | ||
constraints: arch=amd64 | ||
options: | ||
alertmanager: true | ||
compactor: true | ||
querier: true | ||
query-frontend: true | ||
query-scheduler: true | ||
ruler: true | ||
store-gateway: true | ||
trust: true | ||
write: | ||
charm: mimir-worker-k8s | ||
channel: edge | ||
scale: 1 | ||
constraints: arch=amd64 | ||
options: | ||
compactor: true | ||
distributor: true | ||
ingester: true | ||
trust: true | ||
relations: | ||
- - prom:metrics-endpoint | ||
- coord:self-metrics-endpoint | ||
- - coord:mimir-cluster | ||
- read:mimir-cluster | ||
- - coord:mimir-cluster | ||
- write:mimir-cluster | ||
""" | ||
) | ||
|
||
# Deploy the charm and wait for active/idle status | ||
await deploy_literal_bundle(ops_test, test_bundle) # See appendix below | ||
await ops_test.model.wait_for_idle( | ||
apps=["read", "write", "prom"], | ||
status="active", | ||
raise_on_error=False, | ||
timeout=600, | ||
idle_period=30, | ||
) | ||
|
||
await ops_test.model.wait_for_idle( | ||
apps=[coord.name], status="blocked", raise_on_error=False, timeout=600, idle_period=30 | ||
) | ||
|
||
|
||
@pytest.mark.abort_on_fail | ||
async def test_scrape_jobs(ops_test: OpsTest): | ||
# Check scrape jobs | ||
cmd = ["curl", "-sS", "http://localhost:9090/api/v1/targets"] | ||
result = await run_command(ops_test.model_name, "prom", 0, command=cmd) | ||
logger.info(result) | ||
result_json = json.loads(result.decode("utf-8")) | ||
|
||
active_targets = result_json["data"]["activeTargets"] | ||
|
||
for at in active_targets: | ||
assert at["labels"]["juju_application"] in apps | ||
|
||
|
||
@pytest.mark.abort_on_fail | ||
async def test_rules(ops_test: OpsTest): | ||
# Check Rules | ||
cmd = ["curl", "-sS", "http://localhost:9090/api/v1/rules"] | ||
result = await run_command(ops_test.model_name, "prom", 0, command=cmd) | ||
logger.info(result) | ||
result_json = json.loads(result.decode("utf-8")) | ||
groups = result_json["data"]["groups"] | ||
|
||
for group in groups: | ||
for rule in group["rules"]: | ||
assert rule["labels"]["juju_application"] in apps |
Oops, something went wrong.