Skip to content

feature: add custom HTTP client timeout to Metrics API scaler#7551

Merged
rickbrouwer merged 8 commits intokedacore:mainfrom
RokeshVS:feature/metrics-api-scaler-timeout
May 7, 2026
Merged

feature: add custom HTTP client timeout to Metrics API scaler#7551
rickbrouwer merged 8 commits intokedacore:mainfrom
RokeshVS:feature/metrics-api-scaler-timeout

Conversation

@RokeshVS
Copy link
Copy Markdown
Contributor

@RokeshVS RokeshVS commented Mar 16, 2026

Adds support for a custom HTTP client timeout to the Metrics API scaler, consistent with the same feature recently added to the Prometheus and Azure Log Analytics scalers in #6607.

Previously, the Metrics API scaler always used the global HTTP timeout configured for KEDA. This change allows users to override that per-trigger via a timeout triggerMetadata field (value in milliseconds).

Changes

  • Added timeout field (time.Duration) to metricsAPIScalerMetadata
  • Pass meta.timeout to kedautil.CreateHTTPClient in NewMetricsAPIScaler
  • Added 3 test cases to testMetricsAPIMetadata covering valid, negative, and non-numeric timeout values
  • Updated CHANGELOG.md

Checklist

  • I have verified that my change is according to the deprecations & breaking changes policy
  • Tests have been added
  • Changelog has been updated and is aligned with our changelog requirements
  • A PR is opened to update the documentation on (repo)
  • Commits are signed with Developer Certificate of Origin (DCO)

Fixes #7549
Docs: kedacore/keda-docs#1720

Signed-off-by: RokeshVS <rokesh550@gmail.com>
@RokeshVS RokeshVS requested a review from a team as a code owner March 16, 2026 19:12
@keda-automation keda-automation requested a review from a team March 16, 2026 19:12
@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.

@snyk-io
Copy link
Copy Markdown

snyk-io Bot commented Mar 16, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

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

Signed-off-by: RokeshVS <rokesh550@gmail.com>
@rickbrouwer
Copy link
Copy Markdown
Member

please run go fmt . on your files for the static check errors.

Signed-off-by: RokeshVS <rokesh550@gmail.com>
@RokeshVS
Copy link
Copy Markdown
Contributor Author

go fmt .

Done @rickbrouwer

@rickbrouwer
Copy link
Copy Markdown
Member

The scalers were later refactored to comply with the new metadata parsing; see the main branch.

Some adjustments are still needed to comply with that as well, see for example:
https://github.com/kedacore/keda/blob/main/pkg/scalers/azure_log_analytics_scaler.go

Comment thread CHANGELOG.md Outdated
Signed-off-by: RokeshVS <rokesh550@gmail.com>
@keda-automation keda-automation requested a review from a team March 16, 2026 19:53
Copy link
Copy Markdown
Contributor

@dttung2905 dttung2905 left a comment

Choose a reason for hiding this comment

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

Hi @RokeshVS ,
thanks for making this PR. Could you help fixing this to make the CI passed

golangci/golangci-lint info checking GitHub for tag 'v2.8.0'
golangci/golangci-lint info found version: 2.8.0 for v2.8.0/linux/amd64
golangci/golangci-lint info installed /home/runner/go/bin/golangci-lint
golangci-lint run
pkg/scalers/metrics_api_scaler.go:101:36: unnecessary conversion (unconvert)
		httpClientTimeout = time.Duration(meta.Timeout) * time.Millisecond
		                                 ^
1 issues:
* unconvert: 1
make: *** [Makefile:163: golangci] Error 1

Signed-off-by: RokeshVS <rokesh550@gmail.com>
@keda-automation keda-automation requested a review from a team March 17, 2026 01:38
@RokeshVS
Copy link
Copy Markdown
Contributor Author

Hi @RokeshVS , thanks for making this PR. Could you help fixing this to make the CI passed

golangci/golangci-lint info checking GitHub for tag 'v2.8.0'
golangci/golangci-lint info found version: 2.8.0 for v2.8.0/linux/amd64
golangci/golangci-lint info installed /home/runner/go/bin/golangci-lint
golangci-lint run
pkg/scalers/metrics_api_scaler.go:101:36: unnecessary conversion (unconvert)
		httpClientTimeout = time.Duration(meta.Timeout) * time.Millisecond
		                                 ^
1 issues:
* unconvert: 1
make: *** [Makefile:163: golangci] Error 1

Hi @dttung2905 , Thanks for mentioning , Removed unnecessary conversion .

Signed-off-by: RokeshVS <rokesh550@gmail.com>
@rickbrouwer
Copy link
Copy Markdown
Member

rickbrouwer commented Mar 17, 2026

/run-e2e metric
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.

Thanks for this contribution @RokeshVS !

@rickbrouwer rickbrouwer added the Awaiting/2nd-approval This PR needs one more approval review label Mar 17, 2026
@JorTurFer
Copy link
Copy Markdown
Member

I know that this is totally consistent with the current scalers, but I'm afraid about supporting the same parameters multiple times. @kedacore/keda-core-contributors @kedacore/keda-core-maintainers, should we support these kind of HTTP options at trigger level and not inside each scaler?

@RokeshVS RokeshVS requested a review from dttung2905 March 20, 2026 03:49
@rickbrouwer
Copy link
Copy Markdown
Member

rickbrouwer commented Mar 20, 2026

I know that this is totally consistent with the current scalers, but I'm afraid about supporting the same parameters multiple times. @kedacore/keda-core-contributors @kedacore/keda-core-maintainers, should we support these kind of HTTP options at trigger level and not inside each scaler?

I would like this to discuss on KubeCon and/or the next Community Call.
My brief opinion on this right away: because it is consistent, I would like to let it proceed for now. And after that, a plan to bring it into trigger level for all scalers.

@zroubalik
Copy link
Copy Markdown
Member

I know that this is totally consistent with the current scalers, but I'm afraid about supporting the same parameters multiple times. @kedacore/keda-core-contributors @kedacore/keda-core-maintainers, should we support these kind of HTTP options at trigger level and not inside each scaler?

I would like this to discuss on KubeCon and/or the next Community Call. My brief opinion on this right away: because it is consistent, I would like to let it proceed for now. And after that, a plan to bring it into trigger level for all scalers.

💯

Signed-off-by: Rick Brouwer <rickbrouwer@gmail.com>
@keda-automation keda-automation requested a review from a team April 9, 2026 13:58
@rickbrouwer
Copy link
Copy Markdown
Member

rickbrouwer commented Apr 10, 2026

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

@rickbrouwer
Copy link
Copy Markdown
Member

Let's move on to this PR. Supporting this setting at the trigger level seems like a good candidate for V3 to me, as briefly discussed at KubeCon. Agree @kedacore/keda-core-maintainers ?

@rickbrouwer rickbrouwer mentioned this pull request Apr 26, 2026
22 tasks
Signed-off-by: Rick Brouwer <rickbrouwer@gmail.com>
@rickbrouwer
Copy link
Copy Markdown
Member

rickbrouwer commented May 3, 2026

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

@rickbrouwer rickbrouwer removed the Awaiting/2nd-approval This PR needs one more approval review label May 7, 2026
@rickbrouwer rickbrouwer merged commit 4a465f5 into kedacore:main May 7, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metrics API trigger to support timeout which will override the KEDA_HTTP_DEFAULT_TIMEOUT

5 participants