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 |
| 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.
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.
| } | ||
|
|
||
| protected synchronized void setAccountSetting(Settings settings) { | ||
| public synchronized void loadSettings(Settings settings) { |
There was a problem hiding this comment.
how about naming this reload() as well just like in ReloadablePlugin plugin?
There was a problem hiding this comment.
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.
| 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.
is this PagerDutyService missing
clusterSettings.addSettingsUpdateConsumer(this::loadSettings, getSettings());
in its ctor?
There was a problem hiding this comment.
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.
I could also just have NotificationService impl a getSettings that the services overwrite. which is best?
There was a problem hiding this comment.
ahh, nm, its static, it would be more work to change all that.
There was a problem hiding this comment.
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
|
|
||
| public void testReload() throws Exception { | ||
| Settings settings = Settings.builder() | ||
| .put("xpack.watcher.enabled", false) |
There was a problem hiding this comment.
watcher is not enabled, but reloading works? That could be a noop in this case, or?
There was a problem hiding this comment.
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.
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.
|
|
||
| private class TestNotificationService extends NotificationService<Account> { | ||
|
|
||
| boolean calledCreateAccount = false; |
There was a problem hiding this comment.
how about isAccountCreated?
There was a problem hiding this comment.
no longer needed with the mock.
There was a problem hiding this comment.
oops forgot to remove it!
|
These comments have been addressed, pls have another review @spinscale |
spinscale
left a comment
There was a problem hiding this comment.
some more cosmetic changes, almost there
| if (enabled == false || transportClient) { | ||
| return; | ||
| } | ||
| for (NotificationService service : reloadableServices) { |
There was a problem hiding this comment.
reloadableServices.forEach(NotificationService::reload)?
| 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.
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.
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.
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.
Since createComponents is not called, i just created a class that extends Watcher and set this in its constructor.
spinscale
left a comment
There was a problem hiding this comment.
left two minor cleanup comments. LGTM once CI passes
| // 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, |
| return Arrays.asList(registry, inputRegistry, historyStore, triggerService, triggeredWatchParser, | ||
| watcherLifeCycleService, executionService, triggerEngineListener, watcherService, watchParser, | ||
| configuredTriggerEngine, triggeredWatchStore, watcherSearchTemplateService, slackService, pagerDutyService, hipChatService); | ||
| configuredTriggerEngine, triggeredWatchStore, watcherSearchTemplateService, slackService, pagerDutyService, |
| * 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.
this is already documented in ReloadablePlugin I suppose?
There was a problem hiding this comment.
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); |
|
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.