mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
Alerting: Capture refID of rule's condition expression in Loki state history entries (#66419)
* Capture condition from rule * Add test
This commit is contained in:
parent
a21fdd9c81
commit
cf7157f683
@ -260,6 +260,7 @@ func statesToStream(rule history_model.RuleMeta, states []state.StateTransition,
|
||||
Previous: state.PreviousFormatted(),
|
||||
Current: state.Formatted(),
|
||||
Values: valuesAsDataBlob(state.State),
|
||||
Condition: rule.Condition,
|
||||
DashboardUID: rule.DashboardUID,
|
||||
PanelID: rule.PanelID,
|
||||
InstanceLabels: removePrivateLabels(state.Labels),
|
||||
@ -302,6 +303,7 @@ type lokiEntry struct {
|
||||
Current string `json:"current"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Values *simplejson.Json `json:"values"`
|
||||
Condition string `json:"condition"`
|
||||
DashboardUID string `json:"dashboardUID"`
|
||||
PanelID int64 `json:"panelID"`
|
||||
// InstanceLabels is exactly the set of labels associated with the alert instance in Alertmanager.
|
||||
|
@ -139,6 +139,21 @@ func TestRemoteLokiBackend(t *testing.T) {
|
||||
require.InDelta(t, 2.0, entry.Values.Get("A").MustFloat64(), 1e-4)
|
||||
require.InDelta(t, 5.5, entry.Values.Get("B").MustFloat64(), 1e-4)
|
||||
})
|
||||
|
||||
t.Run("captures condition from rule", func(t *testing.T) {
|
||||
rule := createTestRule()
|
||||
rule.Condition = "some-condition"
|
||||
l := log.NewNopLogger()
|
||||
states := singleFromNormal(&state.State{
|
||||
State: eval.Alerting,
|
||||
Labels: data.Labels{"a": "b"},
|
||||
})
|
||||
|
||||
res := statesToStream(rule, states, nil, l)
|
||||
|
||||
entry := requireSingleEntry(t, res)
|
||||
require.Equal(t, rule.Condition, entry.Condition)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("selector string", func(t *testing.T) {
|
||||
|
@ -19,6 +19,7 @@ type RuleMeta struct {
|
||||
NamespaceUID string
|
||||
DashboardUID string
|
||||
PanelID int64
|
||||
Condition string
|
||||
}
|
||||
|
||||
func NewRuleMeta(r *models.AlertRule, log log.Logger) RuleMeta {
|
||||
@ -43,6 +44,7 @@ func NewRuleMeta(r *models.AlertRule, log log.Logger) RuleMeta {
|
||||
NamespaceUID: r.NamespaceUID,
|
||||
DashboardUID: dashUID,
|
||||
PanelID: panelID,
|
||||
Condition: r.Condition,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user