Skip to content

Commit acb53cd

Browse files
committed
Provide an extension of the HttpClientRequest API that exposes the request metric.
Motivation: Sometimes it is necessary to let framework access to underlying metric of an HTTP request in order to reliably and efficiently share state with the metrics implementation. This is useful for frameworks that build on top of HTTP client and wants to extend metrics reporting beyond Vert.x capabitilies.
1 parent 5402370 commit acb53cd

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/main/java/io/vertx/core/http/impl/HttpClientRequestBase.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/**
2929
* @author <a href="mailto:[email protected]">Julien Viet</a>
3030
*/
31-
public abstract class HttpClientRequestBase implements HttpClientRequest {
31+
public abstract class HttpClientRequestBase implements HttpClientRequestInternal {
3232

3333
protected final ContextInternal context;
3434
protected final HttpClientStream stream;
@@ -76,6 +76,10 @@ protected String authority() {
7676
}
7777
}
7878

79+
public Object metric() {
80+
return stream.metric();
81+
}
82+
7983
@Override
8084
public int streamId() {
8185
return stream.id();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2011-2025 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
11+
package io.vertx.core.http.impl;
12+
13+
import io.vertx.core.http.HttpClientRequest;
14+
import io.vertx.core.spi.metrics.ClientMetrics;
15+
16+
/**
17+
* Extends to expose internal methods that are necessary for integration.
18+
*
19+
* @author <a href="mailto:[email protected]">Julien Viet</a>
20+
*/
21+
public interface HttpClientRequestInternal extends HttpClientRequest {
22+
23+
/**
24+
* @return the request metric obtained from {@link ClientMetrics} for this request
25+
*/
26+
Object metric();
27+
28+
}

src/test/java/io/vertx/core/http/HttpMetricsTestBase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.vertx.core.VertxOptions;
1818
import io.vertx.core.buffer.Buffer;
1919
import io.vertx.core.http.impl.HttpClientImpl;
20+
import io.vertx.core.http.impl.HttpClientRequestInternal;
2021
import io.vertx.core.http.impl.HttpServerRequestInternal;
2122
import io.vertx.core.impl.VertxInternal;
2223
import io.vertx.core.metrics.MetricsOptions;
@@ -245,6 +246,9 @@ public void testHttpClientLifecycle(boolean implementInit) throws Exception {
245246
.setPort(HttpTestBase.DEFAULT_HTTP_PORT)
246247
.setHost("localhost")
247248
.setURI("/somepath")).onComplete(onSuccess(req -> {
249+
if (implementInit) {
250+
assertNotNull(((HttpClientRequestInternal)req).metric());
251+
}
248252
req
249253
.response(onSuccess(resp -> {
250254
responseBeginLatch.countDown();

0 commit comments

Comments
 (0)