mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Simplify function signature for GetLatestAlertmanagerConfiguration (#79392)
This commit is contained in:
@@ -31,12 +31,11 @@ func (e AlertmanagerConfigRejectedError) Error() string {
|
||||
}
|
||||
|
||||
type configurationStore interface {
|
||||
GetLatestAlertmanagerConfiguration(ctx context.Context, query *models.GetLatestAlertmanagerConfigurationQuery) (*models.AlertConfiguration, error)
|
||||
GetLatestAlertmanagerConfiguration(ctx context.Context, orgID int64) (*models.AlertConfiguration, error)
|
||||
}
|
||||
|
||||
func (moa *MultiOrgAlertmanager) GetAlertmanagerConfiguration(ctx context.Context, org int64) (definitions.GettableUserConfig, error) {
|
||||
query := models.GetLatestAlertmanagerConfigurationQuery{OrgID: org}
|
||||
amConfig, err := moa.configStore.GetLatestAlertmanagerConfiguration(ctx, &query)
|
||||
amConfig, err := moa.configStore.GetLatestAlertmanagerConfiguration(ctx, org)
|
||||
if err != nil {
|
||||
return definitions.GettableUserConfig{}, fmt.Errorf("failed to get latest configuration: %w", err)
|
||||
}
|
||||
@@ -158,8 +157,7 @@ func (moa *MultiOrgAlertmanager) gettableUserConfigFromAMConfigString(ctx contex
|
||||
|
||||
func (moa *MultiOrgAlertmanager) ApplyAlertmanagerConfiguration(ctx context.Context, org int64, config definitions.PostableUserConfig) error {
|
||||
// Get the last known working configuration
|
||||
query := models.GetLatestAlertmanagerConfigurationQuery{OrgID: org}
|
||||
_, err := moa.configStore.GetLatestAlertmanagerConfiguration(ctx, &query)
|
||||
_, err := moa.configStore.GetLatestAlertmanagerConfiguration(ctx, org)
|
||||
if err != nil {
|
||||
// If we don't have a configuration there's nothing for us to know and we should just continue saving the new one
|
||||
if !errors.Is(err, store.ErrNoAlertmanagerConfiguration) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
||||
"github.com/grafana/grafana/pkg/services/secrets"
|
||||
)
|
||||
@@ -80,8 +79,7 @@ func EncryptReceiverConfigs(c []*definitions.PostableApiReceiver, encrypt defini
|
||||
// LoadSecureSettings adds the corresponding unencrypted secrets stored to the list of input receivers.
|
||||
func (c *alertmanagerCrypto) LoadSecureSettings(ctx context.Context, orgId int64, receivers []*definitions.PostableApiReceiver) error {
|
||||
// Get the last known working configuration.
|
||||
query := models.GetLatestAlertmanagerConfigurationQuery{OrgID: orgId}
|
||||
amConfig, err := c.configs.GetLatestAlertmanagerConfiguration(ctx, &query)
|
||||
amConfig, err := c.configs.GetLatestAlertmanagerConfiguration(ctx, orgId)
|
||||
if err != nil {
|
||||
// If we don't have a configuration there's nothing for us to know and we should just continue saving the new one.
|
||||
if !errors.Is(err, store.ErrNoAlertmanagerConfiguration) {
|
||||
|
||||
@@ -65,8 +65,8 @@ func (f *fakeConfigStore) GetAllLatestAlertmanagerConfiguration(context.Context)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (f *fakeConfigStore) GetLatestAlertmanagerConfiguration(_ context.Context, query *models.GetLatestAlertmanagerConfigurationQuery) (*models.AlertConfiguration, error) {
|
||||
config, ok := f.configs[query.OrgID]
|
||||
func (f *fakeConfigStore) GetLatestAlertmanagerConfiguration(_ context.Context, orgID int64) (*models.AlertConfiguration, error) {
|
||||
config, ok := f.configs[orgID]
|
||||
if !ok {
|
||||
return nil, store.ErrNoAlertmanagerConfiguration
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user