Skip to content

Fallback to cached value if available#7317

Closed
alt-dima wants to merge 16 commits intokedacore:mainfrom
alt-dima:feature/dimaal/fallback-to-cached
Closed

Fallback to cached value if available#7317
alt-dima wants to merge 16 commits intokedacore:mainfrom
alt-dima:feature/dimaal/fallback-to-cached

Conversation

@alt-dima
Copy link
Copy Markdown

@alt-dima alt-dima commented Dec 13, 2025

Adds new fallback behaviour "cached".
Fallback will return metric value from cache (if available)

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
  • 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
  • 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 #6887

Relates to #

@alt-dima alt-dima requested a review from a team as a code owner December 13, 2025 17:16
@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 December 13, 2025 17:16
@snyk-io
Copy link
Copy Markdown

snyk-io Bot commented Dec 13, 2025

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

Status Scanner 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.

Copy link
Copy Markdown
Member

@JorTurFer JorTurFer left a comment

Choose a reason for hiding this comment

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

I like this idea! just smal nits inline

Comment thread pkg/fallback/fallback.go Outdated
Comment thread pkg/scaling/cache/metricscache/metrics_record_test.go Outdated
@JorTurFer
Copy link
Copy Markdown
Member

Could you open a PR also to docs repo adding the new option there too?

@keda-automation keda-automation requested a review from a team December 14, 2025 08:41
@rickbrouwer rickbrouwer added the docs:pending All issues where docs are pending addition/update label Dec 17, 2025
alt-dima and others added 15 commits January 9, 2026 12:52
Signed-off-by: Dmitriy Altuhov <altuhovd@gmail.com>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
Replace self-hosted ARM64 runners with GitHub's free ubuntu-24.04-arm
runners. Consolidate ARM64 and AMD64 smoke tests into a unified matrix.

Signed-off-by: Vincent Link <vlink@redhat.com>
Co-authored-by: Jorge Turrado Ferrero <Jorge_turrado@hotmail.es>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
* Fix smoke tests

To use `go.mod` version for restoring golang, checkout must happen before golang installation task

Signed-off-by: Jorge Turrado Ferrero <Jorge_turrado@hotmail.es>

* Remove duplicate checkout step in workflow

Signed-off-by: Jorge Turrado Ferrero <Jorge_turrado@hotmail.es>

* Apply suggestions from code review

Signed-off-by: Jorge Turrado Ferrero <Jorge_turrado@hotmail.es>

* Update pr-e2e.yml

Signed-off-by: Jorge Turrado Ferrero <Jorge_turrado@hotmail.es>

---------

Signed-off-by: Jorge Turrado Ferrero <Jorge_turrado@hotmail.es>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
…dacore#7326)

Bumps [github.com/expr-lang/expr](https://github.com/expr-lang/expr) from 1.17.6 to 1.17.7.
- [Release notes](https://github.com/expr-lang/expr/releases)
- [Commits](expr-lang/expr@v1.17.6...v1.17.7)

---
updated-dependencies:
- dependency-name: github.com/expr-lang/expr
  dependency-version: 1.17.7
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
* fix: projected service accounts are validated to prevent arbitrary path reads

Signed-off-by: Jorge Turrado <jorge_turrado@hotmail.es>

* validate signature

Signed-off-by: Jorge Turrado <jorge_turrado@hotmail.es>

---------

Signed-off-by: Jorge Turrado <jorge_turrado@hotmail.es>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
* Update releases

Signed-off-by: Jorge Turrado <jorge.turrado@mail.schwarz>

* Update releases

Signed-off-by: Jorge Turrado <jorge.turrado@mail.schwarz>

* fix linting issues

Signed-off-by: Jorge Turrado <jorge.turrado@mail.schwarz>

---------

Signed-off-by: Jorge Turrado <jorge.turrado@mail.schwarz>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
Signed-off-by: Jorge Turrado <jorge_turrado@hotmail.es>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
Signed-off-by: Rick Brouwer <rickbrouwer@gmail.com>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
Signed-off-by: Shivamrut <incineroaraditya@gmail.com>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
…dacore#7351)

Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 3.7.1 to 3.12.0.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](docker/setup-buildx-action@c47758b...8d2750c)

---
updated-dependencies:
- dependency-name: docker/setup-buildx-action
  dependency-version: 3.12.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
…e#7352)

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 4.31.6 to 4.31.9.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@fe4161a...5d4e8d1)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.31.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
…ore#7353)

