Skip to content

Use SdkClient for persistence in MonitorMetadataService - #2083

Merged
engechas merged 1 commit into
opensearch-project:remote-metadata-supportfrom
manaswini1920:feature/sdk-background-services
Apr 6, 2026
Merged

Use SdkClient for persistence in MonitorMetadataService#2083
engechas merged 1 commit into
opensearch-project:remote-metadata-supportfrom
manaswini1920:feature/sdk-background-services

Conversation

@manaswini1920

@manaswini1920 manaswini1920 commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator

Description

Migrates MonitorMetadataService.upsertMetadata() and getMetadata() to use SdkClient instead of direct OpenSearch client calls, as part of the remote metadata SDK migration for background services.

Changes:

  • MonitorMetadataService.upsertMetadata(): Replaced IndexRequest with PutDataObjectRequest via sdkClient.putDataObjectAsync()
  • MonitorMetadataService.getMetadata(): Replaced GetRequest with GetDataObjectRequest via sdkClient.getDataObjectAsync()
  • AlertingPlugin.kt: Set sdkClient on MonitorMetadataService after SDK client creation
  • SdkUtils.kt: Added suspend fun CompletionStage.await() helper for coroutine-safe SDK calls (same as Use SdkClient for persistence in IndexAlertingComment, IndexMonitor #2081)

Notes:

Related Issues

Part of #2094

Part of #2094

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check [here](https://github.com/opensearch-project/alerting/blob/main/CONTRIBUTING.md#developer-certificate
-of-origin).

Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com>
@manaswini1920
manaswini1920 force-pushed the feature/sdk-background-services branch from 592e473 to 4e7543f Compare April 6, 2026 19:28
xContentRegistry,
settings
)
MonitorMetadataService.sdkClient = sdkClient

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 aren't we adding it in the constructor?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Because MonitorMetadataService is a Kotlin object (singleton), not a class — it doesn't have a constructor. It's initialized via MonitorMetadataService.initialize(client, clusterService, xContentRegistry, settings) which sets fields individually. The
sdkClient follows the same pattern.

You could add it as a parameter to initialize() instead of setting it separately. That would be cleaner:

kotlin

fun initialize(
    client: Client,
    clusterService: ClusterService,
    xContentRegistry: NamedXContentRegistry,
    settings: Settings,
    sdkClient: SdkClient
) {
    ...
    this.sdkClient = sdkClient
}


i can take it as follow up on the next PR

}
}

private fun isIndexNotFoundException(e: Throwable): Boolean {

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.

isthis a common method used every where. can we move it to commons and add an extra log line

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ack

@engechas
engechas merged commit 4bff5b3 into opensearch-project:remote-metadata-support Apr 6, 2026
18 checks passed
manaswini1920 pushed a commit to manaswini1920/alerting that referenced this pull request Apr 7, 2026
…back

Migrate AlertService to use SdkClient for all alert persistence:
- searchAlerts: SearchDataObjectRequest with routing
- upsertMonitorErrorAlert: search + put via SdkClient
- clearMonitorErrorAlert: search + bulk put via SdkClient
- moveClearedErrorAlertsToHistory: search + bulk put via SdkClient
- saveAlerts: bulk put/delete via SdkClient
- saveNewAlerts: bulk put via SdkClient
- deleteByQuery stays on direct client (no SDK equivalent)

Address PR opensearch-project#2083 review feedback:
- Move sdkClient into MonitorMetadataService.initialize() parameter
- Use AlertingException.isIndexNotFoundException() from common-utils
- Move sdkClient creation before AlertService in AlertingPlugin

Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com>
riysaxen-amzn pushed a commit that referenced this pull request Apr 9, 2026
…ations ( (#2088)

* Use SdkClient for persistence in AlertService and address review feedback

Migrate AlertService to use SdkClient for all alert persistence:
- searchAlerts: SearchDataObjectRequest with routing
- upsertMonitorErrorAlert: search + put via SdkClient
- clearMonitorErrorAlert: search + bulk put via SdkClient
- moveClearedErrorAlertsToHistory: search + bulk put via SdkClient
- saveAlerts: bulk put/delete via SdkClient
- saveNewAlerts: bulk put via SdkClient
- deleteByQuery stays on direct client (no SDK equivalent)

Address PR #2083 review feedback:
- Move sdkClient into MonitorMetadataService.initialize() parameter
- Use AlertingException.isIndexNotFoundException() from common-utils
- Move sdkClient creation before AlertService in AlertingPlugin

Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com>

* chore: Retrigger CI after common-utils merge

Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com>

* chore: Retrigger CI after SDK 3.6 backport merge

Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com>

* chore: Retrigger CI

Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com>

---------

Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com>
Co-authored-by: Manaswini Ragamouni <ragamanu@amazon.com>
manaswini1920 pushed a commit to manaswini1920/alerting that referenced this pull request Apr 10, 2026
…etadata support

- Migrate TransportGetMonitorAction to use SdkClient (opensearch-project#2053)
- Migrate GetAlerts, DeleteComment, GetWorkflowAlerts, ExecuteMonitor to SdkClient (opensearch-project#2061)
- Fix listener leak in TransportExecuteMonitorAction for empty source (opensearch-project#2080)
- Migrate DeleteMonitor, GetDestinations, SearchAlertingComment, SearchMonitor to SdkClient (opensearch-project#2060)
- Migrate IndexAlertingComment, IndexMonitor to SdkClient (opensearch-project#2081)
- Migrate MonitorMetadataService to SdkClient (opensearch-project#2083)
- Add new query level trigger evaluation independent of ScriptingService (opensearch-project#2079, opensearch-project#2090)
- Migrate AlertService to SdkClient (opensearch-project#2088)
- Migrate TransportAcknowledgeAlertAction to SdkClient (opensearch-project#2089)

Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com>
AWSHurneyt pushed a commit that referenced this pull request Apr 10, 2026
…etadata support (#2093)

- Migrate TransportGetMonitorAction to use SdkClient (#2053)
- Migrate GetAlerts, DeleteComment, GetWorkflowAlerts, ExecuteMonitor to SdkClient (#2061)
- Fix listener leak in TransportExecuteMonitorAction for empty source (#2080)
- Migrate DeleteMonitor, GetDestinations, SearchAlertingComment, SearchMonitor to SdkClient (#2060)
- Migrate IndexAlertingComment, IndexMonitor to SdkClient (#2081)
- Migrate MonitorMetadataService to SdkClient (#2083)
- Add new query level trigger evaluation independent of ScriptingService (#2079, #2090)
- Migrate AlertService to SdkClient (#2088)
- Migrate TransportAcknowledgeAlertAction to SdkClient (#2089)

Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com>
Co-authored-by: Manaswini Ragamouni <ragamanu@amazon.com>
eirsep pushed a commit to eirsep/alerting that referenced this pull request Apr 20, 2026
…roject#2083)

Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com>
Co-authored-by: Manaswini Ragamouni <ragamanu@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants