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

Make watcher settings reloadable #31746

Merged
merged 17 commits into from
Jul 13, 2018
Merged

Conversation

hub-cap
Copy link
Contributor

@hub-cap hub-cap commented Jul 2, 2018

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.

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.
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@hub-cap hub-cap changed the title Make watcher plugin reloadable Make watcher settings reloadable Jul 2, 2018
Copy link
Contributor

@spinscale spinscale left a 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<>();
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor

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()

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@hub-cap hub-cap Jul 3, 2018

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

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

how about isAccountCreated?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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!

@hub-cap
Copy link
Contributor Author

hub-cap commented Jul 10, 2018

These comments have been addressed, pls have another review @spinscale

Copy link
Contributor

@spinscale spinscale left a 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) {
Copy link
Contributor

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<>();
Copy link
Contributor

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);
Copy link
Contributor

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();
Copy link
Contributor

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();
            }
        };

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@spinscale spinscale left a 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,
Copy link
Contributor

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,
Copy link
Contributor

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.
*/
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@hub-cap
Copy link
Contributor Author

hub-cap commented Jul 13, 2018

FUTURE ME, change the PR title to watcher:....

@hub-cap hub-cap merged commit 1f72afa into elastic:master Jul 13, 2018
hub-cap added a commit that referenced this pull request Jul 13, 2018
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.
dnhatn added a commit that referenced this pull request Jul 13, 2018
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants