mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Add rule ID and title to alert state history Loki entry (#79481)
* Add rule ID and title to Loki entry * Combine related tests
This commit is contained in:
parent
ce8fd14f1f
commit
9171bf92bb
@ -255,6 +255,8 @@ func statesToStream(rule history_model.RuleMeta, states []state.StateTransition,
|
||||
DashboardUID: rule.DashboardUID,
|
||||
PanelID: rule.PanelID,
|
||||
Fingerprint: labelFingerprint(sanitizedLabels),
|
||||
RuleTitle: rule.Title,
|
||||
RuleID: rule.ID,
|
||||
RuleUID: rule.UID,
|
||||
InstanceLabels: sanitizedLabels,
|
||||
}
|
||||
@ -300,6 +302,8 @@ type lokiEntry struct {
|
||||
DashboardUID string `json:"dashboardUID"`
|
||||
PanelID int64 `json:"panelID"`
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
RuleTitle string `json:"ruleTitle"`
|
||||
RuleID int64 `json:"ruleID"`
|
||||
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.
|
||||
|
@ -89,7 +89,7 @@ func TestRemoteLokiBackend(t *testing.T) {
|
||||
require.NotContains(t, res.Stream, "__private__")
|
||||
})
|
||||
|
||||
t.Run("includes ruleUID in log line", func(t *testing.T) {
|
||||
t.Run("includes rule data in log line", func(t *testing.T) {
|
||||
rule := createTestRule()
|
||||
l := log.NewNopLogger()
|
||||
states := singleFromNormal(&state.State{
|
||||
@ -98,8 +98,10 @@ func TestRemoteLokiBackend(t *testing.T) {
|
||||
})
|
||||
|
||||
res := statesToStream(rule, states, nil, l)
|
||||
|
||||
entry := requireSingleEntry(t, res)
|
||||
|
||||
require.Equal(t, rule.Title, entry.RuleTitle)
|
||||
require.Equal(t, rule.ID, entry.RuleID)
|
||||
require.Equal(t, rule.UID, entry.RuleUID)
|
||||
})
|
||||
|
||||
@ -525,11 +527,13 @@ func singleFromNormal(st *state.State) []state.StateTransition {
|
||||
func createTestRule() history_model.RuleMeta {
|
||||
return history_model.RuleMeta{
|
||||
OrgID: 1,
|
||||
ID: 123,
|
||||
UID: "rule-uid",
|
||||
Group: "my-group",
|
||||
NamespaceUID: "my-folder",
|
||||
DashboardUID: "dash-uid",
|
||||
PanelID: 123,
|
||||
Title: "my-title",
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user