vert.x
vert.x copied to clipboard
add a method in HttpClientReuqest to get the request metric
Describe the feature
We are reporting metrics using VertxMetrics, and get metric object through
HttpClientRequest.connection().metric() .
This is fine to get TCPMetrics.
Request metric is accessable in HttpClientStream, but it is a protected member of HttpClientRequest, and we can not get the request metrics.
Use cases
Report request metrics like time taken in request begin and end.
Contribution
I am not sure if it is suitable to add a method Object metric() in HttpClientRequest, and I can create a PR if it is fine.
In vert.x 3.x, we get request begin & end by
DefaultHttpSocketMetric httpSocketMetric = (DefaultHttpSocketMetric) ((ConnectionBase) clientRequest.connection())
.metric();
httpSocketMetric.getRequestBeginTime();
httpSocketMetric.getRequestEndTime();
But can not find a way in 4.x.
Our usage is wrong in 3.x. And we find 4.x fixed this but can not get request metric.
Indeed in Vert.x 4 the metric object is held by HttpClientStream.
@vietj what do you think about exposing the metric object in HttpClientRequestBase? Something like:
public Object metric() {
return stream.metric();
}
what is the actual use case that is intended ?
Get request metric can know request begin, request end, resonse begin and response end time, this is usefully for performance issues.
We need reporting time token between request send and response received and need access request metric to do this.
code snippet
clientRequest.response().onComplete(asyncResult -> {
... ... after request succefullly, reporting metrics how long timeout between request end and response received
handleResponse(asyncResult.result());
});
protected void handleResponse(HttpClientResponse httpClientResponse) {
... ...
clientResponse.bodyHandler(this::processResponseBody);
}
protected void processResponseBody(Buffer responseBuf) {
DefaultHttpSocketMetric httpSocketMetric = (DefaultHttpSocketMetric) ((ConnectionBase) clientRequest.connection())
.metric(); // TCPMetrics can be get from connection
// TODO: expect we can get request metric to calculate request end time
}