Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions alerting/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ dependencies {
implementation "com.github.seancfoley:ipaddress:5.4.1"
implementation project(path: ":alerting-spi", configuration: 'shadow')

implementation "org.opensearch:opensearch-remote-metadata-sdk:${opensearch_build}"

testImplementation "org.antlr:antlr4-runtime:${versions.antlr4}"
testImplementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}"
testImplementation "org.mockito:mockito-core:${versions.mockito}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ import org.opensearch.alerting.script.TriggerScript
import org.opensearch.alerting.service.DeleteMonitorService
import org.opensearch.alerting.settings.AlertingSettings
import org.opensearch.alerting.settings.AlertingSettings.Companion.DOC_LEVEL_MONITOR_SHARD_FETCH_SIZE
import org.opensearch.alerting.settings.AlertingSettings.Companion.MULTI_TENANCY_ENABLED
import org.opensearch.alerting.settings.AlertingSettings.Companion.REMOTE_METADATA_ENDPOINT
import org.opensearch.alerting.settings.AlertingSettings.Companion.REMOTE_METADATA_REGION
import org.opensearch.alerting.settings.AlertingSettings.Companion.REMOTE_METADATA_SERVICE_NAME
import org.opensearch.alerting.settings.AlertingSettings.Companion.REMOTE_METADATA_STORE_TYPE
import org.opensearch.alerting.settings.DestinationSettings
import org.opensearch.alerting.settings.LegacyOpenDistroAlertingSettings
import org.opensearch.alerting.settings.LegacyOpenDistroDestinationSettings
Expand Down Expand Up @@ -129,6 +134,13 @@ import org.opensearch.plugins.ReloadablePlugin
import org.opensearch.plugins.ScriptPlugin
import org.opensearch.plugins.SearchPlugin
import org.opensearch.plugins.SystemIndexPlugin
import org.opensearch.remote.metadata.client.SdkClient
import org.opensearch.remote.metadata.client.impl.SdkClientFactory
import org.opensearch.remote.metadata.common.CommonValue.REMOTE_METADATA_ENDPOINT_KEY
import org.opensearch.remote.metadata.common.CommonValue.REMOTE_METADATA_REGION_KEY
import org.opensearch.remote.metadata.common.CommonValue.REMOTE_METADATA_SERVICE_NAME_KEY
import org.opensearch.remote.metadata.common.CommonValue.REMOTE_METADATA_TYPE_KEY
import org.opensearch.remote.metadata.common.CommonValue.TENANT_AWARE_KEY
import org.opensearch.repositories.RepositoriesService
import org.opensearch.rest.RestController
import org.opensearch.rest.RestHandler
Expand Down Expand Up @@ -325,6 +337,19 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R
this.threadPool = threadPool
this.clusterService = clusterService

val sdkClient: SdkClient = SdkClientFactory.createSdkClient(
client,
xContentRegistry,
mapOf(
REMOTE_METADATA_TYPE_KEY to REMOTE_METADATA_STORE_TYPE.get(settings),
REMOTE_METADATA_ENDPOINT_KEY to REMOTE_METADATA_ENDPOINT.get(settings),
REMOTE_METADATA_REGION_KEY to REMOTE_METADATA_REGION.get(settings),
REMOTE_METADATA_SERVICE_NAME_KEY to REMOTE_METADATA_SERVICE_NAME.get(settings),
TENANT_AWARE_KEY to MULTI_TENANCY_ENABLED.get(settings).toString()
),
client.threadPool().executor(ThreadPool.Names.GENERIC)
)

MonitorMetadataService.initialize(
client,
clusterService,
Expand All @@ -351,7 +376,8 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R
destinationMigrationCoordinator,
lockService,
alertService,
triggerService
triggerService,
sdkClient
)
}

Expand Down Expand Up @@ -433,7 +459,12 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R
AlertingSettings.COMMENTS_MAX_CONTENT_SIZE,
AlertingSettings.MAX_COMMENTS_PER_ALERT,
AlertingSettings.MAX_COMMENTS_PER_NOTIFICATION,
AlertingSettings.NOTIFICATION_CONTEXT_RESULTS_ALLOWED_ROLES
AlertingSettings.NOTIFICATION_CONTEXT_RESULTS_ALLOWED_ROLES,
AlertingSettings.MULTI_TENANCY_ENABLED,
AlertingSettings.REMOTE_METADATA_STORE_TYPE,
AlertingSettings.REMOTE_METADATA_ENDPOINT,
AlertingSettings.REMOTE_METADATA_REGION,
AlertingSettings.REMOTE_METADATA_SERVICE_NAME
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ package org.opensearch.alerting.settings
import org.opensearch.alerting.AlertingPlugin
import org.opensearch.common.settings.Setting
import org.opensearch.common.unit.TimeValue
import org.opensearch.remote.metadata.common.CommonValue.REMOTE_METADATA_ENDPOINT_KEY
import org.opensearch.remote.metadata.common.CommonValue.REMOTE_METADATA_REGION_KEY
import org.opensearch.remote.metadata.common.CommonValue.REMOTE_METADATA_SERVICE_NAME_KEY
import org.opensearch.remote.metadata.common.CommonValue.REMOTE_METADATA_TYPE_KEY
import java.util.concurrent.TimeUnit
import java.util.function.Function

