6
6
package org.opensearch.alerting
7
7
8
8
import org.opensearch.action.ActionRequest
9
- import org.opensearch.alerting.action.DocLevelMonitorFanOutAction
10
9
import org.opensearch.alerting.action.ExecuteMonitorAction
11
10
import org.opensearch.alerting.action.ExecuteWorkflowAction
12
11
import org.opensearch.alerting.action.GetDestinationsAction
@@ -25,6 +24,7 @@ import org.opensearch.alerting.core.resthandler.RestScheduledJobStatsHandler
25
24
import org.opensearch.alerting.core.schedule.JobScheduler
26
25
import org.opensearch.alerting.core.settings.LegacyOpenDistroScheduledJobSettings
27
26
import org.opensearch.alerting.core.settings.ScheduledJobSettings
27
+ import org.opensearch.alerting.remote.monitors.RemoteMonitorRegistry
28
28
import org.opensearch.alerting.resthandler.RestAcknowledgeAlertAction
29
29
import org.opensearch.alerting.resthandler.RestAcknowledgeChainedAlertAction
30
30
import org.opensearch.alerting.resthandler.RestDeleteMonitorAction
@@ -52,6 +52,7 @@ import org.opensearch.alerting.settings.AlertingSettings.Companion.DOC_LEVEL_MON
52
52
import org.opensearch.alerting.settings.DestinationSettings
53
53
import org.opensearch.alerting.settings.LegacyOpenDistroAlertingSettings
54
54
import org.opensearch.alerting.settings.LegacyOpenDistroDestinationSettings
55
+ import org.opensearch.alerting.spi.RemoteMonitorRunnerExtension
55
56
import org.opensearch.alerting.transport.TransportAcknowledgeAlertAction
56
57
import org.opensearch.alerting.transport.TransportAcknowledgeChainedAlertAction
57
58
import org.opensearch.alerting.transport.TransportDeleteMonitorAction
@@ -85,6 +86,7 @@ import org.opensearch.common.settings.Setting
85
86
import org.opensearch.common.settings.Settings
86
87
import org.opensearch.common.settings.SettingsFilter
87
88
import org.opensearch.commons.alerting.action.AlertingActions
89
+ import org.opensearch.commons.alerting.action.DocLevelMonitorFanOutAction
88
90
import org.opensearch.commons.alerting.aggregation.bucketselectorext.BucketSelectorExtAggregationBuilder
89
91
import org.opensearch.commons.alerting.model.BucketLevelTrigger
90
92
import org.opensearch.commons.alerting.model.ChainedAlertTrigger
@@ -96,6 +98,7 @@ import org.opensearch.commons.alerting.model.QueryLevelTrigger
96
98
import org.opensearch.commons.alerting.model.ScheduledJob
97
99
import org.opensearch.commons.alerting.model.SearchInput
98
100
import org.opensearch.commons.alerting.model.Workflow
101
+ import org.opensearch.commons.alerting.model.remote.monitors.RemoteMonitorTrigger
99
102
import org.opensearch.core.action.ActionResponse
100
103
import org.opensearch.core.common.io.stream.NamedWriteableRegistry
101
104
import org.opensearch.core.common.io.stream.StreamInput
@@ -110,6 +113,7 @@ import org.opensearch.painless.spi.AllowlistLoader
110
113
import org.opensearch.painless.spi.PainlessExtension
111
114
import org.opensearch.percolator.PercolatorPluginExt
112
115
import org.opensearch.plugins.ActionPlugin
116
+ import org.opensearch.plugins.ExtensiblePlugin
113
117
import org.opensearch.plugins.ReloadablePlugin
114
118
import org.opensearch.plugins.ScriptPlugin
115
119
import org.opensearch.plugins.SearchPlugin
@@ -162,6 +166,7 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R
162
166
lateinit var alertIndices: AlertIndices
163
167
lateinit var clusterService: ClusterService
164
168
lateinit var destinationMigrationCoordinator: DestinationMigrationCoordinator
169
+ var monitorTypeToMonitorRunners: MutableMap <String , RemoteMonitorRegistry > = mutableMapOf ()
165
170
166
171
override fun getRestHandlers (
167
172
settings : Settings ,
@@ -236,6 +241,7 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R
236
241
ClusterMetricsInput .XCONTENT_REGISTRY ,
237
242
DocumentLevelTrigger .XCONTENT_REGISTRY ,
238
243
ChainedAlertTrigger .XCONTENT_REGISTRY ,
244
+ RemoteMonitorTrigger .XCONTENT_REGISTRY ,
239
245
Workflow .XCONTENT_REGISTRY
240
246
)
241
247
}
@@ -277,6 +283,7 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R
277
283
.registerLockService(lockService)
278
284
.registerConsumers()
279
285
.registerDestinationSettings()
286
+ .registerRemoteMonitors(monitorTypeToMonitorRunners)
280
287
scheduledJobIndices = ScheduledJobIndices (client.admin(), clusterService)
281
288
docLevelMonitorQueries = DocLevelMonitorQueries (client, clusterService)
282
289
scheduler = JobScheduler (threadPool, runner)
@@ -409,4 +416,20 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R
409
416
)
410
417
)
411
418
}
419
+
420
+ override fun loadExtensions (loader : ExtensiblePlugin .ExtensionLoader ) {
421
+ for (monitorExtension in loader.loadExtensions(RemoteMonitorRunnerExtension ::class .java)) {
422
+ val monitorTypesToMonitorRunners = monitorExtension.getMonitorTypesToMonitorRunners()
423
+
424
+ for (monitorTypeToMonitorRunner in monitorTypesToMonitorRunners) {
425
+ val monitorType = monitorTypeToMonitorRunner.key
426
+ val monitorRunner = monitorTypeToMonitorRunner.value
427
+
428
+ if (! this .monitorTypeToMonitorRunners.containsKey(monitorType)) {
429
+ val monitorRegistry = RemoteMonitorRegistry (monitorType, monitorRunner)
430
+ this .monitorTypeToMonitorRunners[monitorType] = monitorRegistry
431
+ }
432
+ }
433
+ }
434
+ }
412
435
}
0 commit comments