Alerting: Return merged extra configurations in the API (#109636)
This commit is contained in:
@@ -83,7 +83,7 @@ func (srv AlertmanagerSrv) RouteDeleteAlertingConfig(c *contextmodel.ReqContext)
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetAlertingConfig(c *contextmodel.ReqContext) response.Response {
|
||||
canSeeAutogen := c.HasRole(org.RoleAdmin)
|
||||
config, err := srv.mam.GetAlertmanagerConfiguration(c.Req.Context(), c.GetOrgID(), canSeeAutogen)
|
||||
config, err := srv.mam.GetAlertmanagerConfiguration(c.Req.Context(), c.GetOrgID(), canSeeAutogen, false)
|
||||
if err != nil {
|
||||
if errors.Is(err, store.ErrNoAlertmanagerConfiguration) {
|
||||
return ErrResp(http.StatusNotFound, err, "")
|
||||
|
||||
@@ -135,7 +135,7 @@ type ConvertPrometheusSrv struct {
|
||||
type Alertmanager interface {
|
||||
DeleteExtraConfiguration(ctx context.Context, org int64, identifier string) error
|
||||
SaveAndApplyExtraConfiguration(ctx context.Context, org int64, extraConfig apimodels.ExtraConfiguration) error
|
||||
GetAlertmanagerConfiguration(ctx context.Context, org int64, withAutogen bool) (apimodels.GettableUserConfig, error)
|
||||
GetAlertmanagerConfiguration(ctx context.Context, org int64, withAutogen bool, withMergedExtraConfig bool) (apimodels.GettableUserConfig, error)
|
||||
}
|
||||
|
||||
func NewConvertPrometheusSrv(
|
||||
@@ -594,7 +594,7 @@ func (srv *ConvertPrometheusSrv) RouteConvertPrometheusGetAlertmanagerConfig(c *
|
||||
|
||||
identifier := parseConfigIdentifierHeader(c)
|
||||
|
||||
cfg, err := srv.am.GetAlertmanagerConfiguration(ctx, c.GetOrgID(), false)
|
||||
cfg, err := srv.am.GetAlertmanagerConfiguration(ctx, c.GetOrgID(), false, false)
|
||||
if err != nil {
|
||||
logger.Error("failed to get alertmanager configuration", "err", err)
|
||||
return errorToResponse(err)
|
||||
|
||||
@@ -1782,8 +1782,8 @@ func (m *mockAlertmanager) SaveAndApplyExtraConfiguration(ctx context.Context, o
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
func (m *mockAlertmanager) GetAlertmanagerConfiguration(ctx context.Context, org int64, withAutogen bool) (apimodels.GettableUserConfig, error) {
|
||||
args := m.Called(ctx, org, withAutogen)
|
||||
func (m *mockAlertmanager) GetAlertmanagerConfiguration(ctx context.Context, org int64, withAutogen bool, withMergedExtraConfig bool) (apimodels.GettableUserConfig, error) {
|
||||
args := m.Called(ctx, org, withAutogen, withMergedExtraConfig)
|
||||
return args.Get(0).(apimodels.GettableUserConfig), args.Error(1)
|
||||
}
|
||||
|
||||
@@ -1912,7 +1912,7 @@ func TestRouteConvertPrometheusGetAlertmanagerConfig(t *testing.T) {
|
||||
|
||||
t.Run("without config identifier header should use default identifier", func(t *testing.T) {
|
||||
mockAM := &mockAlertmanager{}
|
||||
mockAM.On("GetAlertmanagerConfiguration", mock.Anything, orgID, false).Return(apimodels.GettableUserConfig{
|
||||
mockAM.On("GetAlertmanagerConfiguration", mock.Anything, orgID, false, false).Return(apimodels.GettableUserConfig{
|
||||
ExtraConfigs: []apimodels.ExtraConfiguration{
|
||||
{
|
||||
Identifier: defaultConfigIdentifier,
|
||||
@@ -1935,7 +1935,7 @@ receivers:
|
||||
|
||||
t.Run("with empty config identifier header should use default identifier", func(t *testing.T) {
|
||||
mockAM := &mockAlertmanager{}
|
||||
mockAM.On("GetAlertmanagerConfiguration", mock.Anything, orgID, false).Return(apimodels.GettableUserConfig{
|
||||
mockAM.On("GetAlertmanagerConfiguration", mock.Anything, orgID, false, false).Return(apimodels.GettableUserConfig{
|
||||
ExtraConfigs: []apimodels.ExtraConfiguration{
|
||||
{
|
||||
Identifier: defaultConfigIdentifier,
|
||||
@@ -1983,7 +1983,7 @@ receivers:
|
||||
},
|
||||
}
|
||||
|
||||
mockAM.On("GetAlertmanagerConfiguration", mock.Anything, int64(1), false).Return(expectedConfig, nil).Once()
|
||||
mockAM.On("GetAlertmanagerConfiguration", mock.Anything, int64(1), false, false).Return(expectedConfig, nil).Once()
|
||||
|
||||
rc := createRequestCtx()
|
||||
rc.Req.Header.Set(configIdentifierHeader, identifier)
|
||||
@@ -2037,7 +2037,7 @@ receivers:
|
||||
},
|
||||
}
|
||||
|
||||
mockAM.On("GetAlertmanagerConfiguration", mock.Anything, orgID, false).Return(expectedConfig, nil).Once()
|
||||
mockAM.On("GetAlertmanagerConfiguration", mock.Anything, orgID, false, false).Return(expectedConfig, nil).Once()
|
||||
|
||||
rc := createRequestCtx()
|
||||
rc.Req.Header.Set(configIdentifierHeader, identifier)
|
||||
@@ -2052,7 +2052,7 @@ receivers:
|
||||
ft := featuremgmt.WithFeatures(featuremgmt.FlagAlertingImportAlertmanagerAPI)
|
||||
srv, _, _ := createConvertPrometheusSrv(t, withAlertmanager(mockAM), withFeatureToggles(ft))
|
||||
|
||||
mockAM.On("GetAlertmanagerConfiguration", mock.Anything, orgID, false).Return(apimodels.GettableUserConfig{}, errors.New("config error")).Once()
|
||||
mockAM.On("GetAlertmanagerConfiguration", mock.Anything, orgID, false, false).Return(apimodels.GettableUserConfig{}, errors.New("config error")).Once()
|
||||
|
||||
rc := createRequestCtx()
|
||||
rc.Req.Header.Set(configIdentifierHeader, identifier)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
amv2 "github.com/prometheus/alertmanager/api/v2/models"
|
||||
|
||||
@@ -11,11 +11,13 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
const extraConfigPrefix = "~grafana-converted-extra-config-"
|
||||
const withExtraConfigUID = "~grafana-with-extra-config"
|
||||
|
||||
type ConvertService interface {
|
||||
RouteConvertPrometheusGetAlertmanagerConfig(ctx *contextmodel.ReqContext) response.Response
|
||||
@@ -42,7 +44,7 @@ func NewForkingAM(datasourceCache datasources.CacheService, proxy *LotexAM, graf
|
||||
|
||||
func (f *AlertmanagerApiHandler) getService(ctx *contextmodel.ReqContext) (*LotexAM, error) {
|
||||
// If this is not an extra config request, we should check that the datasource exists and is of the correct type.
|
||||
if isExtra, _ := f.isExtraConfig(ctx); !isExtra {
|
||||
if isExtra := f.isExtraConfig(ctx); !isExtra {
|
||||
_, err := getDatasourceByUID(ctx, f.DatasourceCache, apimodels.AlertmanagerBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -54,22 +56,18 @@ func (f *AlertmanagerApiHandler) getService(ctx *contextmodel.ReqContext) (*Lote
|
||||
|
||||
// isExtraConfig checks if the datasourceUID represents an extra config.
|
||||
// Extra configs are the alertmanager configurations that were saved using the Prometheus conversion API.
|
||||
func (f *AlertmanagerApiHandler) isExtraConfig(ctx *contextmodel.ReqContext) (bool, string) {
|
||||
func (f *AlertmanagerApiHandler) isExtraConfig(ctx *contextmodel.ReqContext) bool {
|
||||
// Only enabled if feature flag is on
|
||||
if !f.FeatureManager.IsEnabledGlobally(featuremgmt.FlagAlertingImportAlertmanagerUI) {
|
||||
return false, ""
|
||||
return false
|
||||
}
|
||||
|
||||
datasourceUID := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
if strings.HasPrefix(datasourceUID, extraConfigPrefix) {
|
||||
identifier := strings.TrimPrefix(datasourceUID, extraConfigPrefix)
|
||||
return true, identifier
|
||||
}
|
||||
return false, ""
|
||||
return datasourceUID == withExtraConfigUID
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMStatus(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
if isExtra, _ := f.isExtraConfig(ctx); isExtra {
|
||||
if f.isExtraConfig(ctx) {
|
||||
status := apimodels.GettableStatus{
|
||||
Cluster: &amv2.ClusterStatus{
|
||||
Status: util.Pointer("ready"),
|
||||
@@ -87,7 +85,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetAMStatus(ctx *contextmodel.ReqCon
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteCreateSilence(ctx *contextmodel.ReqContext, body apimodels.PostableSilence, dsUID string) response.Response {
|
||||
if isExtra, _ := f.isExtraConfig(ctx); isExtra {
|
||||
if f.isExtraConfig(ctx) {
|
||||
return response.Error(http.StatusForbidden, "Read-only configuration", nil)
|
||||
}
|
||||
|
||||
@@ -100,7 +98,7 @@ func (f *AlertmanagerApiHandler) handleRouteCreateSilence(ctx *contextmodel.ReqC
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteAlertingConfig(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
if isExtra, _ := f.isExtraConfig(ctx); isExtra {
|
||||
if f.isExtraConfig(ctx) {
|
||||
return response.Error(http.StatusForbidden, "Read-only configuration", nil)
|
||||
}
|
||||
|
||||
@@ -113,7 +111,7 @@ func (f *AlertmanagerApiHandler) handleRouteDeleteAlertingConfig(ctx *contextmod
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteSilence(ctx *contextmodel.ReqContext, silenceID string, dsUID string) response.Response {
|
||||
if isExtra, _ := f.isExtraConfig(ctx); isExtra {
|
||||
if f.isExtraConfig(ctx) {
|
||||
return response.Error(http.StatusForbidden, "Read-only configuration", nil)
|
||||
}
|
||||
|
||||
@@ -126,18 +124,14 @@ func (f *AlertmanagerApiHandler) handleRouteDeleteSilence(ctx *contextmodel.ReqC
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAlertingConfig(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
if isExtra, identifier := f.isExtraConfig(ctx); isExtra {
|
||||
ctx.Req.Header.Set(configIdentifierHeader, identifier)
|
||||
ctx.Req.Header.Set("Accept", "application/yaml")
|
||||
|
||||
conversionResp := f.ConvertSvc.RouteConvertPrometheusGetAlertmanagerConfig(ctx)
|
||||
if conversionResp.Status() != http.StatusOK {
|
||||
return conversionResp
|
||||
}
|
||||
|
||||
config, err := yamlExtractor(&apimodels.GettableUserConfig{})(conversionResp.(*response.NormalResponse))
|
||||
if f.isExtraConfig(ctx) {
|
||||
canSeeAutogen := ctx.HasRole(org.RoleAdmin)
|
||||
config, err := f.GrafanaSvc.mam.GetAlertmanagerConfiguration(ctx.Req.Context(), ctx.GetOrgID(), canSeeAutogen, true)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to parse alertmanager config", err)
|
||||
if errors.Is(err, store.ErrNoAlertmanagerConfiguration) {
|
||||
return response.Error(http.StatusNotFound, "No configuration found", err)
|
||||
}
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get merged configuration", err)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, config)
|
||||
@@ -152,7 +146,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetAlertingConfig(ctx *contextmodel.
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMAlertGroups(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
if isExtra, _ := f.isExtraConfig(ctx); isExtra {
|
||||
if f.isExtraConfig(ctx) {
|
||||
return f.GrafanaSvc.RouteGetAMAlertGroups(ctx)
|
||||
}
|
||||
|
||||
@@ -165,7 +159,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetAMAlertGroups(ctx *contextmodel.R
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMAlerts(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
if isExtra, _ := f.isExtraConfig(ctx); isExtra {
|
||||
if f.isExtraConfig(ctx) {
|
||||
return f.GrafanaSvc.RouteGetAMAlerts(ctx)
|
||||
}
|
||||
|
||||
@@ -178,7 +172,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetAMAlerts(ctx *contextmodel.ReqCon
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetSilence(ctx *contextmodel.ReqContext, silenceID string, dsUID string) response.Response {
|
||||
if isExtra, _ := f.isExtraConfig(ctx); isExtra {
|
||||
if f.isExtraConfig(ctx) {
|
||||
return f.GrafanaSvc.RouteGetSilence(ctx, silenceID)
|
||||
}
|
||||
|
||||
@@ -191,7 +185,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetSilence(ctx *contextmodel.ReqCont
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetSilences(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
if isExtra, _ := f.isExtraConfig(ctx); isExtra {
|
||||
if f.isExtraConfig(ctx) {
|
||||
return f.GrafanaSvc.RouteGetSilences(ctx)
|
||||
}
|
||||
|
||||
@@ -204,7 +198,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetSilences(ctx *contextmodel.ReqCon
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostAlertingConfig(ctx *contextmodel.ReqContext, body apimodels.PostableUserConfig, dsUID string) response.Response {
|
||||
if isExtra, _ := f.isExtraConfig(ctx); isExtra {
|
||||
if f.isExtraConfig(ctx) {
|
||||
return response.Error(http.StatusForbidden, "Read-only configuration", nil)
|
||||
}
|
||||
|
||||
@@ -219,7 +213,7 @@ func (f *AlertmanagerApiHandler) handleRoutePostAlertingConfig(ctx *contextmodel
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostAMAlerts(ctx *contextmodel.ReqContext, body apimodels.PostableAlerts, dsUID string) response.Response {
|
||||
if isExtra, _ := f.isExtraConfig(ctx); isExtra {
|
||||
if f.isExtraConfig(ctx) {
|
||||
return response.Error(http.StatusForbidden, "Read-only configuration", nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
@@ -18,39 +16,34 @@ import (
|
||||
|
||||
func TestAlertmanagerApiHandler_isExtraConfig(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
datasourceUID string
|
||||
flagEnabled bool
|
||||
expectedIsExtra bool
|
||||
expectedIdentifier string
|
||||
name string
|
||||
datasourceUID string
|
||||
flagEnabled bool
|
||||
expectedIsExtra bool
|
||||
}{
|
||||
{
|
||||
name: "normal datasource when feature enabled",
|
||||
datasourceUID: "normal-datasource",
|
||||
flagEnabled: true,
|
||||
expectedIsExtra: false,
|
||||
expectedIdentifier: "",
|
||||
name: "normal datasource when feature enabled",
|
||||
datasourceUID: "normal-datasource",
|
||||
flagEnabled: true,
|
||||
expectedIsExtra: false,
|
||||
},
|
||||
{
|
||||
name: "extra config when feature enabled",
|
||||
datasourceUID: "~grafana-converted-extra-config-test-config",
|
||||
flagEnabled: true,
|
||||
expectedIsExtra: true,
|
||||
expectedIdentifier: "test-config",
|
||||
name: "extra config when feature enabled",
|
||||
datasourceUID: "~grafana-with-extra-config",
|
||||
flagEnabled: true,
|
||||
expectedIsExtra: true,
|
||||
},
|
||||
{
|
||||
name: "extra config when feature disabled",
|
||||
datasourceUID: "~grafana-converted-extra-config-test-config",
|
||||
flagEnabled: false,
|
||||
expectedIsExtra: false,
|
||||
expectedIdentifier: "",
|
||||
name: "extra config when feature disabled",
|
||||
datasourceUID: "~grafana-with-extra-config",
|
||||
flagEnabled: false,
|
||||
expectedIsExtra: false,
|
||||
},
|
||||
{
|
||||
name: "empty datasource UID",
|
||||
datasourceUID: "",
|
||||
flagEnabled: true,
|
||||
expectedIsExtra: false,
|
||||
expectedIdentifier: "",
|
||||
name: "empty datasource UID",
|
||||
datasourceUID: "",
|
||||
flagEnabled: true,
|
||||
expectedIsExtra: false,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -81,9 +74,8 @@ func TestAlertmanagerApiHandler_isExtraConfig(t *testing.T) {
|
||||
FeatureManager: features,
|
||||
}
|
||||
|
||||
isExtra, identifier := handler.isExtraConfig(ctx)
|
||||
isExtra := handler.isExtraConfig(ctx)
|
||||
assert.Equal(t, tt.expectedIsExtra, isExtra)
|
||||
assert.Equal(t, tt.expectedIdentifier, identifier)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -101,14 +93,14 @@ func TestAlertmanagerApiHandler_ExtraConfigRouting(t *testing.T) {
|
||||
}
|
||||
|
||||
ctx.Req = web.SetURLParams(req, map[string]string{
|
||||
":DatasourceUID": "~grafana-converted-extra-config-test",
|
||||
":DatasourceUID": "~grafana-with-extra-config",
|
||||
})
|
||||
|
||||
handler := &AlertmanagerApiHandler{
|
||||
FeatureManager: featuremgmt.WithFeatures(featuremgmt.FlagAlertingImportAlertmanagerUI),
|
||||
}
|
||||
|
||||
resp := handler.handleRouteGetAMStatus(ctx, "~grafana-converted-extra-config-test")
|
||||
resp := handler.handleRouteGetAMStatus(ctx, "~grafana-with-extra-config")
|
||||
require.Equal(t, http.StatusOK, resp.Status())
|
||||
})
|
||||
|
||||
@@ -124,80 +116,23 @@ func TestAlertmanagerApiHandler_ExtraConfigRouting(t *testing.T) {
|
||||
}
|
||||
|
||||
ctx.Req = web.SetURLParams(req, map[string]string{
|
||||
":DatasourceUID": "~grafana-converted-extra-config-test",
|
||||
":DatasourceUID": "~grafana-with-extra-config",
|
||||
})
|
||||
|
||||
handler := &AlertmanagerApiHandler{
|
||||
FeatureManager: featuremgmt.WithFeatures(featuremgmt.FlagAlertingImportAlertmanagerUI),
|
||||
}
|
||||
|
||||
resp := handler.handleRouteCreateSilence(ctx, apimodels.PostableSilence{}, "~grafana-converted-extra-config-test")
|
||||
resp := handler.handleRouteCreateSilence(ctx, apimodels.PostableSilence{}, "~grafana-with-extra-config")
|
||||
assert.Equal(t, http.StatusForbidden, resp.Status())
|
||||
|
||||
resp = handler.handleRouteDeleteAlertingConfig(ctx, "~grafana-converted-extra-config-test")
|
||||
resp = handler.handleRouteDeleteAlertingConfig(ctx, "~grafana-with-extra-config")
|
||||
assert.Equal(t, http.StatusForbidden, resp.Status())
|
||||
|
||||
resp = handler.handleRoutePostAlertingConfig(ctx, apimodels.PostableUserConfig{}, "~grafana-converted-extra-config-test")
|
||||
resp = handler.handleRoutePostAlertingConfig(ctx, apimodels.PostableUserConfig{}, "~grafana-with-extra-config")
|
||||
assert.Equal(t, http.StatusForbidden, resp.Status())
|
||||
|
||||
resp = handler.handleRoutePostAMAlerts(ctx, apimodels.PostableAlerts{}, "~grafana-converted-extra-config-test")
|
||||
resp = handler.handleRoutePostAMAlerts(ctx, apimodels.PostableAlerts{}, "~grafana-with-extra-config")
|
||||
assert.Equal(t, http.StatusForbidden, resp.Status())
|
||||
})
|
||||
|
||||
t.Run("GET extra config", func(t *testing.T) {
|
||||
req := &http.Request{
|
||||
Header: make(http.Header),
|
||||
}
|
||||
ctx := &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: req,
|
||||
},
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgID: 1,
|
||||
},
|
||||
}
|
||||
|
||||
ctx.Req = web.SetURLParams(req, map[string]string{
|
||||
":DatasourceUID": "~grafana-converted-extra-config-test-identifier",
|
||||
})
|
||||
|
||||
mockConvertSvc := &mockConvertService{}
|
||||
|
||||
yamlConfig := `alertmanager_config: |
|
||||
global: {}
|
||||
route:
|
||||
receiver: test-receiver
|
||||
receivers:
|
||||
- name: test-receiver`
|
||||
|
||||
mockResponse := response.Respond(http.StatusOK, yamlConfig).
|
||||
SetHeader("Content-Type", "application/yaml")
|
||||
|
||||
mockConvertSvc.On("RouteConvertPrometheusGetAlertmanagerConfig", mock.Anything).
|
||||
Run(func(args mock.Arguments) {
|
||||
passedCtx := args.Get(0).(*contextmodel.ReqContext)
|
||||
assert.Equal(t, "test-identifier", passedCtx.Req.Header.Get(configIdentifierHeader))
|
||||
assert.Equal(t, "application/yaml", passedCtx.Req.Header.Get("Accept"))
|
||||
}).
|
||||
Return(mockResponse)
|
||||
|
||||
handler := &AlertmanagerApiHandler{
|
||||
FeatureManager: featuremgmt.WithFeatures(featuremgmt.FlagAlertingImportAlertmanagerUI),
|
||||
ConvertSvc: mockConvertSvc,
|
||||
}
|
||||
|
||||
resp := handler.handleRouteGetAlertingConfig(ctx, "~grafana-converted-extra-config-test-identifier")
|
||||
assert.Equal(t, http.StatusOK, resp.Status())
|
||||
|
||||
mockConvertSvc.AssertExpectations(t)
|
||||
})
|
||||
}
|
||||
|
||||
type mockConvertService struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (m *mockConvertService) RouteConvertPrometheusGetAlertmanagerConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
args := m.Called(ctx)
|
||||
return args.Get(0).(response.Response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user