Expand All @@ -19,6 +23,7 @@ class AlertingSettings {
companion object {
const val DEFAULT_MAX_ACTIONABLE_ALERT_COUNT = 50L
const val DEFAULT_FINDINGS_INDEXING_BATCH_SIZE = 1000
private const val REMOTE_METADATA_KEY_PREFIX = "plugins.alerting"
const val DEFAULT_PERCOLATE_QUERY_NUM_DOCS_IN_MEMORY = 50000
const val DEFAULT_PERCOLATE_QUERY_DOCS_SIZE_MEMORY_PERCENTAGE_LIMIT = 10
const val DEFAULT_DOC_LEVEL_MONITOR_SHARD_FETCH_SIZE = 10000
Expand Down Expand Up @@ -311,5 +316,36 @@ class AlertingSettings {
Setting.Property.NodeScope,
Setting.Property.Dynamic
)

val MULTI_TENANCY_ENABLED: Setting<Boolean> = Setting.boolSetting(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can this be changed via _cluster/settings API?
if yes, that doesn't seem desirable to me..
this should be only changeable via static XML.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, it cannot be changed at runtime. The setting uses Setting.Property.Final which makes it immutable after node startup — it can only be set in opensearch.yml

"$REMOTE_METADATA_KEY_PREFIX.multi_tenancy_enabled",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is multi_tenancy_enabled not common variable coming from remote metadata sdk?

why is the setting itself different on each plugin? shouldn't all plugins have a single settingname?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a common pattern followed in other plugins too. ml-commons, one of the first plugin to adopt the remote metadata sdk used similar pattern : https://github.com/opensearch-project/ml-commons/blob/82da99868a0074374fa7274ceaa8d0ca291e736e/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java#L317-L335.

false,
Setting.Property.NodeScope,
Setting.Property.Final
)

val REMOTE_METADATA_STORE_TYPE: Setting<String?> = Setting.simpleString(
"$REMOTE_METADATA_KEY_PREFIX.$REMOTE_METADATA_TYPE_KEY",
Setting.Property.NodeScope,
Setting.Property.Final
)

val REMOTE_METADATA_ENDPOINT: Setting<String?> = Setting.simpleString(
"$REMOTE_METADATA_KEY_PREFIX.$REMOTE_METADATA_ENDPOINT_KEY",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can this be null for opensearch cluster deployment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Setting.Property.NodeScope,
Setting.Property.Final
)

val REMOTE_METADATA_REGION: Setting<String?> = Setting.simpleString(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can this be null for opensearch cluster deployment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is only needed if we are setting a remote metadata store.

"$REMOTE_METADATA_KEY_PREFIX.$REMOTE_METADATA_REGION_KEY",
Setting.Property.NodeScope,
Setting.Property.Final
)

val REMOTE_METADATA_SERVICE_NAME: Setting<String?> = Setting.simpleString(
"$REMOTE_METADATA_KEY_PREFIX.$REMOTE_METADATA_SERVICE_NAME_KEY",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is there no default value for this for opensearch clusters for all these settings?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These settings defaults to an empty string. When the values are empty, the sdk client falls back to the local OpenSearch cluster client — so the default behavior is unchanged for standard open search clusters. The settings only need explicit values when configuring a remote metadata store.

Setting.Property.NodeScope,
Setting.Property.Final
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ class AlertingSettingsTests : OpenSearchTestCase() {
ScheduledJobSettings.SWEEP_BACKOFF_RETRY_COUNT,
ScheduledJobSettings.SWEEP_BACKOFF_MILLIS,
ScheduledJobSettings.SWEEPER_ENABLED,
ScheduledJobSettings.REQUEST_TIMEOUT
ScheduledJobSettings.REQUEST_TIMEOUT,
AlertingSettings.MULTI_TENANCY_ENABLED,
AlertingSettings.REMOTE_METADATA_STORE_TYPE,
AlertingSettings.REMOTE_METADATA_ENDPOINT,
AlertingSettings.REMOTE_METADATA_REGION,
AlertingSettings.REMOTE_METADATA_SERVICE_NAME
)
)
)
Expand Down Expand Up @@ -186,4 +191,19 @@ class AlertingSettingsTests : OpenSearchTestCase() {
)
)
}

fun `test remote metadata settings defaults`() {
assertEquals(false, AlertingSettings.MULTI_TENANCY_ENABLED.getDefault(Settings.EMPTY))
assertEquals("", AlertingSettings.REMOTE_METADATA_STORE_TYPE.getDefault(Settings.EMPTY))
assertEquals("", AlertingSettings.REMOTE_METADATA_ENDPOINT.getDefault(Settings.EMPTY))
assertEquals("", AlertingSettings.REMOTE_METADATA_REGION.getDefault(Settings.EMPTY))
assertEquals("", AlertingSettings.REMOTE_METADATA_SERVICE_NAME.getDefault(Settings.EMPTY))
}

fun `test multi_tenancy_enabled setting reads from config`() {
val settings = Settings.builder()
.put("plugins.alerting.multi_tenancy_enabled", true)
.build()
assertEquals(true, AlertingSettings.MULTI_TENANCY_ENABLED.get(settings))
}
}
Loading