fix(grafana): accept null values/labels/annotations in webhook intake - #99
Closed
lshearing-lavanda wants to merge 1 commit into
Closed
lshearing-lavanda wants to merge 1 commit into
lshearing-lavanda wants to merge 1 commit into
Conversation
Grafana Alerting sends "values": null (and can send null labels/annotations)
for alerts that carry no reduced numeric values — e.g. the contact-point
"Test" notification and no-data/resolved transitions. GrafanaAlertSchema types
these as Dict[str, Any] with default_factory=dict, but default_factory only
applies when the key is ABSENT; an explicit null fails validation with
"Input should be a valid dictionary", so /api/integrations/grafana returns 400
and the alert is dropped.
Coerce null -> {} via a mode="before" field validator. Adds a regression test.
Member
|
Hello, and thank you, but it was closed in #94. Will be released with 2.3 in a week |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #98.
Problem
GrafanaAlertSchematypesvalues(andlabels/annotations) asDict[str, Any] = Field(default_factory=dict).default_factoryonly applieswhen the key is absent, so an explicit
"values": null— which GrafanaAlerting sends for alerts with no reduced numeric values (the contact-point
Test button, and no-data/resolved transitions) — fails validation with
Input should be a valid dictionary. The intake then returns400and thealert is dropped.
Fix
A
mode="before"field validator onGrafanaAlertSchemacoercesnull -> {}for
labels,annotationsandvalues, so these Grafana-native nulls areaccepted while every other input is untouched.
Test
Adds
test_grafana_alert_accepts_null_valuestotests/integrations/test_grafana_integration.py, asserting a payload withvalues: nullnormalizes without error and yieldsvalues == {}.Notes
alerts carry
valueslike{"B": 44.2, "C": 1}).intake: the contact-point "Test" button and no-data transitions were failing
with the 400 above.