From 647f73ddc5e8a12364c7f495996a05dcf9865dff Mon Sep 17 00:00:00 2001 From: Alexander Weaver Date: Thu, 2 Feb 2023 13:25:26 -0600 Subject: [PATCH] Alerting: Add static label to all state history entries (#62817) * Add static label to all state history entries * Separate label and value visually --- pkg/services/ngalert/state/historian/loki.go | 6 ++++++ pkg/services/ngalert/state/historian/loki_test.go | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/services/ngalert/state/historian/loki.go b/pkg/services/ngalert/state/historian/loki.go index 1f9662a41e7..f46db89370c 100644 --- a/pkg/services/ngalert/state/historian/loki.go +++ b/pkg/services/ngalert/state/historian/loki.go @@ -22,6 +22,11 @@ const ( FolderUIDLabel = "folderUID" ) +const ( + StateHistoryLabelKey = "from" + StateHistoryLabelValue = "state-history" +) + type remoteLokiClient interface { ping(context.Context) error push(context.Context, []stream) error @@ -72,6 +77,7 @@ func statesToStreams(rule history_model.RuleMeta, states []state.StateTransition } labels := mergeLabels(removePrivateLabels(state.State.Labels), externalLabels) + labels[StateHistoryLabelKey] = StateHistoryLabelValue labels[OrgIDLabel] = fmt.Sprint(rule.OrgID) labels[RuleUIDLabel] = fmt.Sprint(rule.UID) labels[GroupLabel] = fmt.Sprint(rule.Group) diff --git a/pkg/services/ngalert/state/historian/loki_test.go b/pkg/services/ngalert/state/historian/loki_test.go index 0357bac6cc9..01d04cdcecd 100644 --- a/pkg/services/ngalert/state/historian/loki_test.go +++ b/pkg/services/ngalert/state/historian/loki_test.go @@ -59,11 +59,12 @@ func TestRemoteLokiBackend(t *testing.T) { require.Len(t, res, 1) exp := map[string]string{ - "folderUID": rule.NamespaceUID, - "group": rule.Group, - "orgID": fmt.Sprint(rule.OrgID), - "ruleUID": rule.UID, - "a": "b", + StateHistoryLabelKey: StateHistoryLabelValue, + "folderUID": rule.NamespaceUID, + "group": rule.Group, + "orgID": fmt.Sprint(rule.OrgID), + "ruleUID": rule.UID, + "a": "b", } require.Equal(t, exp, res[0].Stream) })