Skip to content

Commit

Permalink
update based on obs team comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Natasha Ho committed Apr 8, 2022
1 parent 398cbc4 commit b698251
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.charm
build/
__pycache__/
.tox
2 changes: 1 addition & 1 deletion metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ provides:
interface: object-storage
schema: https://raw.githubusercontent.com/canonical/operator-schemas/master/object-storage.yaml
versions: [v1]
monitoring:
metrics-endpoint:
interface: prometheus_scrape
grafana-dashboard:
interface: grafana_dashboard
Expand Down
10 changes: 3 additions & 7 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def __init__(self, *args):

self.prometheus_provider = MetricsEndpointProvider(
charm=self,
relation_name="monitoring",
jobs=[
{
"job_name": "minio_metrics",
Expand All @@ -54,9 +53,6 @@ def __init__(self, *args):
self.on.upgrade_charm,
self.on["object-storage"].relation_changed,
self.on["object-storage"].relation_joined,
self.on["monitoring"].relation_changed,
self.on["monitoring"].relation_broken,
self.on["monitoring"].relation_departed,
]:
self.framework.observe(event, self.main)

Expand Down Expand Up @@ -197,14 +193,14 @@ def _gen_pass() -> str:


class CheckFailed(Exception):
""" Raise this exception if one of the checks in main fails. """
"""Raise this exception if one of the checks in main fails."""

def __init__(self, msg, status_type=None):
super().__init__()

self.msg = msg
self.msg = str(msg)
self.status_type = status_type
self.status = status_type(msg)
self.status = status_type(self.msg)


if __name__ == "__main__":
Expand Down
10 changes: 10 additions & 0 deletions src/prometheus_alert_rules/unit_unavailable.rule
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
alert: MinioUnitIsUnavailable
expr: up < 1
for: 0m
labels:
severity: critical
annotations:
summary: Minio unit {{ $labels.juju_model }}/{{ $labels.juju_unit }} unavailable
description: >
The Minio unit {{ $labels.juju_model }} {{ $labels.juju_unit }} is unavailable
LABELS = {{ $labels }}
3 changes: 2 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
pytest
pyyaml
flake8
black==20.8b1
black
flake8-copyright<0.3
requests
43 changes: 43 additions & 0 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import pytest
import yaml
import requests
import json
from pytest_operator.plugin import OpsTest

log = logging.getLogger(__name__)
Expand All @@ -19,6 +21,9 @@

APP_NAME = "minio"
CHARM_ROOT = "."
PROMETHEUS = "prometheus-k8s"
GRAFANA = "grafana-k8s"
PROMETHEUS_SCRAPE = "prometheus-scrape-config-k8s"


@pytest.mark.abort_on_fail
Expand Down Expand Up @@ -118,3 +123,41 @@ async def test_connect_to_console(ops_test: OpsTest):
assert (
ret_code == 0
), f"Test returned code {ret_code} with stdout:\n{stdout}\nstderr:\n{stderr}"


async def test_deploy_with_prometheus_and_grafana(ops_test):
scrape_config = {"scrape_interval": "30s"}
await ops_test.model.deploy(PROMETHEUS, channel="latest/beta")
await ops_test.model.deploy(GRAFANA, channel="latest/beta")
await ops_test.model.deploy(
PROMETHEUS_SCRAPE, channel="latest/beta", config=scrape_config
)
await ops_test.model.add_relation(APP_NAME, PROMETHEUS_SCRAPE)
await ops_test.model.add_relation(PROMETHEUS, PROMETHEUS_SCRAPE)
await ops_test.model.add_relation(PROMETHEUS, GRAFANA)
await ops_test.model.add_relation(APP_NAME, GRAFANA)

await ops_test.model.wait_for_idle(
[APP_NAME, PROMETHEUS, GRAFANA, PROMETHEUS_SCRAPE], status="active"
)


async def test_correct_observability_setup(ops_test):
status = await ops_test.model.get_status()
prometheus_unit_ip = status["applications"][PROMETHEUS]["units"][f"{PROMETHEUS}/0"][
"address"
]
r = requests.get(
f'http://{prometheus_unit_ip}:9090/api/v1/query?query=up{{juju_application="{APP_NAME}"}}'
)
response = json.loads(r.content.decode("utf-8"))
assert response["status"] == "success"
assert len(response["data"]["result"]) == len(
ops_test.model.applications[APP_NAME].units
)

response_metric = response["data"]["result"][0]["metric"]
assert response_metric["juju_application"] == APP_NAME
assert response_metric["juju_charm"] == APP_NAME
assert response_metric["juju_model"] == ops_test.model_name
assert response_metric["juju_unit"] == f"{APP_NAME}/0"
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ commands = pytest -vv {toxinidir}/tests/unit
[testenv:lint]
commands =
flake8 {toxinidir}/src {toxinidir}/tests
black --check {toxinidir}/src {toxinidir}/tests
black --check --diff {toxinidir}/src {toxinidir}/tests

0 comments on commit b698251

Please sign in to comment.