Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: option to query metrics only on polling interval #3940

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

zroubalik
Copy link
Member

@zroubalik zroubalik commented Nov 30, 2022

Signed-off-by: Zbynek Roubalik [email protected]

Adding an option in the trigger spec, that enables caching metric values during polling interval. Then each request coming to KEDA Metrics Server from k8s server (HPA controller), reads the value from this cache and not querying the external service directly. This reduces load on the external services and user have the ability to select this option for an individual trigger in ScaledObject.

  • this feature is EXPERIMENTAL and I'd like to gather feedback, before making it a stable one
  • this feature is available only for ScaledObjects
  • I named this property queryMetricsOnPollingInterval, though I am not happy with the name and I am eager to hear suggestions -> useCachedMetrics

See example:

  - type: kafka
    useCachedMetrics: true     # <-- NEW OPTION, default value: false
    metadata:
      bootstrapServers: kafka.svc:9092
      consumerGroup: my-group
      topic: test-topic
      lagThreshold: '5'

Code changes:

  • I merged scaler.IsActive() and scaler.GetMetrics() calls to single method scaler.GetMetricsAndActivity() -> this way we don't ask for the same information twice. I was able to reduce this calls for majority of scalers, there are some leftovers to be refactored, as the logic was more complex (so in scaler.GetMetricsAndActivity() we call scaler.IsActive() and scaler.GetMetrics() methods instead of single call) - TODO tracking issue for leftovers
  • refactored scalehandler and scalerscache a little bit

Outstanding issues:

  • How to name this property?
  • e2e test
  • more unit tests
  • print warning message if this message is being used in ScaledJobs - it doesn't work there
  • pring error if this is used by scaler where it doesn't make sense - cpu, memory, cron Where else?

Checklist

Fixes #3921

Relates to #2282

@zroubalik
Copy link
Member Author

zroubalik commented Nov 30, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 1, 2022

/run-e2e

Update: You can check the progress here

@zroubalik
Copy link
Member Author

zroubalik commented Dec 1, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 2, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 2, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 2, 2022

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

@zroubalik zroubalik marked this pull request as ready for review December 2, 2022 13:39
@zroubalik zroubalik requested a review from a team as a code owner December 2, 2022 13:39
@zroubalik zroubalik changed the title [WIP] cache requests feat: option to query metrics only on polling interval Dec 2, 2022
@zroubalik zroubalik marked this pull request as draft December 2, 2022 16:08
@zroubalik
Copy link
Member Author

zroubalik commented Dec 2, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 2, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 3, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 3, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 3, 2022

/run-e2e internals/cache_metrics*
Update: You can check the progress here

@zroubalik
Copy link
Member Author

zroubalik commented Dec 6, 2022

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

Copy link
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.

Awesome work! I have left some comments inline

CREATE-NEW-SCALER.md Show resolved Hide resolved
Makefile Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
controllers/keda/scaledobject_controller.go Show resolved Hide resolved
pkg/scalers/azure_eventhub_scaler.go Show resolved Hide resolved
pkg/scalers/external_scaler.go Show resolved Hide resolved
pkg/scalers/predictkube_scaler.go Outdated Show resolved Hide resolved
pkg/scaling/scale_handler.go Show resolved Hide resolved
tests/internals/cache_metrics/cache_metrics_test.go Outdated Show resolved Hide resolved
tests/internals/cache_metrics/cache_metrics_test.go Outdated Show resolved Hide resolved
@zroubalik
Copy link
Member Author

zroubalik commented Dec 6, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 6, 2022

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

@v-shenoy
Copy link
Contributor

v-shenoy commented Dec 6, 2022

@zroubalik I took a look at the PR, but it's kind of hard for me to understand the changes with 92 files changed (although I guess most of those are just merging the IsActive & GetMetrics methods for the scalers).

I am also a little bit confused by the PR title. Doesn't KEDA already query metrics on polling interval?

Copy link
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.

LGTM! 2 suggestions inline, but not blockers

@tomkerkhove
Copy link
Member

tomkerkhove commented Dec 7, 2022

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

@champly
Copy link
Contributor

champly commented Dec 7, 2022

@champly could you please help me understand why is this test failing?

• Failure [5.076 seconds]
ScaledObjectController
/__w/keda/keda/controllers/keda/scaledobject_controller_test.go:54
  scaleobject ready condition 'False/Unknow' to 'True' will requeue [It]
  /__w/keda/keda/controllers/keda/scaledobject_controller_test.go:721

  Timed out after 5.000s.
  Expected
      <v1.ConditionStatus>: True
  To satisfy at least one of these matchers: [%!s(*matchers.EqualMatcher=&{False}) %!s(*matchers.EqualMatcher=&{Unknown})]

you wrote the test and I am not sure, what could break the behavior, thanks!

On my local test it looks like it should work will.

@zroubalik
Copy link
Member Author

@champly could you please help me understand why is this test failing?

• Failure [5.076 seconds]
ScaledObjectController
/__w/keda/keda/controllers/keda/scaledobject_controller_test.go:54
  scaleobject ready condition 'False/Unknow' to 'True' will requeue [It]
  /__w/keda/keda/controllers/keda/scaledobject_controller_test.go:721

  Timed out after 5.000s.
  Expected
      <v1.ConditionStatus>: True
  To satisfy at least one of these matchers: [%!s(*matchers.EqualMatcher=&{False}) %!s(*matchers.EqualMatcher=&{Unknown})]

you wrote the test and I am not sure, what could break the behavior, thanks!

On my local test it looks like it should work will.

@champly thanks a lot for the response, I have already solved this :)

@zroubalik
Copy link
Member Author

zroubalik commented Dec 7, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 7, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 7, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 7, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 8, 2022

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

@tomkerkhove
Copy link
Member

tomkerkhove commented Dec 8, 2022

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

@tomkerkhove
Copy link
Member

Last run and I'll merge it @zroubalik

@zroubalik
Copy link
Member Author

Last run and I'll merge it @zroubalik

please let the merge on me, there might be some PRs merged before this one, so rebase might be needed.

@zroubalik
Copy link
Member Author

zroubalik commented Dec 8, 2022

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

@zroubalik
Copy link
Member Author

zroubalik commented Dec 8, 2022

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

@tomkerkhove
Copy link
Member

tomkerkhove commented Dec 8, 2022

/run-e2e

Update: You can check the progress here

@zroubalik zroubalik merged commit c93a7d4 into kedacore:main Dec 9, 2022
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.

Implement metrics values caching
5 participants