From 737f0528ea1869eaf98945f76b4c30dc203b42a3 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Fri, 21 Jun 2024 15:12:34 -0400 Subject: [PATCH 1/6] Register system index descriptors through SystemIndexPlugin.getSystemIndexDescriptors Signed-off-by: Craig Perkins --- .../org/opensearch/alerting/AlertingPlugin.kt | 18 ++++++++++++------ .../opensearch/alerting/alerts/AlertIndices.kt | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt index 4ca201f60..1f64d4305 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt @@ -15,6 +15,8 @@ import org.opensearch.alerting.action.GetRemoteIndexesAction import org.opensearch.alerting.action.SearchEmailAccountAction import org.opensearch.alerting.action.SearchEmailGroupAction import org.opensearch.alerting.alerts.AlertIndices +import org.opensearch.alerting.alerts.AlertIndices.Companion.ALERT_CONFIG_INDEX +import org.opensearch.alerting.alerts.AlertIndices.Companion.ALL_ALERT_INDEX_PATTERN import org.opensearch.alerting.comments.CommentsIndices import org.opensearch.alerting.core.JobSweeper import org.opensearch.alerting.core.ScheduledJobIndices @@ -114,16 +116,13 @@ import org.opensearch.core.xcontent.XContentParser import org.opensearch.env.Environment import org.opensearch.env.NodeEnvironment import org.opensearch.index.IndexModule +import org.opensearch.indices.SystemIndexDescriptor import org.opensearch.monitor.jvm.JvmStats import org.opensearch.painless.spi.Allowlist import org.opensearch.painless.spi.AllowlistLoader import org.opensearch.painless.spi.PainlessExtension import org.opensearch.percolator.PercolatorPluginExt -import org.opensearch.plugins.ActionPlugin -import org.opensearch.plugins.ExtensiblePlugin -import org.opensearch.plugins.ReloadablePlugin -import org.opensearch.plugins.ScriptPlugin -import org.opensearch.plugins.SearchPlugin +import org.opensearch.plugins.* import org.opensearch.repositories.RepositoriesService import org.opensearch.rest.RestController import org.opensearch.rest.RestHandler @@ -139,7 +138,7 @@ import java.util.function.Supplier * It also adds [Monitor.XCONTENT_REGISTRY], [SearchInput.XCONTENT_REGISTRY], [QueryLevelTrigger.XCONTENT_REGISTRY], * [BucketLevelTrigger.XCONTENT_REGISTRY], [ClusterMetricsInput.XCONTENT_REGISTRY] to the [NamedXContentRegistry] so that we are able to deserialize the custom named objects. */ -internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, ReloadablePlugin, SearchPlugin, PercolatorPluginExt() { +internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, ReloadablePlugin, SearchPlugin, SystemIndexPlugin, PercolatorPluginExt() { override fun getContextAllowlists(): Map, List> { val whitelist = AllowlistLoader.loadFromResourceFiles(javaClass, "org.opensearch.alerting.txt") @@ -426,6 +425,13 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R return listOf(TriggerScript.CONTEXT) } + override fun getSystemIndexDescriptors(settings : Settings): Collection { + return listOf( + SystemIndexDescriptor(ALL_ALERT_INDEX_PATTERN, "Alerting Plugin system index pattern"), + SystemIndexDescriptor(ALERT_CONFIG_INDEX, "Alerting Plugin Configuration index") + ) + } + override fun reload(settings: Settings) { runner.reloadDestinationSettings(settings) } diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt b/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt index 64c62f926..12d57c439 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt @@ -117,6 +117,8 @@ class AlertIndices( /** The in progress alert history index. */ const val ALERT_INDEX = ".opendistro-alerting-alerts" + const val ALERT_CONFIG_INDEX = ".opendistro-alerting-config" + /** The alias of the index in which to write alert history */ const val ALERT_HISTORY_WRITE_INDEX = ".opendistro-alerting-alert-history-write" From 8aaea5066c74b762d68f7c0f78b60454fd3acc61 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Fri, 21 Jun 2024 15:24:50 -0400 Subject: [PATCH 2/6] Remove wildcard import Signed-off-by: Craig Perkins --- .../main/kotlin/org/opensearch/alerting/AlertingPlugin.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt index 1f64d4305..faf9f71bd 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt @@ -122,7 +122,12 @@ import org.opensearch.painless.spi.Allowlist import org.opensearch.painless.spi.AllowlistLoader import org.opensearch.painless.spi.PainlessExtension import org.opensearch.percolator.PercolatorPluginExt -import org.opensearch.plugins.* +import org.opensearch.plugins.ActionPlugin +import org.opensearch.plugins.ExtensiblePlugin +import org.opensearch.plugins.ReloadablePlugin +import org.opensearch.plugins.ScriptPlugin +import org.opensearch.plugins.SearchPlugin +import org.opensearch.plugins.SystemIndexPlugin import org.opensearch.repositories.RepositoriesService import org.opensearch.rest.RestController import org.opensearch.rest.RestHandler From 68006a28843c9c306e0e6e9269e06957dd5f6eb7 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Fri, 21 Jun 2024 15:32:06 -0400 Subject: [PATCH 3/6] Fix lint issue Signed-off-by: Craig Perkins --- .../src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt index faf9f71bd..b1b8d58c0 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt @@ -430,7 +430,7 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R return listOf(TriggerScript.CONTEXT) } - override fun getSystemIndexDescriptors(settings : Settings): Collection { + override fun getSystemIndexDescriptors(settings: Settings): Collection { return listOf( SystemIndexDescriptor(ALL_ALERT_INDEX_PATTERN, "Alerting Plugin system index pattern"), SystemIndexDescriptor(ALERT_CONFIG_INDEX, "Alerting Plugin Configuration index") From b095f39c0e31db4184757ec34dc821e7ebc54388 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Fri, 21 Jun 2024 16:01:55 -0400 Subject: [PATCH 4/6] Fix ktlint on JDK11 Signed-off-by: Craig Perkins --- .../src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt index b1b8d58c0..fb0918e3c 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt @@ -143,7 +143,8 @@ import java.util.function.Supplier * It also adds [Monitor.XCONTENT_REGISTRY], [SearchInput.XCONTENT_REGISTRY], [QueryLevelTrigger.XCONTENT_REGISTRY], * [BucketLevelTrigger.XCONTENT_REGISTRY], [ClusterMetricsInput.XCONTENT_REGISTRY] to the [NamedXContentRegistry] so that we are able to deserialize the custom named objects. */ -internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, ReloadablePlugin, SearchPlugin, SystemIndexPlugin, PercolatorPluginExt() { +internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, ReloadablePlugin, + SearchPlugin, SystemIndexPlugin, PercolatorPluginExt() { override fun getContextAllowlists(): Map, List> { val whitelist = AllowlistLoader.loadFromResourceFiles(javaClass, "org.opensearch.alerting.txt") From 1784eff712a3ef92d41840a64b1bee97bce45886 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Mon, 24 Jun 2024 11:20:20 -0400 Subject: [PATCH 5/6] Use constants from common-utils Signed-off-by: Craig Perkins --- .../src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt | 3 ++- .../main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt index fb0918e3c..7987c80f0 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt @@ -105,6 +105,7 @@ import org.opensearch.commons.alerting.model.DocumentLevelTrigger import org.opensearch.commons.alerting.model.Monitor import org.opensearch.commons.alerting.model.QueryLevelTrigger import org.opensearch.commons.alerting.model.ScheduledJob +import org.opensearch.commons.alerting.model.ScheduledJob.Companion.SCHEDULED_JOBS_INDEX import org.opensearch.commons.alerting.model.SearchInput import org.opensearch.commons.alerting.model.Workflow import org.opensearch.commons.alerting.model.remote.monitors.RemoteMonitorTrigger @@ -434,7 +435,7 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R override fun getSystemIndexDescriptors(settings: Settings): Collection { return listOf( SystemIndexDescriptor(ALL_ALERT_INDEX_PATTERN, "Alerting Plugin system index pattern"), - SystemIndexDescriptor(ALERT_CONFIG_INDEX, "Alerting Plugin Configuration index") + SystemIndexDescriptor(SCHEDULED_JOBS_INDEX, "Alerting Plugin Configuration index") ) } diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt b/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt index 12d57c439..64c62f926 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt @@ -117,8 +117,6 @@ class AlertIndices( /** The in progress alert history index. */ const val ALERT_INDEX = ".opendistro-alerting-alerts" - const val ALERT_CONFIG_INDEX = ".opendistro-alerting-config" - /** The alias of the index in which to write alert history */ const val ALERT_HISTORY_WRITE_INDEX = ".opendistro-alerting-alert-history-write" From 5a65033a29e88cb3a0f82e1147d571deb5860c3a Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Mon, 24 Jun 2024 11:27:03 -0400 Subject: [PATCH 6/6] Remove unused import Signed-off-by: Craig Perkins --- .../src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt index 7987c80f0..f7383aaab 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt @@ -15,7 +15,6 @@ import org.opensearch.alerting.action.GetRemoteIndexesAction import org.opensearch.alerting.action.SearchEmailAccountAction import org.opensearch.alerting.action.SearchEmailGroupAction import org.opensearch.alerting.alerts.AlertIndices -import org.opensearch.alerting.alerts.AlertIndices.Companion.ALERT_CONFIG_INDEX import org.opensearch.alerting.alerts.AlertIndices.Companion.ALL_ALERT_INDEX_PATTERN import org.opensearch.alerting.comments.CommentsIndices import org.opensearch.alerting.core.JobSweeper