mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Send external URL to the remote Alertmanager (#89701)
* Alerting: Send external URL to the remote Alertmanager * test that the URL is sent to the remote Alertmanager * AppURL -> ExternalURL
This commit is contained in:
parent
3db4e5a0c6
commit
fe1309dd96
@ -203,6 +203,7 @@ func (ng *AlertNG) init() error {
|
||||
URL: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.URL,
|
||||
PromoteConfig: true,
|
||||
SyncInterval: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.SyncInterval,
|
||||
ExternalURL: ng.Cfg.AppURL,
|
||||
}
|
||||
remoteAM, err := createRemoteAlertmanager(cfg, ng.KVStore, ng.SecretsService.Decrypt, autogenFn, m, ng.tracer)
|
||||
if err != nil {
|
||||
@ -237,6 +238,7 @@ func (ng *AlertNG) init() error {
|
||||
PromoteConfig: true,
|
||||
TenantID: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.TenantID,
|
||||
URL: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.URL,
|
||||
ExternalURL: ng.Cfg.AppURL,
|
||||
}
|
||||
remoteAM, err := createRemoteAlertmanager(cfg, ng.KVStore, ng.SecretsService.Decrypt, autogenFn, m, ng.tracer)
|
||||
if err != nil {
|
||||
@ -273,6 +275,7 @@ func (ng *AlertNG) init() error {
|
||||
TenantID: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.TenantID,
|
||||
URL: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.URL,
|
||||
SyncInterval: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.SyncInterval,
|
||||
ExternalURL: ng.Cfg.AppURL,
|
||||
}
|
||||
remoteAM, err := createRemoteAlertmanager(cfg, ng.KVStore, ng.SecretsService.Decrypt, autogenFn, m, ng.tracer)
|
||||
if err != nil {
|
||||
|
@ -77,10 +77,12 @@ type AlertmanagerConfig struct {
|
||||
BasicAuthPassword string
|
||||
|
||||
DefaultConfig string
|
||||
|
||||
// ExternalURL is used in notifications sent by the remote Alertmanager.
|
||||
ExternalURL string
|
||||
// PromoteConfig is a flag that determines whether the configuration should be used in the remote Alertmanager.
|
||||
// The same flag is used for promoting state.
|
||||
PromoteConfig bool
|
||||
|
||||
// SyncInterval determines how often we should attempt to synchronize configuration.
|
||||
SyncInterval time.Duration
|
||||
}
|
||||
@ -117,6 +119,7 @@ func NewAlertmanager(cfg AlertmanagerConfig, store stateStore, decryptFn Decrypt
|
||||
TenantID: cfg.TenantID,
|
||||
URL: u,
|
||||
PromoteConfig: cfg.PromoteConfig,
|
||||
ExternalURL: cfg.ExternalURL,
|
||||
}
|
||||
mc, err := remoteClient.New(mcCfg, metrics, tracer)
|
||||
if err != nil {
|
||||
|
@ -168,6 +168,7 @@ func TestApplyConfig(t *testing.T) {
|
||||
DefaultConfig: defaultGrafanaConfig,
|
||||
PromoteConfig: true,
|
||||
SyncInterval: 1 * time.Hour,
|
||||
ExternalURL: "https://test.grafana.com",
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
@ -198,6 +199,9 @@ func TestApplyConfig(t *testing.T) {
|
||||
require.JSONEq(t, testGrafanaConfigWithSecret, string(amCfg))
|
||||
require.True(t, configSent.Promoted)
|
||||
|
||||
// Grafana's URL should be sent alongside the configuration.
|
||||
require.Equal(t, cfg.ExternalURL, configSent.ExternalURL)
|
||||
|
||||
// If we already got a 200 status code response and the sync interval hasn't elapsed,
|
||||
// we shouldn't send the state/configuration again.
|
||||
expStateSync := lastStateSync
|
||||
|
@ -21,6 +21,7 @@ type UserGrafanaConfig struct {
|
||||
CreatedAt int64 `json:"created"`
|
||||
Default bool `json:"default"`
|
||||
Promoted bool `json:"promoted"`
|
||||
ExternalURL string `json:"external_url"`
|
||||
}
|
||||
|
||||
func (mc *Mimir) ShouldPromoteConfig() bool {
|
||||
@ -53,6 +54,7 @@ func (mc *Mimir) CreateGrafanaAlertmanagerConfig(ctx context.Context, cfg *apimo
|
||||
CreatedAt: createdAt,
|
||||
Default: isDefault,
|
||||
Promoted: mc.promoteConfig,
|
||||
ExternalURL: mc.externalURL,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -40,6 +40,7 @@ type Mimir struct {
|
||||
logger log.Logger
|
||||
metrics *metrics.RemoteAlertmanager
|
||||
promoteConfig bool
|
||||
externalURL string
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
@ -49,6 +50,7 @@ type Config struct {
|
||||
|
||||
Logger log.Logger
|
||||
PromoteConfig bool
|
||||
ExternalURL string
|
||||
}
|
||||
|
||||
// successResponse represents a successful response from the Mimir API.
|
||||
@ -91,6 +93,7 @@ func New(cfg *Config, metrics *metrics.RemoteAlertmanager, tracer tracing.Tracer
|
||||
logger: cfg.Logger,
|
||||
metrics: metrics,
|
||||
promoteConfig: cfg.PromoteConfig,
|
||||
externalURL: cfg.ExternalURL,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user