Skip to content

Commit

Permalink
Fix mapped severity (#163)
Browse files Browse the repository at this point in the history
* Fix mapped severity

This PR fixes: #146

We multiply the value  by 2 so the severity is mapped to a critical 



Signed-off-by: Jose C. Massón <[email protected]>

* update libs

* linting

* bug in pyright. pinning version

* fix scenario tests

* add cryptography as binary package

* change issue comment

* bump LIBPATCH

---------

Signed-off-by: Jose C. Massón <[email protected]>
  • Loading branch information
Abuelodelanada authored Dec 6, 2024
1 parent fc86ee9 commit 73d8ee3
Show file tree
Hide file tree
Showing 10 changed files with 519 additions and 127 deletions.
1 change: 1 addition & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ parts:
# Install PyYAML from binary and avoid building it from sources. This way, we can use PyYAML with C-optimized lib.
# With the C-optimized lib, serialization in ops is 20x faster.
- PyYAML
- cryptography
nrpe-exporter:
plugin: dump
source: .
Expand Down
7 changes: 5 additions & 2 deletions lib/charms/grafana_agent/v0/cos_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
Using the `COSAgentProvider` object only requires instantiating it,
typically in the `__init__` method of your charm (the one which sends telemetry).
The constructor of `COSAgentProvider` has only one required and nine optional parameters:
```python
def __init__(
Expand All @@ -36,6 +35,7 @@ def __init__(
log_slots: Optional[List[str]] = None,
dashboard_dirs: Optional[List[str]] = None,
refresh_events: Optional[List] = None,
tracing_protocols: Optional[List[str]] = None,
scrape_configs: Optional[Union[List[Dict], Callable]] = None,
):
```
Expand Down Expand Up @@ -65,6 +65,8 @@ def __init__(
- `refresh_events`: List of events on which to refresh relation data.
- `tracing_protocols`: List of requested tracing protocols that the charm requires to send traces.
- `scrape_configs`: List of standard scrape_configs dicts or a callable that returns the list in
case the configs need to be generated dynamically. The contents of this list will be merged
with the configs from `metrics_endpoints`.
Expand Down Expand Up @@ -108,6 +110,7 @@ def __init__(self, *args):
log_slots=["my-app:slot"],
dashboard_dirs=["./src/dashboards_1", "./src/dashboards_2"],
refresh_events=["update-status", "upgrade-charm"],
tracing_protocols=["otlp_http", "otlp_grpc"],
scrape_configs=[
{
"job_name": "custom_job",
Expand Down Expand Up @@ -249,7 +252,7 @@ class _MetricsEndpointDict(TypedDict):

LIBID = "dc15fa84cef84ce58155fb84f6c6213a"
LIBAPI = 0
LIBPATCH = 10
LIBPATCH = 12

PYDEPS = ["cosl", "pydantic"]

Expand Down
8 changes: 5 additions & 3 deletions lib/charms/nrpe_exporter/v0/nrpe_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

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


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -477,9 +477,11 @@ def _generate_alert(self, relation, cmd, id, unit, nagios_host_context) -> dict:
# Average over 5 minutes considering a 60-second scrape interval
# We need to "round" so the severity label is always set. This is
# necessary for PagerDuty's dynamic notifications.
#
# We multiply the `absent_over_time` by 2 so the value is mapped to a critical severity.
"expr": f"round(avg_over_time(command_status{{juju_unit='{unit_label}',command='{cmd}'}}[15m])) > 1"
+ f" or (absent_over_time(command_status{{juju_unit='{unit_label}',command='{cmd}'}}[10m]) == 1)"
+ f" or (absent_over_time(up{{juju_unit='{unit_label}'}}[10m]) == 1)",
+ f" or ((absent_over_time(command_status{{juju_unit='{unit_label}',command='{cmd}'}}[10m]) == 1))*2"
+ f" or ((absent_over_time(up{{juju_unit='{unit_label}'}}[10m]) == 1))*2",
"for": "0m",
"labels": {
"severity": "{{ if eq $value 0.0 -}} info {{- else if eq $value 1.0 -}} warning {{- else if eq $value 2.0 -}} critical {{- else if eq $value 3.0 -}} error {{- end }}",
Expand Down
Loading

0 comments on commit 73d8ee3

Please sign in to comment.