-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Make watcher settings reloadable #31746
Conversation
This commit allows for rebuilding watcher secure secrets via the reload_secure_settings API call. The commit also renames a method in the Notification Service to make it a bit more readable.
Pinging @elastic/es-core-infra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left a few comments
@@ -221,6 +224,11 @@ | |||
protected final boolean transportClient; | |||
protected final boolean enabled; | |||
protected final Environment env; | |||
private SetOnce<EmailService> emailService = new SetOnce<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about a List<NotificationService>
that you fill in createComponents
? This way you could get rid of the getReloadableServices()
method entirely and loop through that list in the reload()
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -30,7 +30,7 @@ public NotificationService(Settings settings, String type) { | |||
this.type = type; | |||
} | |||
|
|||
protected synchronized void setAccountSetting(Settings settings) { | |||
public synchronized void loadSettings(Settings settings) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about naming this reload()
as well just like in ReloadablePlugin
plugin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason i did not name it reload is because it is used to init settings as well, but ill change it to reload
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
153a97b
@@ -45,7 +45,7 @@ public PagerDutyService(Settings settings, HttpClient httpClient, ClusterSetting | |||
clusterSettings.addAffixUpdateConsumer(SETTING_SERVICE_API_KEY, (s, o) -> {}, (s, o) -> {}); | |||
clusterSettings.addAffixUpdateConsumer(SETTING_SECURE_SERVICE_API_KEY, (s, o) -> {}, (s, o) -> {}); | |||
clusterSettings.addAffixUpdateConsumer(SETTING_DEFAULTS, (s, o) -> {}, (s, o) -> {}); | |||
setAccountSetting(settings); | |||
loadSettings(settings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this PagerDutyService missing
clusterSettings.addSettingsUpdateConsumer(this::loadSettings, getSettings());
in its ctor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to prevent this mistake, you could move
clusterSettings.addSettingsUpdateConsumer(this::loadSettings, getSettings());
into the NotificationService
constructor and pass the getSettings()
as arg to super()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could also just have NotificationService
impl a getSettings
that the services overwrite. which is best?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh, nm, its static, it would be more work to change all that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im doing this in another commit, to ensure it does not muddy up this pull request. Ill edit this comment w/ the new PR once ive finished testing.
PR #31762
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#31762 has been merged
|
||
public void testReload() throws Exception { | ||
Settings settings = Settings.builder() | ||
.put("xpack.watcher.enabled", false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
watcher is not enabled, but reloading works? That could be a noop in this case, or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively you could mock a NotificationService and check with verify
if the loadSettings
method was called, no need to have an impl then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in terms of the enable, there is no check to see if the service is active, like there are in things like register components. But there should be, since the case involving a reload for a inactive plugin will attempt to register some things and likely fail miserably. Will add & add tests, and just mock them so i dont have to impl them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
private class TestNotificationService extends NotificationService<Account> { | ||
|
||
boolean calledCreateAccount = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about isAccountCreated
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no longer needed with the mock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops forgot to remove it!
These comments have been addressed, pls have another review @spinscale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some more cosmetic changes, almost there
if (enabled == false || transportClient) { | ||
return; | ||
} | ||
for (NotificationService service : reloadableServices) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reloadableServices.forEach(NotificationService::reload)
?
@@ -221,6 +224,12 @@ | |||
protected final boolean transportClient; | |||
protected final boolean enabled; | |||
protected final Environment env; | |||
private SetOnce<EmailService> emailService = new SetOnce<>(); | |||
private SetOnce<HipChatService> hipChatService = new SetOnce<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can get rid of all the SetOnce
instance definitions here again with the List<>
, or?
|
||
verify(mockService, times(0)).reload(settings); | ||
watcher.reload(settings); | ||
verify(mockService, times(0)).reload(settings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a verifyNoInteractions()
method, that makes this test a bit easier to read
.build(); | ||
NotificationService mockService = mock(NotificationService.class); | ||
Watcher watcher = new Watcher(settings); | ||
watcher.reloadableServices.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of exposing the reloadableServices
via package private visibility, how about making it protected
and do this (otherwise we have another different visibility in the watcher class)
Watcher watcher = new Watcher(settings) {
@Override
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
ResourceWatcherService resourceWatcherService, ScriptService scriptService,
NamedXContentRegistry xContentRegistry, Environment environment,
NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) {
reloadableServices.add(mockService);
return Collections.emptyList();
}
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since createComponents is not called, i just created a class that extends Watcher and set this in its constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left two minor cleanup comments. LGTM once CI passes
@@ -300,7 +309,8 @@ public Watcher(final Settings settings) { | |||
|
|||
// actions | |||
final Map<String, ActionFactory> actionFactoryMap = new HashMap<>(); | |||
actionFactoryMap.put(EmailAction.TYPE, new EmailActionFactory(settings, emailService, templateEngine, emailAttachmentsParser)); | |||
actionFactoryMap.put(EmailAction.TYPE, new EmailActionFactory(settings, emailService, templateEngine, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unneeded change
@@ -367,7 +377,8 @@ public Watcher(final Settings settings) { | |||
|
|||
return Arrays.asList(registry, inputRegistry, historyStore, triggerService, triggeredWatchParser, | |||
watcherLifeCycleService, executionService, triggerEngineListener, watcherService, watchParser, | |||
configuredTriggerEngine, triggeredWatchStore, watcherSearchTemplateService, slackService, pagerDutyService, hipChatService); | |||
configuredTriggerEngine, triggeredWatchStore, watcherSearchTemplateService, slackService, pagerDutyService, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unneeded change
* retrievable, including the values stored in the node's keystore. | ||
* The setting values are the initial ones, from when the node has be | ||
* started, i.e. they don't follow dynamic updates. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is already documented in ReloadablePlugin
I suppose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea intellij automagically placed it here... i assumed that was a good thing (tm) but ill gladly remove it.
|
||
TestWatcher(Settings settings, NotificationService service) { | ||
super(settings); | ||
reloadableServices.add(service); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
FUTURE ME, change the PR title to |
This commit allows for rebuilding watcher secure secrets via the reload_secure_settings API call. The commit also renames a method in the Notification Service to make it a bit more readable.
* 6.x: Watcher: Make settings reloadable (#31746) [Rollup] Histo group config should support scaled_floats (#32048) lazy snapshot repository initialization (#31606) Add secure setting for watcher email password (#31620) Watcher: cleanup ensureWatchExists use (#31926) Add second level of field collapsing (#31808) Added lenient flag for synonym token filter (#31484) (#31970) Test: Fix a second case of bad watch creation [Rollup] Use composite's missing_bucket (#31402) Docs: Restyled cloud link in getting started Docs: Change formatting of Cloud options Re-instate link in StringFunctionUtils javadocs Correct spelling of AnalysisPlugin#requriesAnalysisSettings (#32025) Fix problematic chars in javadoc [ML] Move open job failure explanation out of root cause (#31925) [ML] Switch ML native QA tests to use a 3 node cluster (#32011)
This commit allows for rebuilding watcher secure secrets via the
reload_secure_settings API call. The commit also renames a method in the
Notification Service to make it a bit more readable.