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

add a method in HttpClientReuqest to get the request metric #4023

Open
liubao68 opened this issue Jul 20, 2021 · 5 comments
Open

add a method in HttpClientReuqest to get the request metric #4023

liubao68 opened this issue Jul 20, 2021 · 5 comments

Comments

@liubao68
Copy link

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.

@liubao68
Copy link
Author

liubao68 commented Jul 20, 2021

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.

@tsegismont
Copy link
Contributor

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();
  }

@vietj
Copy link
Member

vietj commented Jul 22, 2021

what is the actual use case that is intended ?

@liubao68
Copy link
Author

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.

@liubao68
Copy link
Author

liubao68 commented Jul 23, 2021

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
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants