Skip to content

Add OpenSearch scaler#7540

Open
musztardem wants to merge 14 commits intokedacore:mainfrom
musztardem:feature/opensearch-scaler
Open

Add OpenSearch scaler#7540
musztardem wants to merge 14 commits intokedacore:mainfrom
musztardem:feature/opensearch-scaler

Conversation

@musztardem
Copy link
Copy Markdown

@musztardem musztardem commented Mar 12, 2026

  • Introduced the OpenSearch scaler
  • Heavily inspired by the elasticsearch scaler

Checklist

  • When introducing a new scaler, I agree with the scaling governance policy
  • I have verified that my change is according to the deprecations & breaking changes policy
  • Tests have been added (if applicable)
  • Ensure make generate-scalers-schema has been run to update any outdated generated files
  • Changelog has been updated and is aligned with our changelog requirements, only when the change impacts end users
  • A PR is opened to update our Helm chart (repo) (if applicable, ie. when deployment manifests are modified)
  • A PR is opened to update the documentation on (repo) (if applicable)
  • Commits are signed with Developer Certificate of Origin (DCO - learn more)

Fixes #7456

keda-docs: kedacore/keda-docs#1718

@musztardem musztardem requested a review from a team as a code owner March 12, 2026 13:22
@github-actions
Copy link
Copy Markdown

Thank you for your contribution! 🙏

Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected.

While you are waiting, make sure to:

  • Add an entry in our changelog in alphabetical order and link related issue
  • Update the documentation, if needed
  • Add unit & e2e tests for your changes
  • GitHub checks are passing
  • Is the DCO check failing? Here is how you can fix DCO issues

Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient.

Learn more about our contribution guide.

@keda-automation keda-automation requested a review from a team March 12, 2026 13:23
@musztardem musztardem force-pushed the feature/opensearch-scaler branch from 0dcc47b to 3f3076f Compare March 12, 2026 13:24
Comment thread tests/scalers/opensearch/opensearch_test.go Outdated
@musztardem musztardem force-pushed the feature/opensearch-scaler branch from a8d069a to c49e502 Compare March 12, 2026 14:02
@snyk-io
Copy link
Copy Markdown

snyk-io Bot commented Mar 12, 2026

⚠️ Snyk checks are incomplete.

Status Scan Engine Critical High Medium Low Total (0)
⚠️ Open Source Security 0 0 0 0 See details

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@musztardem musztardem force-pushed the feature/opensearch-scaler branch 2 times, most recently from 9d64997 to bbaf9d2 Compare March 12, 2026 14:24
@rickbrouwer
Copy link
Copy Markdown
Member

rickbrouwer commented Mar 13, 2026

Running the e2e is purely for early feedback; I have not yet conducted a review.

@rickbrouwer
Copy link
Copy Markdown
Member

rickbrouwer commented Mar 13, 2026

/run-e2e opensearch
Update: You can check the progress here

@rickbrouwer
Copy link
Copy Markdown
Member

rickbrouwer commented Mar 16, 2026

/run-e2e opensearch
Update: You can check the progress here

@rickbrouwer
Copy link
Copy Markdown
Member

A quick tip: it is not necessary to merge every change in the main branch into this pull request.

We will review this pull request at a later date. Because KubeCon is coming up, we are a bit busier. The review will probably take place after that. If necessary, we will merge the main branch.

@musztardem
Copy link
Copy Markdown
Author

Hi @rickbrouwer

I wanted to follow up on the current pull request. I just wanted to check in — do you have a rough idea of when you might have time to take a look? Thanks!

@wozniakjan wozniakjan requested a review from Copilot April 21, 2026 14:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new OpenSearch scaler (inspired by the existing Elasticsearch scaler) and wires it into the scaler builder, along with unit + e2e coverage and a changelog entry.

Changes:

  • Introduce opensearch scaler implementation and register it in the scaler builder
  • Add unit tests for metadata parsing/validation and client creation
  • Add e2e tests and update dependencies + changelog

Reviewed changes

