Skip to content

Commit 7d5a726

Browse files
committed
Encapsulate observability properties in an ObservabilityConfig object.
1 parent b8530df commit 7d5a726

9 files changed

Lines changed: 148 additions & 91 deletions

File tree

vertx-core/src/main/java/io/vertx/core/http/HttpClientConfig.java

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ private static QuicClientConfig defaultQuicConfig() {
7575
private int defaultPort;
7676
private int maxRedirects;
7777
private boolean forceSni;
78-
private String metricsName;
79-
private TracingPolicy tracingPolicy;
78+
private ObservabilityConfig observabilityConfig;
8079
private boolean shared;
8180
private String name;
8281
private boolean followAlternativeServices;
@@ -95,8 +94,7 @@ public HttpClientConfig() {
9594
this.defaultPort = HttpClientOptions.DEFAULT_DEFAULT_PORT;
9695
this.maxRedirects = HttpClientOptions.DEFAULT_MAX_REDIRECTS;
9796
this.forceSni = HttpClientOptions.DEFAULT_FORCE_SNI;
98-
this.metricsName = null;
99-
this.tracingPolicy = HttpClientOptions.DEFAULT_TRACING_POLICY;
97+
this.observabilityConfig = null;
10098
this.shared = HttpClientOptions.DEFAULT_SHARED;
10199
this.name = HttpClientOptions.DEFAULT_NAME;
102100
this.followAlternativeServices = HttpClientOptions.DEFAULT_FOLLOW_ALTERNATIVE_SERVICES;
@@ -116,32 +114,38 @@ public HttpClientConfig(HttpClientConfig other) {
116114
this.defaultPort = other.defaultPort;
117115
this.maxRedirects = other.maxRedirects;
118116
this.forceSni = other.forceSni;
119-
this.metricsName = other.metricsName;
120-
this.tracingPolicy = other.tracingPolicy;
117+
this.observabilityConfig = other.observabilityConfig != null ? new ObservabilityConfig(other.observabilityConfig) : null;
121118
this.shared = other.shared;
122119
this.name = other.name;
123120
this.followAlternativeServices = other.followAlternativeServices;
124121
}
125122

126-
public HttpClientConfig(HttpClientOptions other) {
127-
this.tcpConfig = new TcpClientConfig(other);
123+
public HttpClientConfig(HttpClientOptions options) {
124+
125+
ObservabilityConfig observabilityConfig = null;
126+
if (options.getMetricsName() != null || options.getTracingPolicy() != HttpServerOptions.DEFAULT_TRACING_POLICY) {
127+
observabilityConfig = new ObservabilityConfig()
128+
.setMetricsName(options.getMetricsName())
129+
.setTracingPolicy(options.getTracingPolicy());
130+
}
131+
132+
this.tcpConfig = new TcpClientConfig(options);
128133
this.quicConfig = defaultQuicConfig();
129-
this.ssl = other.isSsl();
130-
this.versions = new ArrayList<>(toSupportedVersion(other.getProtocolVersion()));
131-
this.http1Config = other.getHttp1Config();
132-
this.http2Config = other.getHttp2Config();
134+
this.ssl = options.isSsl();
135+
this.versions = new ArrayList<>(toSupportedVersion(options.getProtocolVersion()));
136+
this.http1Config = options.getHttp1Config();
137+
this.http2Config = options.getHttp2Config();
133138
this.http3Config = new Http3ClientConfig();
134-
this.verifyHost = other.isVerifyHost();
135-
this.decompressionEnabled = other.isDecompressionSupported();
136-
this.defaultHost = other.getDefaultHost();
137-
this.defaultPort = other.getDefaultPort();
138-
this.maxRedirects = other.getMaxRedirects();
139-
this.forceSni = other.isForceSni();
140-
this.metricsName = other.getMetricsName();
141-
this.tracingPolicy = other.getTracingPolicy();
142-
this.shared = other.isShared();
143-
this.name = other.getName();
144-
this.followAlternativeServices = other.getFollowAlternativeServices();
139+
this.verifyHost = options.isVerifyHost();
140+
this.decompressionEnabled = options.isDecompressionSupported();
141+
this.defaultHost = options.getDefaultHost();
142+
this.defaultPort = options.getDefaultPort();
143+
this.maxRedirects = options.getMaxRedirects();
144+
this.forceSni = options.isForceSni();
145+
this.observabilityConfig = observabilityConfig;
146+
this.shared = options.isShared();
147+
this.name = options.getName();
148+
this.followAlternativeServices = options.getFollowAlternativeServices();
145149
}
146150

147151
/**
@@ -466,39 +470,19 @@ public HttpClientConfig setForceSni(boolean forceSni) {
466470
}
467471

468472
/**
469-
* @return the metrics name identifying the reported metrics
470-
*/
471-
public String getMetricsName() {
472-
return metricsName;
473-
}
474-
475-
/**
476-
* Set the metrics name identifying the reported metrics, useful for grouping metrics
477-
* with the same name.
478-
*
479-
* @param metricsName the metrics name
480-
* @return a reference to this, so the API can be used fluently
481-
*/
482-
public HttpClientConfig setMetricsName(String metricsName) {
483-
this.metricsName = metricsName;
484-
return this;
485-
}
486-
487-
/**
488-
* @return the tracing policy
473+
* @return the client observability config.
489474
*/
490-
public TracingPolicy getTracingPolicy() {
491-
return tracingPolicy;
475+
public ObservabilityConfig getObservabilityConfig() {
476+
return observabilityConfig;
492477
}
493478

494479
/**
495-
* Set the tracing policy for the client behavior when Vert.x has tracing enabled.
496-
*
497-
* @param tracingPolicy the tracing policy
480+
* Set the client observability config.
481+
* @param observabilityConfig the server observability config
498482
* @return a reference to this, so the API can be used fluently
499483
*/
500-
public HttpClientConfig setTracingPolicy(TracingPolicy tracingPolicy) {
501-
this.tracingPolicy = tracingPolicy;
484+
public HttpClientConfig setObservabilityConfig(ObservabilityConfig observabilityConfig) {
485+
this.observabilityConfig = observabilityConfig;
502486
return this;
503487
}
504488

vertx-core/src/main/java/io/vertx/core/http/HttpServerConfig.java

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ private static TcpServerConfig defaultTcpServerConfig() {
6666
private int maxFormBufferedBytes;
6767
private boolean handle100ContinueAutomatically;
6868
private boolean strictThreadMode;
69-
private String metricsName;
70-
private TracingPolicy tracingPolicy;
69+
private ObservabilityConfig observabilityConfig;
7170
private Http1ServerConfig http1Config;
7271
private Http2ServerConfig http2Config;
7372
private Http3ServerConfig http3Config;
@@ -113,14 +112,20 @@ public HttpServerConfig(HttpServerOptions options) {
113112
versions = EnumSet.of(HttpVersion.HTTP_1_1);
114113
}
115114

115+
ObservabilityConfig observabilityConfig = null;
116+
if (options.getMetricsName() != null || options.getTracingPolicy() != HttpServerOptions.DEFAULT_TRACING_POLICY) {
117+
observabilityConfig = new ObservabilityConfig()
118+
.setMetricsName(options.getMetricsName())
119+
.setTracingPolicy(options.getTracingPolicy());
120+
}
121+
116122
this.versions = versions;
117123
this.maxFormAttributeSize = options.getMaxFormAttributeSize();
118124
this.maxFormFields = options.getMaxFormFields();
119125
this.maxFormBufferedBytes = options.getMaxFormBufferedBytes();
120126
this.handle100ContinueAutomatically = options.isHandle100ContinueAutomatically();
121127
this.strictThreadMode = options.getStrictThreadMode();
122-
this.metricsName = options.getMetricsName();
123-
this.tracingPolicy = options.getTracingPolicy();
128+
this.observabilityConfig = observabilityConfig;
124129
this.http1Config = new Http1ServerConfig(options.getHttp1Config());
125130
this.http2Config = new Http2ServerConfig(options.getHttp2Config());
126131
this.webSocketConfig = new WebSocketServerConfig(options.getWebSocketConfig());
@@ -139,8 +144,7 @@ public HttpServerConfig() {
139144
this.maxFormBufferedBytes = HttpServerOptions.DEFAULT_MAX_FORM_BUFFERED_SIZE;
140145
this.handle100ContinueAutomatically = HttpServerOptions.DEFAULT_HANDLE_100_CONTINE_AUTOMATICALLY;
141146
this.strictThreadMode = HttpServerOptions.DEFAULT_STRICT_THREAD_MODE_STRICT;
142-
this.metricsName = null;
143-
this.tracingPolicy = HttpServerOptions.DEFAULT_TRACING_POLICY;
147+
this.observabilityConfig = null;
144148
this.http1Config = null;
145149
this.http2Config = null;
146150
this.http3Config = null;
@@ -162,8 +166,7 @@ public HttpServerConfig(HttpServerConfig other) {
162166
this.maxFormBufferedBytes = other.maxFormBufferedBytes;
163167
this.handle100ContinueAutomatically = other.handle100ContinueAutomatically;
164168
this.strictThreadMode = other.strictThreadMode;
165-
this.metricsName = other.metricsName;
166-
this.tracingPolicy = other.tracingPolicy;
169+
this.observabilityConfig = other.observabilityConfig != null ? new ObservabilityConfig(other.observabilityConfig) : null;
167170
this.http1Config = other.http1Config != null ? new Http1ServerConfig(other.http1Config) : null;
168171
this.http2Config = other.http2Config != null ? new Http2ServerConfig(other.http2Config) : null;
169172
this.http3Config = other.http3Config != null ? new Http3ServerConfig(other.http3Config) : null;
@@ -470,38 +473,19 @@ public HttpServerConfig setStrictThreadMode(boolean strictThreadMode) {
470473
}
471474

472475
/**
473-
* @return the metrics name identifying the reported metrics.
474-
*/
475-
public String getMetricsName() {
476-
return metricsName;
477-
}
478-
479-
/**
480-
* Set the metrics name identifying the reported metrics, useful for naming the server metrics.
481-
*
482-
* @param metricsName the metrics name
483-
* @return a reference to this, so the API can be used fluently
484-
*/
485-
public HttpServerConfig setMetricsName(String metricsName) {
486-
this.metricsName = metricsName;
487-
return this;
488-
}
489-
490-
/**
491-
* @return the tracing policy
476+
* @return the server observability config.
492477
*/
493-
public TracingPolicy getTracingPolicy() {
494-
return tracingPolicy;
478+
public ObservabilityConfig getObservabilityConfig() {
479+
return observabilityConfig;
495480
}
496481

497482
/**
498-
* Set the tracing policy for the server behavior when Vert.x has tracing enabled.
499-
*
500-
* @param tracingPolicy the tracing policy
483+
* Set the server observability config.
484+
* @param observabilityConfig the server observability config
501485
* @return a reference to this, so the API can be used fluently
502486
*/
503-
public HttpServerConfig setTracingPolicy(TracingPolicy tracingPolicy) {
504-
this.tracingPolicy = tracingPolicy;
487+
public HttpServerConfig setObservabilityConfig(ObservabilityConfig observabilityConfig) {
488+
this.observabilityConfig = observabilityConfig;
505489
return this;
506490
}
507491

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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;
12+
13+
import io.vertx.codegen.annotations.DataObject;
14+
import io.vertx.core.tracing.TracingPolicy;
15+
16+
/**
17+
* Generic client/server observability config.
18+
*
19+
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
20+
*/
21+
@DataObject
22+
public class ObservabilityConfig {
23+
24+
private String metricsName;
25+
private TracingPolicy tracingPolicy;
26+
27+
public ObservabilityConfig() {
28+
this.metricsName = null;
29+
this.tracingPolicy = HttpServerOptions.DEFAULT_TRACING_POLICY;
30+
}
31+
32+
public ObservabilityConfig(ObservabilityConfig other) {
33+
this.metricsName = other.metricsName;
34+
this.tracingPolicy = other.tracingPolicy;
35+
}
36+
37+
/**
38+
* @return the metrics name identifying the reported metrics.
39+
*/
40+
public String getMetricsName() {
41+
return metricsName;
42+
}
43+
44+
/**
45+
* Set the metrics name identifying the reported metrics, useful for naming the server metrics.
46+
*
47+
* @param metricsName the metrics name
48+
* @return a reference to this, so the API can be used fluently
49+
*/
50+
public ObservabilityConfig setMetricsName(String metricsName) {
51+
this.metricsName = metricsName;
52+
return this;
53+
}
54+
55+
/**
56+
* @return the tracing policy
57+
*/
58+
public TracingPolicy getTracingPolicy() {
59+
return tracingPolicy;
60+
}
61+
62+
/**
63+
* Set the tracing policy for the server behavior when Vert.x has tracing enabled.
64+
*
65+
* @param tracingPolicy the tracing policy
66+
* @return a reference to this, so the API can be used fluently
67+
*/
68+
public ObservabilityConfig setTracingPolicy(TracingPolicy tracingPolicy) {
69+
this.tracingPolicy = tracingPolicy;
70+
return this;
71+
}
72+
}

vertx-core/src/main/java/io/vertx/core/http/impl/HttpClientBuilderInternal.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.vertx.core.net.TcpClientConfig;
2828
import io.vertx.core.net.impl.tcp.NetClientBuilder;
2929
import io.vertx.core.spi.metrics.HttpClientMetrics;
30+
import io.vertx.core.tracing.TracingPolicy;
3031

3132
import java.time.Duration;
3233
import java.util.List;
@@ -192,7 +193,10 @@ private static TcpClientConfig netClientConfig(HttpClientConfig httpConfig) {
192193
TcpClientConfig config = new TcpClientConfig(httpConfig.getTcpConfig());
193194
config.setProxyOptions(null);
194195
config.setSsl(false);
195-
config.setMetricsName(httpConfig.getMetricsName());
196+
ObservabilityConfig observabilityConfig = httpConfig.getObservabilityConfig();
197+
if (observabilityConfig != null) {
198+
config.setMetricsName(observabilityConfig.getMetricsName());
199+
}
196200
return config;
197201
}
198202

@@ -267,9 +271,10 @@ public HttpClientAgent build() {
267271
.sslEngineOptions(sslEngineOptions)
268272
.build();
269273
LogConfig logConfig = co.getTcpConfig().getLogConfig();
274+
ObservabilityConfig observabilityConfig = co.getObservabilityConfig();
270275
transport = new TcpHttpClientTransport(
271276
tcpClient,
272-
co.getTracingPolicy(),
277+
observabilityConfig != null ? observabilityConfig.getTracingPolicy() : null,
273278
co.isDecompressionEnabled(),
274279
logConfig != null && logConfig.isEnabled(),
275280
logConfig != null ? logConfig.getDataFormat() : null,

vertx-core/src/main/java/io/vertx/core/http/impl/quic/QuicHttpClientTransport.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.vertx.core.http.Http3ClientConfig;
1717
import io.vertx.core.http.Http3Settings;
1818
import io.vertx.core.http.HttpClientConfig;
19+
import io.vertx.core.http.ObservabilityConfig;
1920
import io.vertx.core.http.impl.HttpClientConnection;
2021
import io.vertx.core.http.impl.HttpConnectParams;
2122
import io.vertx.core.http.impl.http3.Http3ClientConnection;
@@ -44,7 +45,11 @@ public class QuicHttpClientTransport implements HttpClientTransport {
4445
public QuicHttpClientTransport(VertxInternal vertx, HttpClientConfig config) {
4546

4647
QuicClientConfig quicConfig = new QuicClientConfig(config.getQuicConfig());
47-
quicConfig.setMetricsName(config.getMetricsName());
48+
49+
ObservabilityConfig observabilityConfig = config.getObservabilityConfig();
50+
if (observabilityConfig != null) {
51+
quicConfig.setMetricsName(observabilityConfig.getMetricsName());
52+
}
4853

4954
Http3ClientConfig http3Config = config.getHttp3Config();
5055
if (http3Config == null) {

vertx-core/src/main/java/io/vertx/core/http/impl/tcp/TcpHttpClientTransport.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.vertx.core.http.Http1ClientConfig;
2828
import io.vertx.core.http.Http2ClientConfig;
2929
import io.vertx.core.http.HttpClientConfig;
30+
import io.vertx.core.http.ObservabilityConfig;
3031
import io.vertx.core.http.impl.*;
3132
import io.vertx.core.http.impl.http1.Http1ClientConnection;
3233
import io.vertx.core.http.impl.http2.Http2ClientChannelInitializer;
@@ -65,8 +66,9 @@ public class TcpHttpClientTransport implements HttpClientTransport {
6566
public static TcpHttpClientTransport create(NetClientInternal netClient,
6667
HttpClientConfig config,
6768
HttpClientMetrics httpMetrics) {
69+
ObservabilityConfig observabilityConfig = config.getObservabilityConfig();
6870
return new TcpHttpClientTransport(netClient,
69-
config.getTracingPolicy(),
71+
observabilityConfig != null ? observabilityConfig.getTracingPolicy() : null,
7072
config.isDecompressionEnabled(),
7173
config.getTcpConfig().getLogConfig() != null && config.getTcpConfig().getLogConfig().isEnabled(),
7274
config.getTcpConfig().getLogConfig() != null ? config.getTcpConfig().getLogConfig().getDataFormat() : null,

vertx-core/src/main/java/io/vertx/core/http/impl/tcp/TcpHttpServer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ public synchronized Future<HttpServer> listen(ContextInternal context, SocketAdd
235235
exceptionHandler,
236236
http2Config != null ? http2Config.getConnectionWindowSize() : HttpServerOptions.DEFAULT_HTTP2_CONNECTION_WINDOW_SIZE);
237237

238+
ObservabilityConfig observabilityConfig = config.getObservabilityConfig();
239+
238240
List<CompressionOptions> compressors = compression != null ? compression.getCompressors() : null;
239241
HttpServerConnectionInitializer initializer = new HttpServerConnectionInitializer(
240242
listenContext,
@@ -244,7 +246,7 @@ public synchronized Future<HttpServer> listen(ContextInternal context, SocketAdd
244246
this,
245247
compressors != null && !compressors.isEmpty() && compression.isCompressionEnabled(),
246248
compressors != null && !compressors.isEmpty() && compression.isDecompressionEnabled(),
247-
config.getTracingPolicy(),
249+
observabilityConfig != null ? observabilityConfig.getTracingPolicy() : null,
248250
config.getTcpConfig().getLogConfig() != null,
249251
compressors != null ? compressors.toArray(new CompressionOptions[0]) : null,
250252
compression != null ? compression.getContentSizeThreshold() : 0,

vertx-core/src/test/java/io/vertx/test/fakemetrics/FakeVertxMetrics.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public EventBusMetrics createEventBusMetrics() {
6161

6262
@Override
6363
public HttpClientMetrics<?, ?> createHttpClientMetrics(HttpClientConfig options) {
64-
return new FakeHttpClientMetrics(options.getMetricsName());
64+
ObservabilityConfig observabilityConfig = options.getObservabilityConfig();
65+
return new FakeHttpClientMetrics(observabilityConfig != null ? observabilityConfig.getMetricsName() : null);
6566
}
6667

6768
public TransportMetrics<?> createTcpServerMetrics(TcpServerConfig config, String protocol, SocketAddress localAddress) {

0 commit comments

Comments
 (0)