-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improve context propagation to Scalers #2190
Labels
Comments
@jerbob92 thanks for opening this, well written. |
@ahmelsayed do you think that you can prepare the code in #2187 so we can later resolve the second issue mentioned here. |
@jerbob92 @zroubalik I can take on the first point in the original post. Is that ok? |
@arschles that would be great! |
7 tasks
work started in #2202 |
3 tasks
Now that #2187 is merged, I can take (2). I'll submit a draft PR today to start it. |
2 tasks
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Labels
Proposal
At this point, the scalers only receive a context in the scaler methods
GetMetrics()
andIsActive()
.I think there are 2 issues that we face right now:
http.NewRequestWithContext()
instead ofhttp.NewRequest()
).buildScaler
, while some Scalers would be able to use a context there (the Redis Scaler pings the Redis server in thebuildScaler
logic)The first issue is quite easy to fix, every Scaler should be checked whether it can use a context in
GetMetrics()
orIsActive()
and then implement that. If it already uses it we should check if it uses it properly. (for example, MongoDB scaler does use a context in theCountDocuments()
method, but it extendscontext.Background()
instead of the given context inGetMetrics()
andIsActive()
).The second issue is harder. If you look at the code in
scale_handler.go
, if you go back far enough frombuildScaler
, you eventually find a context instartPushScalers
andstartScaleLoop
. This is the cancelable context fromHandleScalableObject
. The question would be if that is the right context to pass to thebuildScaler
, or whether we have to introduce a new cancelable context.Use-Case
A context is a useful feature of Go to pass arbitrary values around, but it also provides features like canceling and timeouts. A lot of libraries allow you to pass a context to it when doing stuff, for example:
http.NewRequestWithContext()
QueryRowContext
)If we would use context's properly everywhere, Scalers have to spend less time on tasks that would otherwise timeout/cancel.
Anything else?
Anything to add @zroubalik?
The text was updated successfully, but these errors were encountered: