[v9.4.x] Alerting: Add static label to all state history entries (#62819)

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

* Add static label to all state history entries

* Separate label and value visually

(cherry picked from commit 647f73ddc5)

Co-authored-by: Alexander Weaver <weaver.alex.d@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2023-02-02 14:00:09 -06:00
committed by GitHub
co-authored by Alexander Weaver
parent 94ec932d29
commit 385b15bf69
2 changed files with 12 additions and 5 deletions
@@ -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)
@@ -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)
})