[release-12.1.1] Alerting: Add rule group name validation to the Prometheus conversion API (#108767)
Alerting: Add rule group name validation to the Prometheus conversion API (#108740)
Alerting: Add rule group name validation to the conversion API
(cherry picked from commit f969eb0277)
Co-authored-by: Alexander Akhmetov <me@alx.cx>
This commit is contained in:
co-authored by
Alexander Akhmetov
parent
9c3ae92722
commit
302e95684d
@@ -291,6 +291,30 @@ func TestRouteConvertPrometheusPostRuleGroup(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("with empty rule group name should return 400", func(t *testing.T) {
|
||||
srv, _, _ := createConvertPrometheusSrv(t)
|
||||
rc := createRequestCtx()
|
||||
|
||||
emptyNameGroup := apimodels.PrometheusRuleGroup{
|
||||
Name: "",
|
||||
Interval: prommodel.Duration(1 * time.Minute),
|
||||
Rules: []apimodels.PrometheusRule{
|
||||
{
|
||||
Alert: "TestAlert",
|
||||
Expr: "up == 0",
|
||||
For: util.Pointer(prommodel.Duration(5 * time.Minute)),
|
||||
Labels: map[string]string{
|
||||
"severity": "critical",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
response := srv.RouteConvertPrometheusPostRuleGroup(rc, "test", emptyNameGroup)
|
||||
require.Equal(t, http.StatusBadRequest, response.Status())
|
||||
require.Contains(t, string(response.Body()), "rule group name must not be empty")
|
||||
})
|
||||
|
||||
t.Run("with valid request should return 202", func(t *testing.T) {
|
||||
srv, _, _ := createConvertPrometheusSrv(t)
|
||||
rc := createRequestCtx()
|
||||
|
||||
Reference in New Issue
Block a user