-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Changes from 13 commits
f89207c
153a97b
7be7b49
b97f21b
ee19d3a
98d41ee
b49a645
cc09f7b
0a1d9af
38df695
ad5d8a1
68ef919
79f0b7e
e956505
a326338
0b90cc8
9218784
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
import org.elasticsearch.node.Node; | ||
import org.elasticsearch.plugins.ActionPlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.plugins.ReloadablePlugin; | ||
import org.elasticsearch.plugins.ScriptPlugin; | ||
import org.elasticsearch.rest.RestController; | ||
import org.elasticsearch.rest.RestHandler; | ||
|
@@ -123,6 +124,7 @@ | |
import org.elasticsearch.xpack.watcher.input.simple.SimpleInputFactory; | ||
import org.elasticsearch.xpack.watcher.input.transform.TransformInput; | ||
import org.elasticsearch.xpack.watcher.input.transform.TransformInputFactory; | ||
import org.elasticsearch.xpack.watcher.notification.NotificationService; | ||
import org.elasticsearch.xpack.watcher.notification.email.Account; | ||
import org.elasticsearch.xpack.watcher.notification.email.EmailService; | ||
import org.elasticsearch.xpack.watcher.notification.email.HtmlSanitizer; | ||
|
@@ -194,7 +196,7 @@ | |
|
||
import static java.util.Collections.emptyList; | ||
|
||
public class Watcher extends Plugin implements ActionPlugin, ScriptPlugin { | ||
public class Watcher extends Plugin implements ActionPlugin, ScriptPlugin, ReloadablePlugin { | ||
|
||
// This setting is only here for backward compatibility reasons as 6.x indices made use of it. It can be removed in 8.x. | ||
@Deprecated | ||
|
@@ -221,6 +223,7 @@ public class Watcher extends Plugin implements ActionPlugin, ScriptPlugin { | |
protected final boolean transportClient; | ||
protected final boolean enabled; | ||
protected final Environment env; | ||
protected List<NotificationService> reloadableServices = new ArrayList<>(); | ||
|
||
public Watcher(final Settings settings) { | ||
this.settings = settings; | ||
|
@@ -275,6 +278,12 @@ public Collection<Object> createComponents(Client client, ClusterService cluster | |
SlackService slackService = new SlackService(settings, httpClient, clusterService.getClusterSettings()); | ||
PagerDutyService pagerDutyService = new PagerDutyService(settings, httpClient, clusterService.getClusterSettings()); | ||
|
||
reloadableServices.add(emailService); | ||
reloadableServices.add(hipChatService); | ||
reloadableServices.add(jiraService); | ||
reloadableServices.add(slackService); | ||
reloadableServices.add(pagerDutyService); | ||
|
||
TextTemplateEngine templateEngine = new TextTemplateEngine(settings, scriptService); | ||
Map<String, EmailAttachmentParser> emailAttachmentParsers = new HashMap<>(); | ||
emailAttachmentParsers.put(HttpEmailAttachementParser.TYPE, new HttpEmailAttachementParser(httpClient, httpTemplateParser, | ||
|
@@ -300,7 +309,8 @@ public Collection<Object> createComponents(Client client, ClusterService cluster | |
|
||
// 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, | ||
emailAttachmentsParser)); | ||
actionFactoryMap.put(WebhookAction.TYPE, new WebhookActionFactory(settings, httpClient, httpTemplateParser, templateEngine)); | ||
actionFactoryMap.put(IndexAction.TYPE, new IndexActionFactory(settings, client)); | ||
actionFactoryMap.put(LoggingAction.TYPE, new LoggingActionFactory(settings, templateEngine)); | ||
|
@@ -367,7 +377,8 @@ public Collection<Object> createComponents(Client client, ClusterService cluster | |
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. unneeded change |
||
hipChatService); | ||
} | ||
|
||
protected TriggerEngine getTriggerEngine(Clock clock, ScheduleRegistry scheduleRegistry) { | ||
|
@@ -613,4 +624,21 @@ public List<ScriptContext> getContexts() { | |
public void close() throws IOException { | ||
IOUtils.closeWhileHandlingException(httpClient); | ||
} | ||
|
||
|
||
/** | ||
* Reloads all reloadable services' settings. | ||
* @param settings | ||
* Settings used while reloading the plugin. All values are | ||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more. this is already documented in There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
@Override | ||
public void reload(Settings settings) { | ||
if (enabled == false || transportClient) { | ||
return; | ||
} | ||
reloadableServices.forEach(s -> s.reload(settings)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,18 @@ | |
import org.elasticsearch.test.IndexSettingsModule; | ||
import org.elasticsearch.threadpool.ExecutorBuilder; | ||
import org.elasticsearch.xpack.core.watcher.watch.Watch; | ||
import org.elasticsearch.xpack.watcher.notification.NotificationService; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Collections.emptyMap; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
|
||
public class WatcherPluginTests extends ESTestCase { | ||
|
||
|
@@ -97,4 +102,36 @@ public void testThreadPoolSize() { | |
.build(); | ||
assertThat(Watcher.getWatcherThreadPoolSize(noDataNodeSettings), is(1)); | ||
} | ||
|
||
public void testReload() { | ||
Settings settings = Settings.builder() | ||
.put("xpack.watcher.enabled", true) | ||
.put("path.home", createTempDir()) | ||
.build(); | ||
NotificationService mockService = mock(NotificationService.class); | ||
Watcher watcher = new TestWatcher(settings, mockService); | ||
|
||
watcher.reload(settings); | ||
verify(mockService, times(1)).reload(settings); | ||
} | ||
|
||
public void testReloadDisabled() { | ||
Settings settings = Settings.builder() | ||
.put("xpack.watcher.enabled", false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. alternatively you could mock a NotificationService and check with There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.put("path.home", createTempDir()) | ||
.build(); | ||
NotificationService mockService = mock(NotificationService.class); | ||
Watcher watcher = new TestWatcher(settings, mockService); | ||
|
||
watcher.reload(settings); | ||
verifyNoMoreInteractions(mockService); | ||
} | ||
|
||
private class TestWatcher extends Watcher { | ||
|
||
TestWatcher(Settings settings, NotificationService service) { | ||
super(settings); | ||
reloadableServices.add(service); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
unneeded change