Fix query response time metric#13661
Conversation
As of PR apache#13179, the query response time metrics started to get extremely high for all tables. The root cause tured out to be a missed initialization in which the query arrival time was set to 0 by default. The refactor broke the contract that the broker request handler always returns the time taken to handle the request. Added code to initialize the arrival time. Since the refactor attempted to include client pre-processing time, added this code under the condition that the value is not already set. Ideally, callers of the method should add on their own pre and post-processing time to the time returned by the handleRequest() method.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #13661 +/- ##
============================================
+ Coverage 61.75% 61.96% +0.21%
+ Complexity 207 198 -9
============================================
Files 2436 2554 +118
Lines 133233 140567 +7334
Branches 20636 21869 +1233
============================================
+ Hits 82274 87109 +4835
- Misses 44911 46827 +1916
- Partials 6048 6631 +583
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Jackie-Jiang
left a comment
There was a problem hiding this comment.
Currently, we always set request arrival time when the RequestContext is just created (since it is a property within it).
Are you running some some custom code which is directly hooked to the BrokerRequestHandler.handleRequest()? Sorry I didn't expect this usage pattern during the refactor. I'd suggest following the same way to set it when the RequestContext is created for consistency.
If you want to make it more robust, we can set it in BaseBrokerRequestHandler.handleRequest() because we might not use delegate all the time
| public BrokerResponse handleRequest(JsonNode request, @Nullable SqlNodeAndOptions sqlNodeAndOptions, | ||
| @Nullable RequesterIdentity requesterIdentity, RequestContext requestContext, @Nullable HttpHeaders httpHeaders) | ||
| throws Exception { | ||
| if (requestContext.getRequestArrivalTimeMillis() == 0) { |
There was a problem hiding this comment.
Might be more robust if we check for <= 0 because the return value is per implementation based
The Secondly, yes, installations may have some code before (and after return from) IIRC used to be that request context was created inside handleRequest and returned. Somehow that interface has now changed to include requestContext as an argument, and I think that has caused the confusion. Why is the "client" code directly calling BrokerRequestHandler? (isnt the client remote)? I can change it to <= 0 if you like, but I also think the contract of this method needs a re-look? |
You are correct. Currently we always create a delegate even without the multi-stage request handler, so it should be good to set it in the delegate.
Basically we want to include the query parsing time during the request handling. In |
I suggest setting it (without any if check) inside the handleRequest() call, like it was before. If this is ok with you, I will remove the Agreed? |
No, I don't agree. We should capture the query parsing time as part of the request handling. You may take a look at |
I see. In that case, are we deprecating handleRequest() (and therefore BrokerRequestHandler)? Should PinotClientRequest be moved to spi? |
We are not deprecating it. |
|
OK, modified as discussed offline and added comments so that we don't miss this in other re-factoring. |
As of PR #13179, the query response time metrics started to get extremely high for all tables. The root cause tured out to be a missed initialization in which the query arrival time was set to 0 by default.
The refactor broke the contract that the broker request handler always returns the time taken to handle the request.
Added code to initialize the arrival time.
Since the refactor attempted to include client pre-processing time, added this code under the condition that the value is not already set.
Ideally, callers of the method should add on their own pre and post-processing time to the time returned by the handleRequest() method.