Bumps [oNaiPs/secrets-to-env-action](https://github.com/onaips/secrets-to-env-action) from 1.5 to 1.7.
- [Release notes](https://github.com/onaips/secrets-to-env-action/releases)
- [Commits](oNaiPs/secrets-to-env-action@ec46a22...be0f849)

---
updated-dependencies:
- dependency-name: oNaiPs/secrets-to-env-action
  dependency-version: '1.7'
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
the final semaphore acquisition was still missing, which resulted in loop not waiting until all metrics were gathered from each metrics API server

Signed-off-by: julian GUINARD <julian.guinard@ovhcloud.com>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
* Include trigger actvivity in raw metrics

Include information about trigger activity in raw metrics.
This is usefull when a trigger defines `activityThreshold`,
where non-zere value does not necessarily mean that the
trigger is active.

Signed-off-by: Josef Karasek <karasek.jose@gmail.com>

* update changelog

Signed-off-by: Josef Karasek <karasek.jose@gmail.com>

* Fix lint

Signed-off-by: Josef Karasek <karasek.jose@gmail.com>

---------

Signed-off-by: Josef Karasek <karasek.jose@gmail.com>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
Signed-off-by: Dima Altukhov <dimaal@monday.com>
@alt-dima alt-dima force-pushed the feature/dimaal/fallback-to-cached branch from 597d1d6 to 51bd50c Compare January 9, 2026 10:52
@JorTurFer
Copy link
Copy Markdown
Member

@kedacore/keda-core-contributors

@alt-dima
Copy link
Copy Markdown
Author

alt-dima commented Jan 9, 2026

Interesting, I just noticed this information. And a bit confused.
So this PR is irrelevant. But I was sure until this time that HPA stops scaling at all (nor UP nor DOWN)

If multiple metrics are specified in a HorizontalPodAutoscaler, this calculation is done for each metric, and then the largest of the desired replica counts is chosen. If any of these metrics cannot be converted into a desired replica count (e.g. due to an error fetching the metrics from the metrics APIs) and a scale down is suggested by the metrics which can be fetched, scaling is skipped. This means that the HPA is still capable of scaling up if one or more metrics give a desiredReplicas greater than the current value.

https://kubernetes.io/docs/concepts/workloads/autoscaling/horizontal-pod-autoscale/#algorithm-details

@alt-dima
Copy link
Copy Markdown
Author

alt-dima commented Jan 9, 2026

Comment thread pkg/scaling/cache/metricscache/metrics_record.go
Copy link
Copy Markdown
Member

@JorTurFer JorTurFer left a comment

Choose a reason for hiding this comment

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

Looking nice! just a question inlined 😄

Comment on lines +442 to +443
// scaler instances but keep last known good metrics available for fallback behavior.
func (h *scaleHandler) resetScalersCacheKeepMetrics(ctx context.Context, scalableObject interface{}) error {
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.

Does it make sense to rename the current to something like DeleteScalersCache and the new one as ResetScalersCache? I understand that this new one is called during refresh and the previous one during scaledobject update/delete

@kedacore/keda-core-contributors @kedacore/keda-core-maintainers ?

@rickbrouwer rickbrouwer added waiting-author-response All PR's or Issues where we are waiting for a response from the author and removed docs:pending All issues where docs are pending addition/update labels Jan 23, 2026
@github-actions
Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale All issues that are marked as stale due to inactivity label Mar 25, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 1, 2026

This pull request has been automatically closed due to inactivity.

@github-actions github-actions Bot closed this Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale All issues that are marked as stale due to inactivity waiting-author-response All PR's or Issues where we are waiting for a response from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keda blocks scaling when prometheus is down

7 participants