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

Fix stackdriver client returning 0 for metric types of double #3788

Merged

Conversation

octothorped
Copy link
Contributor

@octothorped octothorped commented Oct 31, 2022

Updated the Stackdriver client to detect if a metric value type of double or int64 has been retrieved. Then it properly casts the value to the float64 to be used downstream by the scalars.
This fixes a bug in which the Stackdriver metric is always returning a value of 0 for a metric value type of double. This is because the monitoring client is asserting the value type and if false will return 0.

Checklist

Fixes #3777

@octothorped octothorped requested a review from a team as a code owner October 31, 2022 16:50
@octothorped octothorped changed the title Fix stackdriver client double metric Fix stackdriver client returning 0 for metric types of double Oct 31, 2022
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.

Looking good
Thanks a lot for the fix, I left some comments inline and IDK if adding test to avoid regressions here is possible, but I'd be nice

pkg/scalers/gcp_pubsub_scaler.go Outdated Show resolved Hide resolved
pkg/scalers/gcp_pubsub_scaler.go Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
pkg/scalers/gcp_stackdriver_scaler.go Outdated Show resolved Hide resolved
@JorTurFer
Copy link
Member

JorTurFer commented Oct 31, 2022

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

@octothorped
Copy link
Contributor Author

IDK if adding test to avoid regressions here is possible, but I'd be nice

Appreciate the feedback. It would be nice to have a test. I tried looking into but we are using the Google API so it makes it a little tougher. We could abstract the retrieval of the metrics call into an interface and use that throughout though. Then mock it in the tests. It might be okay assuming the client footprint is small.

I'll update the PR based on your comments first and then see if I can get a test going.

@JorTurFer
Copy link
Member

JorTurFer commented Oct 31, 2022

Appreciate the feedback. It would be nice to have a test. I tried looking into but we are using the Google API so it makes it a little tougher. We could abstract the retrieval of the metrics call into an interface and use that throughout though. Then mock it in the tests. It might be okay assuming the client footprint is small.

Could we test this using e2e tests? I mean, we have e2e test using gcp services, so if we can force this behaviour there (IDK how), we can check it, we don't need to mock anything. I asked because maybe unit test would cover this, but if we need e2e tests, we can do it. Maybe we could just update current e2e tests to enforce the usage of float64

@zroubalik
Copy link
Member

@octothorped any update on this please? we plan to do a release in ~2 weeks.

@octothorped
Copy link
Contributor Author

@octothorped any update on this please? we plan to do a release in ~2 weeks.

Sorry about the long delay. I will try to get an update in the next few days. I have been swapped with other work and this suddenly took a backseat. I will see about getting this finished.

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>
Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>
Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>
@octothorped octothorped force-pushed the fix-stackdriver-client-double-metric branch from cb780e5 to 24dafb1 Compare November 30, 2022 07:54
@tomkerkhove
Copy link
Member

@JorTurFer @zroubalik Can you re-review this PR please to see if we need to change things before our release on Thrusday?

@octothorped Can you fix the open merge conflicts please?

@octothorped octothorped requested a review from JorTurFer December 2, 2022 16:52
@JorTurFer
Copy link
Member

JorTurFer commented Dec 2, 2022

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

@JorTurFer
Copy link
Member

One thing, if activationValue is float64, value should be too. Could you update it?
This change also requires a documentation update to reflect that it's float.
Basically, you need to update these pages:

You can check how them should be comparing the with threshold and activationThresold from prometheus scaler

@octothorped
Copy link
Contributor Author

Updated the target value parameters to be float64 as well.

Put out a PR that updates the documentation for the float changes.

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>
@octothorped octothorped force-pushed the fix-stackdriver-client-double-metric branch from 2cd39eb to 6809f98 Compare December 3, 2022 00:25
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!
Thanks for the improvement! Let me trigger e2e test and once they pass, the PR is ready :)

@JorTurFer
Copy link
Member

JorTurFer commented Dec 3, 2022

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

@JorTurFer JorTurFer merged commit d5f3349 into kedacore:main Dec 5, 2022
josephangbc pushed a commit to josephangbc/keda that referenced this pull request Dec 6, 2022
…re#3788)

* Update stackdriver client to handle metrics of value type double

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* move change log note to below general

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* parse activation value as float64

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* change target value to float64 for GCP pub/sub and stackdriver

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>
@JorTurFer JorTurFer mentioned this pull request Jan 17, 2023
1 task
pedro-stanaka pushed a commit to pedro-stanaka/keda that referenced this pull request Jan 18, 2023
…re#3788)

* Update stackdriver client to handle metrics of value type double

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* move change log note to below general

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* parse activation value as float64

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* change target value to float64 for GCP pub/sub and stackdriver

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>
@pedro-stanaka pedro-stanaka mentioned this pull request Jan 18, 2023
7 tasks
pedro-stanaka pushed a commit to pedro-stanaka/keda that referenced this pull request Jan 18, 2023
…re#3788)

