Alerting: Metric to count imported from Prometheus rules (#100847)
This commit is contained in:
@@ -457,9 +457,9 @@ func grafanaRuleGroupToPrometheus(group string, rules []models.AlertRule) (apimo
|
||||
}
|
||||
|
||||
for i, rule := range rules {
|
||||
promDefinition := rule.PrometheusRuleDefinition()
|
||||
if promDefinition == "" {
|
||||
return apimodels.PrometheusRuleGroup{}, fmt.Errorf("failed to get the Prometheus definition of the rule with UID %s", rule.UID)
|
||||
promDefinition, err := rule.PrometheusRuleDefinition()
|
||||
if err != nil {
|
||||
return apimodels.PrometheusRuleGroup{}, fmt.Errorf("failed to get the Prometheus definition of the rule with UID %s: %w", rule.UID, err)
|
||||
}
|
||||
var r apimodels.PrometheusRule
|
||||
if err := yaml.Unmarshal([]byte(promDefinition), &r); err != nil {
|
||||
|
||||
@@ -115,7 +115,10 @@ func TestRouteConvertPrometheusPostRuleGroup(t *testing.T) {
|
||||
require.Equal(t, fmt.Sprintf("[%s] %s", simpleGroup.Name, simpleGroup.Rules[0].Alert), remaining[0].Title)
|
||||
promRuleYAML, err := yaml.Marshal(simpleGroup.Rules[0])
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, string(promRuleYAML), remaining[0].PrometheusRuleDefinition())
|
||||
|
||||
promDefinition, err := remaining[0].PrometheusRuleDefinition()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, string(promRuleYAML), promDefinition)
|
||||
})
|
||||
|
||||
t.Run("should fail to replace a provisioned rule group", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user