-
Notifications
You must be signed in to change notification settings - Fork 679
fix: add PROPAGATION_EXCLUDE_PORTS to httpclient-4.x plugin #800
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
Changes from 3 commits
9e3ed49
bd53bbd
aad37d2
8c53417
6d822b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.skywalking.apm.plugin.httpClient.v4; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.mockito.ArgumentMatchers.anyString; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.apache.http.HttpHost; | ||
| import org.apache.http.HttpResponse; | ||
| import org.apache.http.ProtocolVersion; | ||
| import org.apache.http.RequestLine; | ||
| import org.apache.http.StatusLine; | ||
| import org.apache.http.client.methods.HttpGet; | ||
| import org.apache.skywalking.apm.agent.core.boot.ServiceManager; | ||
| import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; | ||
| import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; | ||
| import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; | ||
| import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; | ||
| import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; | ||
| import org.apache.skywalking.apm.plugin.httpclient.HttpClientPluginConfig; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.MockitoJUnit; | ||
| import org.mockito.junit.MockitoRule; | ||
|
|
||
| /** | ||
| * Verifies that requests to ports listed in | ||
| * {@link HttpClientPluginConfig.Plugin.HttpClient#PROPAGATION_EXCLUDE_PORTS} | ||
| * are silently skipped (no span created, no sw8 header injected). | ||
| */ | ||
| @RunWith(TracingSegmentRunner.class) | ||
| public class HttpClientPropagationExcludePortTest { | ||
|
|
||
| @SegmentStoragePoint | ||
| private SegmentStorage segmentStorage; | ||
|
|
||
| @Rule | ||
| public AgentServiceRule agentServiceRule = new AgentServiceRule(); | ||
| @Rule | ||
| public MockitoRule rule = MockitoJUnit.rule(); | ||
|
|
||
| @Mock | ||
| private HttpHost clickHouseHost; | ||
| @Mock | ||
| private HttpHost regularHost; | ||
| @Mock | ||
| private HttpGet request; | ||
| @Mock | ||
| private HttpResponse httpResponse; | ||
| @Mock | ||
| private StatusLine statusLine; | ||
| @Mock | ||
| private EnhancedInstance enhancedInstance; | ||
|
|
||
| private HttpClientExecuteInterceptor interceptor; | ||
|
|
||
| private Object[] clickHouseArgs; | ||
| private Object[] regularArgs; | ||
| private Class<?>[] argumentsType; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| ServiceManager.INSTANCE.boot(); | ||
|
|
||
| HttpClientPluginConfig.Plugin.HttpClient.PROPAGATION_EXCLUDE_PORTS = "8123"; | ||
| interceptor = new HttpClientExecuteInterceptor(); | ||
|
|
||
| when(statusLine.getStatusCode()).thenReturn(200); | ||
| when(httpResponse.getStatusLine()).thenReturn(statusLine); | ||
|
|
||
| RequestLine requestLine = new RequestLine() { | ||
| @Override | ||
| public String getMethod() { | ||
| return "GET"; | ||
| } | ||
|
|
||
| @Override | ||
| public ProtocolVersion getProtocolVersion() { | ||
| return new ProtocolVersion("http", 1, 1); | ||
| } | ||
|
|
||
| @Override | ||
| public String getUri() { | ||
| return "http://my-service:8080/api/ping"; | ||
| } | ||
| }; | ||
| when(request.getRequestLine()).thenReturn(requestLine); | ||
|
|
||
| when(clickHouseHost.getHostName()).thenReturn("clickhouse-server"); | ||
| when(clickHouseHost.getSchemeName()).thenReturn("http"); | ||
| when(clickHouseHost.getPort()).thenReturn(8123); | ||
|
|
||
| when(regularHost.getHostName()).thenReturn("my-service"); | ||
| when(regularHost.getSchemeName()).thenReturn("http"); | ||
| when(regularHost.getPort()).thenReturn(8080); | ||
|
|
||
| clickHouseArgs = new Object[]{clickHouseHost, request}; | ||
| regularArgs = new Object[]{regularHost, request}; | ||
| argumentsType = new Class[]{HttpHost.class, HttpGet.class}; | ||
| } | ||
|
|
||
| @Test | ||
| public void requestToExcludedPort_noSpanAndNoHeaderInjected() throws Throwable { | ||
| interceptor.beforeMethod(enhancedInstance, null, clickHouseArgs, argumentsType, null); | ||
| interceptor.afterMethod(enhancedInstance, null, clickHouseArgs, argumentsType, httpResponse); | ||
|
|
||
| List<TraceSegment> segments = segmentStorage.getTraceSegments(); | ||
| assertThat(segments.size(), is(0)); | ||
| verify(request, never()).setHeader(anyString(), anyString()); | ||
| } | ||
|
|
||
| @Test | ||
| public void requestToRegularPort_spanCreatedAndHeadersInjected() throws Throwable { | ||
| interceptor.beforeMethod(enhancedInstance, null, regularArgs, argumentsType, null); | ||
| interceptor.afterMethod(enhancedInstance, null, regularArgs, argumentsType, httpResponse); | ||
|
|
||
| List<TraceSegment> segments = segmentStorage.getTraceSegments(); | ||
| assertThat(segments.size(), is(1)); | ||
| verify(request, times(3)).setHeader(anyString(), anyString()); | ||
| } | ||
|
|
||
| @Test | ||
| public void whenExcludePortsEmpty_allPortsAreTraced() throws Throwable { | ||
| HttpClientPluginConfig.Plugin.HttpClient.PROPAGATION_EXCLUDE_PORTS = ""; | ||
|
|
||
| HttpClientExecuteInterceptor freshInterceptor = new HttpClientExecuteInterceptor(); | ||
| freshInterceptor.beforeMethod(enhancedInstance, null, clickHouseArgs, argumentsType, null); | ||
| freshInterceptor.afterMethod(enhancedInstance, null, clickHouseArgs, argumentsType, httpResponse); | ||
|
|
||
| List<TraceSegment> segments = segmentStorage.getTraceSegments(); | ||
| assertThat(segments.size(), is(1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void multipleExcludedPorts_allSkippedAndNonExcludedStillTraced() throws Throwable { | ||
| HttpClientPluginConfig.Plugin.HttpClient.PROPAGATION_EXCLUDE_PORTS = "8123,9200"; | ||
|
|
||
| HttpClientExecuteInterceptor freshInterceptor = new HttpClientExecuteInterceptor(); | ||
|
|
||
| // 8123 should be excluded | ||
| freshInterceptor.beforeMethod(enhancedInstance, null, clickHouseArgs, argumentsType, null); | ||
| freshInterceptor.afterMethod(enhancedInstance, null, clickHouseArgs, argumentsType, httpResponse); | ||
| assertThat(segmentStorage.getTraceSegments().size(), is(0)); | ||
|
|
||
| // 9200 should also be excluded | ||
| HttpHost esHost = mock(HttpHost.class); | ||
| when(esHost.getHostName()).thenReturn("es-server"); | ||
| when(esHost.getSchemeName()).thenReturn("http"); | ||
| when(esHost.getPort()).thenReturn(9200); | ||
| Object[] esArgs = new Object[]{esHost, request}; | ||
|
|
||
| freshInterceptor = new HttpClientExecuteInterceptor(); | ||
| HttpClientPluginConfig.Plugin.HttpClient.PROPAGATION_EXCLUDE_PORTS = "8123,9200"; | ||
| freshInterceptor.beforeMethod(enhancedInstance, null, esArgs, argumentsType, null); | ||
| freshInterceptor.afterMethod(enhancedInstance, null, esArgs, argumentsType, httpResponse); | ||
| assertThat(segmentStorage.getTraceSegments().size(), is(0)); | ||
|
|
||
| // 8080 should still be traced | ||
| freshInterceptor = new HttpClientExecuteInterceptor(); | ||
| HttpClientPluginConfig.Plugin.HttpClient.PROPAGATION_EXCLUDE_PORTS = "8123,9200"; | ||
| freshInterceptor.beforeMethod(enhancedInstance, null, regularArgs, argumentsType, null); | ||
| freshInterceptor.afterMethod(enhancedInstance, null, regularArgs, argumentsType, httpResponse); | ||
| assertThat(segmentStorage.getTraceSegments().size(), is(1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void excludedPort_handleMethodExceptionSkipped() throws Throwable { | ||
| interceptor.beforeMethod(enhancedInstance, null, clickHouseArgs, argumentsType, null); | ||
| interceptor.handleMethodException(enhancedInstance, null, clickHouseArgs, argumentsType, new RuntimeException("test")); | ||
| interceptor.afterMethod(enhancedInstance, null, clickHouseArgs, argumentsType, httpResponse); | ||
|
|
||
| List<TraceSegment> segments = segmentStorage.getTraceSegments(); | ||
| assertThat(segments.size(), is(0)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,8 +218,10 @@ plugin.jdkthreading.threading_class_prefixes=${SW_PLUGIN_JDKTHREADING_THREADING_ | |
| plugin.tomcat.collect_http_params=${SW_PLUGIN_TOMCAT_COLLECT_HTTP_PARAMS:false} | ||
| # This config item controls that whether the SpringMVC plugin should collect the parameters of the request, when your Spring application is based on Tomcat, consider only setting either `plugin.tomcat.collect_http_params` or `plugin.springmvc.collect_http_params`. Also, activate implicitly in the profiled trace. | ||
| plugin.springmvc.collect_http_params=${SW_PLUGIN_SPRINGMVC_COLLECT_HTTP_PARAMS:false} | ||
| # This config item controls that whether the HttpClient plugin should collect the parameters of the request | ||
| # This config item controls that whether the HttpClient plugin should collect the parameters of the request | ||
| plugin.httpclient.collect_http_params=${SW_PLUGIN_HTTPCLIENT_COLLECT_HTTP_PARAMS:false} | ||
| # Comma-separated list of destination ports whose outbound HTTP requests will be completely skipped by the httpclient-4.x interceptor (no exit span created, no sw8 headers injected). Default: 8123 (ClickHouse HTTP interface). | ||
| plugin.httpclient.propagation_exclude_ports=${SW_PLUGIN_HTTPCLIENT_PROPAGATION_EXCLUDE_PORTS:8123} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be added as a default. This config should only exist in ck test cases.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Removed the default from |
||
| # When `COLLECT_HTTP_PARAMS` is enabled, how many characters to keep and send to the OAP backend, use negative values to keep and send the complete parameters, NB. this config item is added for the sake of performance. | ||
| plugin.http.http_params_length_threshold=${SW_PLUGIN_HTTP_HTTP_PARAMS_LENGTH_THRESHOLD:1024} | ||
| # When `include_http_headers` declares header names, this threshold controls the length limitation of all header values. use negative values to keep and send the complete headers. Note. this config item is added for the sake of performance. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This default value should be removed. No default to exclude. The config item
plugin.httpclient.propagation_exclude_portsshould be a part of config file, but also have an empty value.