Alerting: Remote Alertmanager to calculate hash of the request payload instead of just the configuration (#108632)
* update CreateGrafanaAlertmanagerConfig to accept UserGrafanaConfig move construction logic to alertmanager * consolidate building UserGrafanaConfig into buildConfig * use config to determine whether it needs to be send calculate hash of the entire request struct rather than configuration
This commit is contained in:
@@ -39,10 +39,6 @@ type UserGrafanaConfig struct {
|
||||
SmtpConfig SmtpConfig `json:"smtp_config"`
|
||||
}
|
||||
|
||||
func (mc *Mimir) ShouldPromoteConfig() bool {
|
||||
return mc.promoteConfig
|
||||
}
|
||||
|
||||
func (mc *Mimir) GetGrafanaAlertmanagerConfig(ctx context.Context) (*UserGrafanaConfig, error) {
|
||||
gc := &UserGrafanaConfig{}
|
||||
response := successResponse{
|
||||
@@ -62,16 +58,8 @@ func (mc *Mimir) GetGrafanaAlertmanagerConfig(ctx context.Context) (*UserGrafana
|
||||
return gc, nil
|
||||
}
|
||||
|
||||
func (mc *Mimir) CreateGrafanaAlertmanagerConfig(ctx context.Context, cfg GrafanaAlertmanagerConfig, hash string, createdAt int64, isDefault bool) error {
|
||||
payload, err := definition.MarshalJSONWithSecrets(&UserGrafanaConfig{
|
||||
GrafanaAlertmanagerConfig: cfg,
|
||||
Hash: hash,
|
||||
CreatedAt: createdAt,
|
||||
Default: isDefault,
|
||||
Promoted: mc.promoteConfig,
|
||||
ExternalURL: mc.externalURL,
|
||||
SmtpConfig: mc.smtpConfig,
|
||||
})
|
||||
func (mc *Mimir) CreateGrafanaAlertmanagerConfig(ctx context.Context, cfg *UserGrafanaConfig) error {
|
||||
payload, err := definition.MarshalJSONWithSecrets(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -30,26 +30,21 @@ type MimirClient interface {
|
||||
DeleteGrafanaAlertmanagerState(ctx context.Context) error
|
||||
|
||||
GetGrafanaAlertmanagerConfig(ctx context.Context) (*UserGrafanaConfig, error)
|
||||
CreateGrafanaAlertmanagerConfig(ctx context.Context, configuration GrafanaAlertmanagerConfig, hash string, createdAt int64, isDefault bool) error
|
||||
CreateGrafanaAlertmanagerConfig(ctx context.Context, config *UserGrafanaConfig) error
|
||||
DeleteGrafanaAlertmanagerConfig(ctx context.Context) error
|
||||
|
||||
TestTemplate(ctx context.Context, c alertingNotify.TestTemplatesConfigBodyParams) (*alertingNotify.TestTemplatesResults, error)
|
||||
TestReceivers(ctx context.Context, c alertingNotify.TestReceiversConfigBodyParams) (*alertingNotify.TestReceiversResult, int, error)
|
||||
|
||||
ShouldPromoteConfig() bool
|
||||
|
||||
// Mimir implements an extended version of the receivers API under a different path.
|
||||
GetReceivers(ctx context.Context) ([]apimodels.Receiver, error)
|
||||
}
|
||||
|
||||
type Mimir struct {
|
||||
client client.Requester
|
||||
endpoint *url.URL
|
||||
logger log.Logger
|
||||
metrics *metrics.RemoteAlertmanager
|
||||
promoteConfig bool
|
||||
externalURL string
|
||||
smtpConfig SmtpConfig
|
||||
client client.Requester
|
||||
endpoint *url.URL
|
||||
logger log.Logger
|
||||
metrics *metrics.RemoteAlertmanager
|
||||
}
|
||||
|
||||
type SmtpConfig struct {
|
||||
@@ -69,10 +64,7 @@ type Config struct {
|
||||
TenantID string
|
||||
Password string
|
||||
|
||||
Logger log.Logger
|
||||
PromoteConfig bool
|
||||
ExternalURL string
|
||||
Smtp SmtpConfig
|
||||
Logger log.Logger
|
||||
}
|
||||
|
||||
// successResponse represents a successful response from the Mimir API.
|
||||
@@ -110,13 +102,10 @@ func New(cfg *Config, metrics *metrics.RemoteAlertmanager, tracer tracing.Tracer
|
||||
trc := client.NewTracedClient(tc, tracer, "remote.alertmanager.client")
|
||||
|
||||
return &Mimir{
|
||||
endpoint: cfg.URL,
|
||||
client: trc,
|
||||
logger: cfg.Logger,
|
||||
metrics: metrics,
|
||||
promoteConfig: cfg.PromoteConfig,
|
||||
externalURL: cfg.ExternalURL,
|
||||
smtpConfig: cfg.Smtp,
|
||||
endpoint: cfg.URL,
|
||||
client: trc,
|
||||
logger: cfg.Logger,
|
||||
metrics: metrics,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user