Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ValidateConfig of all receivers to accept only what is needed #61

Merged
merged 6 commits into from
Feb 23, 2023

Conversation

yuri-tceretian
Copy link
Contributor

Currently, every ValidateConfig accepts entire receivers.FactoryConfig and takes only 3 fields at best: raw settings, secure settings map, and decrypt function.
This PR refactors those functions to accept only two parameters (sometimes one):

  • raw settings
  • a decrypt function func(key string, fallback string) string as you can see it does not accept the secure settings (and context). The reason is to hide the way secure settings are stored.

Also, currently, some functions return Config struct and some pointer *Config. This PR refactors those that return pointer to return struct.

No public API of this package are changed.

@yuri-tceretian yuri-tceretian added enhancement New feature or request kata:am_unify labels Feb 14, 2023
@yuri-tceretian yuri-tceretian self-assigned this Feb 14, 2023
@@ -42,6 +44,10 @@ type FactoryConfig struct {
Logger logging.Logger
}

func (fc *FactoryConfig) Decrypt(key, fallback string) string {
return fc.DecryptFunc(context.Background(), fc.Config.SecureSettings, key, fallback)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a wrapper to hide secure settings and context from notifier's config builder

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured it out - this is a nice change - not sure if that context.Background() might cause us more hard than good in the end but let's roll with it for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

To hide implementation details of secrets storage from config parser, and reduce the scope for functions NewConfig. The context will be enclosed upstream (in Grafana) where it makes sense because it provides a secret service that requires context.

@yuri-tceretian yuri-tceretian force-pushed the yuri-tceretian/refactor-configs branch 3 times, most recently from 77f76d4 to 5bde521 Compare February 14, 2023 21:21
Copy link
Collaborator

@gotjosh gotjosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but please look at my comment, I think we need one more quick change.

Comment on lines -14 to -21
func NewFactoryConfigForValidateConfigTesting(t *testing.T, m *receivers.NotificationChannelConfig) (receivers.FactoryConfig, error) {
tmpl := templates.ForTests(t)
tmpl.ExternalURL = ParseURLUnsafe("http://localhost")
return receivers.NewFactoryConfig(m, nil, DecryptForTesting, tmpl, &images.UnavailableImageStore{}, func(ctx ...interface{}) logging.Logger {
return &logging.FakeLogger{}
}, "1.2.3")
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming that all this setup (the templates, the logger, etc) was never used in the places where we setup this configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much, yes

@@ -42,6 +44,10 @@ type FactoryConfig struct {
Logger logging.Logger
}

func (fc *FactoryConfig) Decrypt(key, fallback string) string {
return fc.DecryptFunc(context.Background(), fc.Config.SecureSettings, key, fallback)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured it out - this is a nice change - not sure if that context.Background() might cause us more hard than good in the end but let's roll with it for now.

receivers/alertmanager/config.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@gotjosh gotjosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yuri-tceretian yuri-tceretian merged commit f5fde7b into main Feb 23, 2023
@yuri-tceretian yuri-tceretian deleted the yuri-tceretian/refactor-configs branch February 23, 2023 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request kata:am_unify
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants