Alerting: Add endpoint to revert to a previous alertmanager configuration (#65751)

* Alerting: Add endpoint to revert to a previous alertmanager configuration

This endpoint is meant to be used in conjunction with /api/alertmanager/grafana/config/history to
revert to a previously applied alertmanager configuration. This is done by ID instead of raw config
string in order to avoid secure field complications.
This commit is contained in:
Matthew Jacobson
2023-04-05 14:10:03 -04:00
committed by GitHub
parent 6c6427e63f
commit 85f738cdf9
16 changed files with 393 additions and 9 deletions
@@ -381,6 +381,46 @@ func TestRouteGetAlertingConfigHistory(t *testing.T) {
})
}
func TestRoutePostGrafanaAlertingConfigHistoryActivate(t *testing.T) {
sut := createSut(t, nil)
t.Run("assert 404 when no historical configurations are found", func(tt *testing.T) {
req, err := http.NewRequest(http.MethodGet, "https://grafana.net", nil)
require.NoError(tt, err)
q := req.URL.Query()
req.URL.RawQuery = q.Encode()
rc := createRequestCtxInOrg(10)
response := sut.RoutePostGrafanaAlertingConfigHistoryActivate(rc, "0")
require.Equal(tt, 404, response.Status())
})
t.Run("assert 202 for a valid org and id", func(tt *testing.T) {
req, err := http.NewRequest(http.MethodGet, "https://grafana.net", nil)
require.NoError(tt, err)
q := req.URL.Query()
req.URL.RawQuery = q.Encode()
rc := createRequestCtxInOrg(1)
response := sut.RoutePostGrafanaAlertingConfigHistoryActivate(rc, "0")
require.Equal(tt, 202, response.Status())
})
t.Run("assert 400 when id is not parseable", func(tt *testing.T) {
req, err := http.NewRequest(http.MethodGet, "https://grafana.net", nil)
require.NoError(tt, err)
q := req.URL.Query()
req.URL.RawQuery = q.Encode()
rc := createRequestCtxInOrg(1)
response := sut.RoutePostGrafanaAlertingConfigHistoryActivate(rc, "abc")
require.Equal(tt, 400, response.Status())
})
}
func TestSilenceCreate(t *testing.T) {
makeSilence := func(comment string, createdBy string,
startsAt, endsAt strfmt.DateTime, matchers amv2.Matchers) amv2.Silence {