Skip to content

Commit

Permalink
Alert dict (#513)
Browse files Browse the repository at this point in the history
* use alert_expression_dict

* fully convert to JujuTopology from cosl

* add requirements

* fix integration test

* formatting
  • Loading branch information
dstathis authored Aug 28, 2023
1 parent 236e4dc commit fa76874
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 322 deletions.
301 changes: 0 additions & 301 deletions lib/charms/observability_libs/v0/juju_topology.py

This file was deleted.

11 changes: 2 additions & 9 deletions lib/charms/prometheus_k8s/v0/prometheus_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@
Source code can be found on GitHub at:
https://github.com/canonical/prometheus-k8s-operator/tree/main/lib/charms/prometheus_k8s
## Dependencies
Using this library requires you to fetch the juju_topology library from
[observability-libs](https://charmhub.io/observability-libs/libraries/juju_topology).
`charmcraft fetch-lib charms.observability_libs.v0.juju_topology`
## Provider Library Usage
This Prometheus charm interacts with its scrape targets using its
Expand Down Expand Up @@ -369,7 +362,7 @@ def _on_scrape_targets_changed(self, event):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 40
LIBPATCH = 41

PYDEPS = ["cosl"]

Expand Down Expand Up @@ -1129,7 +1122,7 @@ def _inject_alert_expr_labels(self, rules: Dict[str, Any]) -> Dict[str, Any]:
# Inject topology and put it back in the list
rule["expr"] = self._tool.inject_label_matchers(
re.sub(r"%%juju_topology%%,?", "", rule["expr"]),
topology.label_matcher_dict,
topology.alert_expression_dict,
)
except KeyError:
# Some required JujuTopology key is missing. Just move on.
Expand Down
4 changes: 2 additions & 2 deletions lib/charms/prometheus_k8s/v1/prometheus_remote_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 1
LIBPATCH = 2

PYDEPS = ["cosl"]

Expand Down Expand Up @@ -838,7 +838,7 @@ def _inject_alert_expr_labels(self, rules: Dict[str, Any]) -> Dict[str, Any]:
# Inject topology and put it back in the list
rule["expr"] = self._tool.inject_label_matchers(
re.sub(r"%%juju_topology%%,?", "", rule["expr"]),
topology.label_matcher_dict,
topology.alert_expression_dict,
)
except KeyError:
# Some required JujuTopology key is missing. Just move on.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cosl
cryptography
jsonschema
ops
Expand Down
2 changes: 1 addition & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from charms.grafana_k8s.v0.grafana_dashboard import GrafanaDashboardProvider
from charms.grafana_k8s.v0.grafana_source import GrafanaSourceProvider
from charms.observability_libs.v0.cert_handler import CertHandler
from charms.observability_libs.v0.juju_topology import JujuTopology
from charms.observability_libs.v0.kubernetes_compute_resources_patch import (
K8sResourcePatchFailedEvent,
KubernetesComputeResourcesPatch,
Expand All @@ -42,6 +41,7 @@
IngressPerUnitRequirer,
IngressPerUnitRevokedForUnitEvent,
)
from cosl import JujuTopology
from lightkube.core.client import Client
from lightkube.core.exceptions import ApiError as LightkubeApiError
from lightkube.resources.core_v1 import PersistentVolumeClaim, Pod
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/test_remote_write_grafana_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ async def test_remote_write_with_grafana_agent(

expr = tester_rules["query"]
topology_labels = [
f'{k}="{v}"' for k, v in tester_rules["labels"].items() if k.startswith("juju_")
f'{k}="{v}"'
for k, v in tester_rules["labels"].items()
if k.startswith("juju_") and k != "juju_charm"
]
assert all(field in expr for field in topology_labels)

Expand Down
Loading

0 comments on commit fa76874

Please sign in to comment.