Sanitize and send alert's annotations as structured metadata to Loki

pull/101196/head
Mostafa Moradian 5 months ago
parent eecf43730c
commit d0a50c23e2
No known key found for this signature in database
GPG Key ID: F77FCEA0D3854DA3
  1. 30
      pkg/services/ngalert/state/historian/loki.go

@ -284,19 +284,22 @@ func StatesToStream(rule history_model.RuleMeta, states []state.StateTransition,
}
sanitizedLabels := removePrivateLabels(state.Labels)
sanitizedStructuredMetadata := removePrivateLabels(state.Annotations)
entry := LokiEntry{
SchemaVersion: 1,
Previous: state.PreviousFormatted(),
Current: state.Formatted(),
Values: valuesAsDataBlob(state.State),
Condition: rule.Condition,
DashboardUID: rule.DashboardUID,
PanelID: rule.PanelID,
Fingerprint: labelFingerprint(sanitizedLabels),
RuleTitle: rule.Title,
RuleID: rule.ID,
RuleUID: rule.UID,
InstanceLabels: sanitizedLabels,
SchemaVersion: 1,
Previous: state.PreviousFormatted(),
Current: state.Formatted(),
Values: valuesAsDataBlob(state.State),
Condition: rule.Condition,
DashboardUID: rule.DashboardUID,
PanelID: rule.PanelID,
Fingerprint: labelFingerprint(sanitizedLabels),
RuleTitle: rule.Title,
RuleID: rule.ID,
RuleUID: rule.UID,
InstanceLabels: sanitizedLabels,
StructuredMetadata: sanitizedStructuredMetadata,
}
if state.State.State == eval.Error {
entry.Error = state.Error.Error()
@ -345,7 +348,8 @@ type LokiEntry struct {
RuleUID string `json:"ruleUID"`
// InstanceLabels is exactly the set of labels associated with the alert instance in Alertmanager.
// These should not be conflated with labels associated with log streams.
InstanceLabels map[string]string `json:"labels"`
InstanceLabels map[string]string `json:"labels"`
StructuredMetadata map[string]string `json:"structuredMetadata,omitempty"`
}
func valuesAsDataBlob(state *state.State) *simplejson.Json {

Loading…
Cancel
Save