* Update stackdriver client to handle metrics of value type double

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* move change log note to below general

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* parse activation value as float64

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* change target value to float64 for GCP pub/sub and stackdriver

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>
Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>
pedro-stanaka pushed a commit to pedro-stanaka/keda that referenced this pull request Jan 19, 2023
…re#3788)

* Update stackdriver client to handle metrics of value type double

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* move change log note to below general

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* parse activation value as float64

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* change target value to float64 for GCP pub/sub and stackdriver

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>
Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>
pedro-stanaka pushed a commit to pedro-stanaka/keda that referenced this pull request Jan 19, 2023
…re#3788)

* Update stackdriver client to handle metrics of value type double

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* move change log note to below general

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* parse activation value as float64

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* change target value to float64 for GCP pub/sub and stackdriver

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
JorTurFer added a commit that referenced this pull request Jan 19, 2023
* fix: CVE-2022-3172 (#3693)

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>

* fix: Respect optional parameter inside envs for ScaledJobs (#3694)

Signed-off-by: Jorge Turrado <jorge_turrado@hotmail.es>
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>

* fix(prometheus scaler): Detect Inf before casting float to int (#3762)

* fix(prometheus scaler): Detect Inf before casting float to int

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

* Improve the log message

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

Signed-off-by: Jorge Turrado <jorge_turrado@hotmail.es>
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>

* fix(nats-jetstream): correctly count messages that should be redelivered (waiting for ack) towards keda value (#3809)

* fix: keda now include the messages that should be retried in the count of pending messages used for scaling

Signed-off-by: Antoine Laffargue <antoine.laffargue@gmail.com>

* chore: update changelog

Signed-off-by: Antoine Laffargue <antoine.laffargue@gmail.com>

Signed-off-by: Antoine Laffargue <antoine.laffargue@gmail.com>
Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>

* NewRelic scaler crashes on logging (#3946)

Signed-off-by: Laszlo Kishalmi <laszlo.kishalmi@partech.com>

Signed-off-by: Laszlo Kishalmi <laszlo.kishalmi@partech.com>
Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>

* Fix stackdriver client returning 0 for metric types of double (#3788)

* Update stackdriver client to handle metrics of value type double

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* move change log note to below general

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* parse activation value as float64

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

* change target value to float64 for GCP pub/sub and stackdriver

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>

Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>

* Fixing conflicts after cherry-pick

Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>

* fix: Close is called twice on PushScaler's deletion (#3599)

Signed-off-by: ytz <1020560484@qq.com>
Signed-off-by: taenyang <1020560484@qq.com>
Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>

* fix/datadog-scaler-null-last-point (#3954)

Signed-off-by: Tony Lee <dogzzdogzz@gmail.com>
Signed-off-by: Tony Lee <tony.lee@shopback.com>
Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
Co-authored-by: Tony Lee <tony.lee@shopback.com>
Co-authored-by: Zbynek Roubalik <zroubalik@gmail.com>
Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>

* fix(mongodb): escape username and password (#3989)

Fixes #3992

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>

* Hacking generated files to version CI expects

Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>

* Updating aws-sdk and golang packages to fix CVEs

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>

* Updating golang/text package to fix CVE

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>

* Using same version of aws sdk as in main

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
Signed-off-by: Jorge Turrado <jorge_turrado@hotmail.es>
Signed-off-by: Antoine Laffargue <antoine.laffargue@gmail.com>
Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com>
Signed-off-by: Laszlo Kishalmi <laszlo.kishalmi@partech.com>
Signed-off-by: Eric Takemoto <24865872+octothorped@users.noreply.github.com>
Signed-off-by: ytz <1020560484@qq.com>
Signed-off-by: taenyang <1020560484@qq.com>
Signed-off-by: Tony Lee <dogzzdogzz@gmail.com>
Signed-off-by: Tony Lee <tony.lee@shopback.com>
Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
Co-authored-by: Jorge Turrado Ferrero <Jorge_turrado@hotmail.es>
Co-authored-by: Antoine LAFFARGUE <antoine.laffargue@gmail.com>
Co-authored-by: Laszlo Kishalmi <laszlo.kishalmi@gmail.com>
Co-authored-by: Eric Takemoto <eric.takemoto@gocrisp.com>
Co-authored-by: taenyang <1020560484@qq.com>
Co-authored-by: Tony Lee <dogzzdogzz@gmail.com>
Co-authored-by: Tony Lee <tony.lee@shopback.com>
Co-authored-by: Zbynek Roubalik <zroubalik@gmail.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.

Stackdriver scalar returns 0 for gauge values of type double
4 participants