Alerting: Add static label to all state history entries (#62817)

* Add static label to all state history entries

* Separate label and value visually
pull/62822/head
Alexander Weaver 2 years ago committed by GitHub
parent 40ec4ef5b8
commit 647f73ddc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      pkg/services/ngalert/state/historian/loki.go
  2. 11
      pkg/services/ngalert/state/historian/loki_test.go

@ -22,6 +22,11 @@ const (
FolderUIDLabel = "folderUID" FolderUIDLabel = "folderUID"
) )
const (
StateHistoryLabelKey = "from"
StateHistoryLabelValue = "state-history"
)
type remoteLokiClient interface { type remoteLokiClient interface {
ping(context.Context) error ping(context.Context) error
push(context.Context, []stream) 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 := mergeLabels(removePrivateLabels(state.State.Labels), externalLabels)
labels[StateHistoryLabelKey] = StateHistoryLabelValue
labels[OrgIDLabel] = fmt.Sprint(rule.OrgID) labels[OrgIDLabel] = fmt.Sprint(rule.OrgID)
labels[RuleUIDLabel] = fmt.Sprint(rule.UID) labels[RuleUIDLabel] = fmt.Sprint(rule.UID)
labels[GroupLabel] = fmt.Sprint(rule.Group) labels[GroupLabel] = fmt.Sprint(rule.Group)

@ -59,11 +59,12 @@ func TestRemoteLokiBackend(t *testing.T) {
require.Len(t, res, 1) require.Len(t, res, 1)
exp := map[string]string{ exp := map[string]string{
"folderUID": rule.NamespaceUID, StateHistoryLabelKey: StateHistoryLabelValue,
"group": rule.Group, "folderUID": rule.NamespaceUID,
"orgID": fmt.Sprint(rule.OrgID), "group": rule.Group,
"ruleUID": rule.UID, "orgID": fmt.Sprint(rule.OrgID),
"a": "b", "ruleUID": rule.UID,
"a": "b",
} }
require.Equal(t, exp, res[0].Stream) require.Equal(t, exp, res[0].Stream)
}) })

Loading…
Cancel
Save