Copilot reviewed 6 out of 349 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
pkg/scaling/scalers_builder.go Registers the new opensearch trigger type with the scaler factory.
pkg/scalers/opensearch_scaler.go Implements OpenSearch scaler: metadata parsing/validation, client setup, query execution, metric extraction.
pkg/scalers/opensearch_scaler_test.go Adds unit tests for metadata validation/parsing and HTTP/TLS client behavior.
tests/scalers/opensearch/opensearch_test.go Adds e2e coverage for query and search-template modes against an in-cluster OpenSearch.
go.mod Adds OpenSearch Go client dependency.
CHANGELOG.md Adds a “New” changelog entry for the OpenSearch scaler.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/scalers/opensearch_scaler.go
Comment thread pkg/scalers/opensearch_scaler.go
Comment thread pkg/scalers/opensearch_scaler.go Outdated
Comment thread pkg/scalers/opensearch_scaler.go Outdated
Comment thread pkg/scalers/opensearch_scaler.go Outdated
Comment thread pkg/scalers/opensearch_scaler_test.go Outdated
Comment thread tests/scalers/opensearch/opensearch_test.go Outdated
@musztardem musztardem force-pushed the feature/opensearch-scaler branch from 5d803b9 to 18d9de2 Compare April 24, 2026 15:16
@rickbrouwer
Copy link
Copy Markdown
Member

Please run 'make generate-scalers-schema'

musztardem and others added 11 commits April 27, 2026 10:28
Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
Co-authored-by: semgrep-code-kedacore[bot] <258932899+semgrep-code-kedacore[bot]@users.noreply.github.com>
Signed-off-by: Antoni <antek.pstras@gmail.com>
Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
@musztardem musztardem force-pushed the feature/opensearch-scaler branch from 18d9de2 to 7ea643d Compare April 27, 2026 08:29
@rickbrouwer
Copy link
Copy Markdown
Member

rickbrouwer commented Apr 28, 2026

/run-e2e opensearch
Update: You can check the progress here

@rickbrouwer
Copy link
Copy Markdown
Member

I think I have a few final questions/comments. I did some comparisons with the ElasticSearch scaler, because I think it should be reasonably similar to this one.

Is there a specific reason to use google.golang.org/grpc/status and codes for errors instead of fmt.Errorf like the other one? The codes get wrapped by fmt.Errorf("error inspecting opensearch: %w", err) further up the call chain anyway, so they're effectively lost i think.

Further, is TriggerIndex intentionally left unset in parseOpensearchMetadata? The Elasticsearch scaler has meta.TriggerIndex = config.TriggerIndex right after TypedConfig, but it's missing here. The field is always 0 now and isn't read anywhere.

Is making metricName unexported a deliberate choice? In Elasticsearch it's MetricName (exported). It doesn't matter functionally to be honest, but should we align them for consistency between the two scalers?

Last thing, TypedConfig trims metadata values via configParamValue (and treats whitespace-only as absent), so s.metadata.Query and s.metadata.SearchTemplateName are already trimmed by the time they reach getQueryResult()/search(). Combined with Validate() already guaranteeing at least one of them is non-empty, the strings.TrimSpace(...) != "" checks in getQueryResult() and the if query == "" check in search() look redundant. So i think this can be removed(?)

Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
@musztardem
Copy link
Copy Markdown
Author

thanks for the comment and for spotting these issues

  • grpc statuses with error codes are not needed - changed to fmt.Errorf
  • TriggerIndex indeed should be set
  • the unexported metricName was a deliberate choice as we do not allow user to override this value and yet we have it exported. It makes sense however to keep it consistent with the Elasticsearch scaler in case someone needs to migrate from one scaler to another for whatever reason
  • I've missed the fact that TypedConfig trims metadata - I removed redundant trims and checks.
  • One additional update - I've noticed that I've been immediately returning err after an erroneous s.osAPIClient.Search/s.osAPIClient.SearchTemplate call, which skipped readResponseBody entirely - and with it the checkHTTPStatus call that was inside it. So 401/403 errors were never surfaced with a clear message. I've updated these so the http checker is actually used.


Comment thread pkg/scalers/opensearch_scaler.go
Comment thread pkg/scalers/opensearch_scaler.go
Signed-off-by: Antoni Pstraś <antoni.pstras@sap.com>
@keda-automation keda-automation requested a review from a team May 1, 2026 13:49
@musztardem musztardem requested a review from rickbrouwer May 1, 2026 13:51
@rickbrouwer
Copy link
Copy Markdown
Member

rickbrouwer commented May 1, 2026

/run-e2e opensearch
Update: You can check the progress here

Copy link
Copy Markdown
Member

@rickbrouwer rickbrouwer left a comment

Choose a reason for hiding this comment

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

I think we're all set now. Thanks!

@rickbrouwer rickbrouwer added the Awaiting/2nd-approval This PR needs one more approval review label May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Awaiting/2nd-approval This PR needs one more approval review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants