Remote Alertmanager: Use the correct OrgID when creating the store (#111634)

* Remote Alertmanager: Use the correct OrgID when creating the store

* fix test
This commit is contained in:
Santiago
2025-09-25 16:53:07 +00:00
committed by GitHub
parent 6629021f36
commit dab39c873f
4 changed files with 9 additions and 8 deletions
@@ -7,6 +7,7 @@ import (
alertingNotify "github.com/grafana/alerting/notify"
"github.com/grafana/grafana/pkg/infra/kvstore"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/tracing"
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
@@ -25,7 +26,7 @@ type RemotePrimaryForkedAlertmanager struct {
// NewRemotePrimaryFactory returns a function to override the default AM factory in the multi-org Alertmanager.
func NewRemotePrimaryFactory(
cfg AlertmanagerConfig,
store stateStore,
store kvstore.KVStore,
crypto Crypto,
autogenFn AutogenFn,
m *metrics.RemoteAlertmanager,
@@ -43,7 +44,7 @@ func NewRemotePrimaryFactory(
cfg.OrgID = orgID
cfg.PromoteConfig = true
l := log.New("ngalert.forked-alertmanager.remote-primary")
remoteAM, err := NewAlertmanager(ctx, cfg, store, crypto, autogenFn, m, t)
remoteAM, err := NewAlertmanager(ctx, cfg, notifier.NewFileStore(cfg.OrgID, store), crypto, autogenFn, m, t)
if err != nil {
l.Error("Failed to create remote Alertmanager, falling back to using only the internal one", "err", err)
return internalAM, nil
@@ -8,6 +8,7 @@ import (
alertingNotify "github.com/grafana/alerting/notify"
"github.com/grafana/grafana/pkg/infra/kvstore"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/tracing"
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
@@ -65,7 +66,7 @@ func (c *RemoteSecondaryConfig) Validate() error {
// NewRemoteSecondaryFactory returns a function to override the default AM factory in the multi-org Alertmanager.
func NewRemoteSecondaryFactory(
cfg AlertmanagerConfig,
stateStore stateStore,
store kvstore.KVStore,
cfgStore configStore,
syncInterval time.Duration,
crypto Crypto,
@@ -79,7 +80,7 @@ func NewRemoteSecondaryFactory(
// Create the remote Alertmanager first so we don't need to unregister internal AM metrics if this fails.
cfg.OrgID = orgID
l := log.New("ngalert.forked-alertmanager.remote-secondary")
remoteAM, err := NewAlertmanager(ctx, cfg, stateStore, crypto, autogenFn, m, t)
remoteAM, err := NewAlertmanager(ctx, cfg, notifier.NewFileStore(cfg.OrgID, store), crypto, autogenFn, m, t)
if err != nil && withRemoteState {
// We can't start the internal Alertmanager without the remote state.
return nil, fmt.Errorf("failed to create remote Alertmanager, can't start the internal Alertmanager without the remote state: %w", err)