-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
AWS Cloudwatch Scaler metrics pulling logic is not optimized #2242
Comments
cc @zroubalik |
#2187 should fix this problem, am I right @fivesheep? |
@zroubalik Not exactly, they serve different purpose. what I mean is we can move the following code from
and let I did not make a change for this in PR #2243, since I saw in some other places such as the AWS SQS shall also use the same pattern, and it will also need to be improved the same way. |
Yeah now I see what you meant, you are right. Do you think that you can add this change in a separate PR once #2243 is merged? It would be nice improvement. |
The AWS related stuff hasn't been updated for a while, so it definitely deserves some improvements. Unfortunately there hasn't been anybody with enough experience so far. |
@zroubalik sure, I will send a separate PR after that |
@fivesheep I guess we can close this one, right? Or is there anything else to be done? |
@zroubalik Yup, I think we can close this one now. thx! |
Report
The metrics pulling logic is not optimized for cloudwatch scaler, and it has a chance to not getting any data point back from aws due to cloudwatch's eventually consistent model, some of the well know tricks for exporting cloudwatch data with the GetMetricData API needs to be applied:
11:06
if we try to get the latest datapoint (which will be recored for 11:05), we set starttime to11:00
and endtime to11:05
, very likely cloudwatch will return no datapoint to the api call, and also very likely for the next cycle with 11:05 to 11:10, it won't return any data either if the endtime is too close to the current time. One way to avoid this is to extend the time range with additional cycles, for example, always add two to three cycles to the time range for getting data. to get the data point from 11:05, set the starttime to 10:55 or even 11:50 (it won't increase the cost), also setScanBy
the request param toTimestampDescending
, and always take the first data point return from the output. In the current scaler code, there's a parammetricCollectionTime
can be used for that, however,ScanBy
is not set, which the dehavoir of datapoint returning order is undefined(not documented). It would make sense to always set this param when sending the requestIf you omit Unit in your request, all data that was collected with any unit is returned, along with the corresponding units that were specified when the data was reported to CloudWatch. If you specify a unit, the operation returns only data that was collected with that unit specified. If you specify a unit that does not match the data collected, the results of the operation are null. CloudWatch does not perform unit conversions.
Expected Behavior
Cloudwatch scaler shall always be able to get a stable value back from aws
Actual Behavior
Due to the eventually consistent model of cloudwatch api, the scaler might not be able to get a value
Steps to Reproduce the Problem
kubectl get --raw /apis/external.metrics.k8s.io/v1beta1 | jq
It returns 0 some times
Logs from KEDA operator
KEDA Version
2.4.0
Kubernetes Version
No response
Platform
Amazon Web Services
Scaler Details
Cloudwatch
Anything else?
The cloudwatch client can also be cached, it has the same lifecycle as the scaler, and it can renew token by itself, we don't need to make 2 calls to create this client every time when pulling a metrics data. it will improve the performance and cost
The text was updated successfully, but these errors were encountered: