Alerting: Fetch all applied alerting configurations (#65728)
* WIP * skip invalid historic configurations instead of erroring * add warning log when bad historic config is found * remove unused custom marshaller for GettableHistoricUserConfig * add id to historic user config, move limit check to store, fix typo * swagger spec
This commit is contained in:
@@ -291,6 +291,96 @@ func TestAlertmanagerConfig(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRouteGetAlertingConfigHistory(t *testing.T) {
|
||||
sut := createSut(t, nil)
|
||||
|
||||
t.Run("assert 200 and empty slice when no applied 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()
|
||||
q.Add("limit", "10")
|
||||
req.URL.RawQuery = q.Encode()
|
||||
|
||||
rc := createRequestCtxInOrg(10)
|
||||
|
||||
response := sut.RouteGetAlertingConfigHistory(rc)
|
||||
require.Equal(tt, 200, response.Status())
|
||||
|
||||
var configs []apimodels.GettableHistoricUserConfig
|
||||
err = json.Unmarshal(response.Body(), &configs)
|
||||
require.NoError(tt, err)
|
||||
|
||||
require.Len(tt, configs, 0)
|
||||
})
|
||||
|
||||
t.Run("assert 200 and one config in the response for an org that has one successfully applied configuration", func(tt *testing.T) {
|
||||
req, err := http.NewRequest(http.MethodGet, "https://grafana.net", nil)
|
||||
require.NoError(tt, err)
|
||||
q := req.URL.Query()
|
||||
q.Add("limit", "10")
|
||||
req.URL.RawQuery = q.Encode()
|
||||
|
||||
rc := createRequestCtxInOrg(1)
|
||||
|
||||
response := sut.RouteGetAlertingConfigHistory(rc)
|
||||
require.Equal(tt, 200, response.Status())
|
||||
|
||||
var configs []apimodels.GettableHistoricUserConfig
|
||||
err = json.Unmarshal(response.Body(), &configs)
|
||||
require.NoError(tt, err)
|
||||
|
||||
require.Len(tt, configs, 1)
|
||||
})
|
||||
|
||||
t.Run("assert 200 when no limit is provided", func(tt *testing.T) {
|
||||
rc := createRequestCtxInOrg(1)
|
||||
|
||||
response := sut.RouteGetAlertingConfigHistory(rc)
|
||||
require.Equal(tt, 200, response.Status())
|
||||
|
||||
configs := asGettableHistoricUserConfigs(tt, response)
|
||||
for _, config := range configs {
|
||||
require.NotZero(tt, config.LastApplied)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("assert 200 when limit is < 1", func(tt *testing.T) {
|
||||
req, err := http.NewRequest(http.MethodGet, "https://grafana.net", nil)
|
||||
require.NoError(tt, err)
|
||||
q := req.URL.Query()
|
||||
q.Add("limit", "0")
|
||||
req.URL.RawQuery = q.Encode()
|
||||
|
||||
rc := createRequestCtxInOrg(1)
|
||||
|
||||
response := sut.RouteGetAlertingConfigHistory(rc)
|
||||
require.Equal(tt, 200, response.Status())
|
||||
|
||||
configs := asGettableHistoricUserConfigs(tt, response)
|
||||
for _, config := range configs {
|
||||
require.NotZero(tt, config.LastApplied)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("assert 200 when limit is > 100", func(tt *testing.T) {
|
||||
req, err := http.NewRequest(http.MethodGet, "https://grafana.net", nil)
|
||||
require.NoError(tt, err)
|
||||
q := req.URL.Query()
|
||||
q.Add("limit", "1000")
|
||||
req.URL.RawQuery = q.Encode()
|
||||
|
||||
rc := createRequestCtxInOrg(1)
|
||||
|
||||
response := sut.RouteGetAlertingConfigHistory(rc)
|
||||
require.Equal(tt, 200, response.Status())
|
||||
|
||||
configs := asGettableHistoricUserConfigs(tt, response)
|
||||
for _, config := range configs {
|
||||
require.NotZero(tt, config.LastApplied)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestSilenceCreate(t *testing.T) {
|
||||
makeSilence := func(comment string, createdBy string,
|
||||
startsAt, endsAt strfmt.DateTime, matchers amv2.Matchers) amv2.Silence {
|
||||
@@ -661,3 +751,11 @@ func asGettableUserConfig(t *testing.T, r response.Response) *apimodels.Gettable
|
||||
require.NoError(t, err)
|
||||
return body
|
||||
}
|
||||
|
||||
func asGettableHistoricUserConfigs(t *testing.T, r response.Response) []apimodels.GettableHistoricUserConfig {
|
||||
t.Helper()
|
||||
var body []apimodels.GettableHistoricUserConfig
|
||||
err := json.Unmarshal(r.Body(), &body)
|
||||
require.NoError(t, err)
|
||||
return body
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user