Skip to content

Commit e627d45

Browse files
committed
Address review comments on httpclient-5.x exclude-port fix
- Use effective port (port(host)) instead of host.getPort() in skipIntercept so default ports (-1) resolve correctly to 80/443 - Fix Javadoc on PROPAGATION_EXCLUDE_PORTS to state that tracing is fully skipped (no span, no headers), not just header injection - Update CHANGES.md to match actual behaviour - Replace atLeastOnce() with times(3) in tests for consistency with existing module tests - Fix misleading Javadoc + add missing non-excluded-port assertion in multipleExcludedPorts test
1 parent 4d1e290 commit e627d45

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Release Notes.
77

88
* Added support for Lettuce reactive Redis commands.
99
* Add Spring AI 1.x plugin and GenAI layer.
10-
* Fix httpclient-5.x plugin injecting sw8 propagation headers into ClickHouse HTTP requests (port 8123), causing HTTP 400. Add `PROPAGATION_EXCLUDE_PORTS` config to skip header injection for specified ports.
10+
* Fix httpclient-5.x plugin injecting sw8 propagation headers into ClickHouse HTTP requests (port 8123), causing HTTP 400. Add `PROPAGATION_EXCLUDE_PORTS` config to skip tracing (including header injection) for specified ports in the classic client interceptor.
1111

1212
All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/249?closed=1)
1313

apm-sniffer/apm-sdk-plugin/httpclient-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpclient/v5/HttpClient5PluginConfig.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ public static class Plugin {
2525
@PluginConfig(root = HttpClient5PluginConfig.class)
2626
public static class HttpClient5 {
2727
/**
28-
* Comma-separated list of destination ports whose HTTP requests
29-
* should NOT have SkyWalking propagation headers injected.
28+
* Comma-separated list of destination ports whose outbound HTTP requests
29+
* will be completely skipped by the classic client interceptor: no exit
30+
* span is created and no SkyWalking propagation headers are injected.
3031
*
3132
* <p>Some HTTP-based database protocols (e.g. ClickHouse on port 8123)
3233
* reject requests that contain unknown HTTP headers, returning HTTP 400.
33-
* Adding such ports here prevents the agent from injecting the {@code sw8}
34-
* tracing headers into those outbound requests while leaving all other
35-
* HTTP calls fully traced.
34+
* Adding such ports here prevents the agent from creating exit spans
35+
* and from injecting the {@code sw8} tracing headers into those outbound
36+
* requests, meaning these requests are completely untraced by SkyWalking,
37+
* while leaving all other HTTP calls fully traced.
3638
*
3739
* <p>Default: {@code "8123"} (ClickHouse HTTP interface).
3840
*

apm-sniffer/apm-sdk-plugin/httpclient-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpclient/v5/HttpClientDoExecuteInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected boolean skipIntercept(EnhancedInstance objInst, Method method, Object[
9595
if (host == null) {
9696
return true;
9797
}
98-
return isExcludedPort(host.getPort());
98+
return isExcludedPort(port(host));
9999
}
100100

101101
/**

apm-sniffer/apm-sdk-plugin/httpclient-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/httpclient/v5/HttpClientPropagationExcludePortTest.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ public void internalClient_requestToRegularPort_spanCreatedAndHeadersInjected()
151151

152152
List<TraceSegment> segments = segmentStorage.getTraceSegments();
153153
assertThat("A trace segment must be created for a non-excluded port", segments.size(), is(1));
154-
// sw8, sw8-correlation, sw8-x are the 3 propagation headers
155-
verify(request, org.mockito.Mockito.atLeastOnce()).setHeader(anyString(), anyString());
154+
// sw8, sw8-correlation, sw8-x – exactly 3 propagation headers, consistent with existing tests
155+
verify(request, org.mockito.Mockito.times(3)).setHeader(anyString(), anyString());
156156
}
157157

158158
// -----------------------------------------------------------------------
@@ -183,7 +183,7 @@ public void minimalClient_requestToRegularPort_spanCreatedAndHeadersInjected() t
183183

184184
List<TraceSegment> segments = segmentStorage.getTraceSegments();
185185
assertThat("A trace segment must be created for a non-excluded port", segments.size(), is(1));
186-
verify(request, org.mockito.Mockito.atLeastOnce()).setHeader(anyString(), anyString());
186+
verify(request, org.mockito.Mockito.times(3)).setHeader(anyString(), anyString());
187187
}
188188

189189
// -----------------------------------------------------------------------
@@ -209,20 +209,20 @@ public void whenExcludePortsEmpty_allPortsAreTraced() throws Throwable {
209209

210210
/**
211211
* Multiple ports can be listed: verify that both excluded ports are silently
212-
* skipped while a third, non-excluded port is still traced.
212+
* skipped while a non-excluded port is still traced under the same config.
213213
*/
214214
@Test
215-
public void multipleExcludedPorts_allSkipped() throws Throwable {
215+
public void multipleExcludedPorts_allSkippedAndNonExcludedStillTraced() throws Throwable {
216216
HttpClient5PluginConfig.Plugin.HttpClient5.PROPAGATION_EXCLUDE_PORTS = "8123,9200";
217217

218218
HttpClientDoExecuteInterceptor freshInterceptor = new MinimalClientDoExecuteInterceptor();
219219

220220
// 8123 – must be excluded
221221
freshInterceptor.beforeMethod(enhancedInstance, null, clickHouseArgs, argumentsType, null);
222222
freshInterceptor.afterMethod(enhancedInstance, null, clickHouseArgs, argumentsType, httpResponse);
223-
assertThat(segmentStorage.getTraceSegments().size(), is(0));
223+
assertThat("Port 8123 should be excluded", segmentStorage.getTraceSegments().size(), is(0));
224224

225-
// Set up a mock host on port 9200 (Elasticsearch)
225+
// 9200 (Elasticsearch) – must also be excluded
226226
HttpHost esHost = org.mockito.Mockito.mock(HttpHost.class);
227227
when(esHost.getHostName()).thenReturn("es-server");
228228
when(esHost.getSchemeName()).thenReturn("http");
@@ -233,5 +233,12 @@ public void multipleExcludedPorts_allSkipped() throws Throwable {
233233
freshInterceptor.beforeMethod(enhancedInstance, null, esArgs, argumentsType, null);
234234
freshInterceptor.afterMethod(enhancedInstance, null, esArgs, argumentsType, httpResponse);
235235
assertThat("Port 9200 should also be excluded", segmentStorage.getTraceSegments().size(), is(0));
236+
237+
// 8080 (regular service) – must still be traced under the same multi-port config
238+
freshInterceptor = new MinimalClientDoExecuteInterceptor();
239+
freshInterceptor.beforeMethod(enhancedInstance, null, regularArgs, argumentsType, null);
240+
freshInterceptor.afterMethod(enhancedInstance, null, regularArgs, argumentsType, httpResponse);
241+
assertThat("Non-excluded port 8080 must still produce a trace segment",
242+
segmentStorage.getTraceSegments().size(), is(1));
236243
}
237244
}

0 commit comments

Comments
 (0)