Provide a configuration to control the length of the peer field (#3105)
* Fix 3096
This commit is contained in:
parent
758b085c4f
commit
b1dea4c540
|
|
@ -158,6 +158,12 @@ public class Config {
|
|||
}
|
||||
|
||||
public static class Plugin {
|
||||
|
||||
/**
|
||||
* Control the length of the peer field.
|
||||
*/
|
||||
public static int PEER_MAX_LENGTH = 200;
|
||||
|
||||
public static class MongoDB {
|
||||
/**
|
||||
* If true, trace all the parameters in MongoDB access, default is false. Only trace the operation, not include parameters.
|
||||
|
|
|
|||
|
|
@ -18,17 +18,6 @@
|
|||
|
||||
package org.apache.skywalking.apm.agent.core.conf;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
|
||||
import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath;
|
||||
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
|
||||
|
|
@ -37,6 +26,9 @@ import org.apache.skywalking.apm.util.ConfigInitializer;
|
|||
import org.apache.skywalking.apm.util.PropertyPlaceholderHelper;
|
||||
import org.apache.skywalking.apm.util.StringUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* The <code>SnifferConfigInitializer</code> initializes all configs in several way.
|
||||
*
|
||||
|
|
@ -100,6 +92,10 @@ public class SnifferConfigInitializer {
|
|||
if (StringUtil.isEmpty(Config.Collector.BACKEND_SERVICE)) {
|
||||
throw new ExceptionInInitializerError("`collector.backend_service` is missing.");
|
||||
}
|
||||
if (Config.Plugin.PEER_MAX_LENGTH <= 3) {
|
||||
logger.warn("PEER_MAX_LENGTH configuration:{} error, the default value of 200 will be used.", Config.Plugin.PEER_MAX_LENGTH);
|
||||
Config.Plugin.PEER_MAX_LENGTH = 200;
|
||||
}
|
||||
|
||||
IS_INIT_COMPLETED = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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.agent.core.context.util;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.conf.Config;
|
||||
import org.apache.skywalking.apm.util.StringUtil;
|
||||
|
||||
/**
|
||||
* @author zhaoyuguang
|
||||
*/
|
||||
|
||||
public class PeerFormat {
|
||||
|
||||
private static final String ABBR = "...";
|
||||
|
||||
public static String shorten(String original) {
|
||||
if (!StringUtil.isEmpty(original) && original.length() > Config.Plugin.PEER_MAX_LENGTH) {
|
||||
return original.substring(0, Config.Plugin.PEER_MAX_LENGTH - 3) + ABBR;
|
||||
}
|
||||
return original;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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.agent.core.util;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.context.util.PeerFormat;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author zhaoyuguang
|
||||
*/
|
||||
|
||||
public class PeerFormatTest {
|
||||
|
||||
@Test
|
||||
public void testShorten() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
sb.append("localhost:" + i + ";");
|
||||
}
|
||||
Assert.assertTrue(PeerFormat.shorten(sb.toString()).length() == 200);
|
||||
}
|
||||
}
|
||||
|
|
@ -19,11 +19,13 @@
|
|||
|
||||
package org.apache.skywalking.apm.plugin.jedis.v2;
|
||||
|
||||
import java.util.Set;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import org.apache.skywalking.apm.agent.core.context.util.PeerFormat;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class JedisClusterConstructorWithListHostAndPortArgInterceptor implements InstanceConstructorInterceptor {
|
||||
|
||||
@Override
|
||||
|
|
@ -34,6 +36,6 @@ public class JedisClusterConstructorWithListHostAndPortArgInterceptor implements
|
|||
redisConnInfo.append(hostAndPort.toString()).append(";");
|
||||
}
|
||||
|
||||
objInst.setSkyWalkingDynamicField(redisConnInfo.toString());
|
||||
objInst.setSkyWalkingDynamicField(PeerFormat.shorten(redisConnInfo.toString()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,9 @@
|
|||
|
||||
package org.apache.skywalking.apm.plugin.jedis.v2;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
@ -29,6 +28,9 @@ import org.mockito.Mock;
|
|||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
|
|
@ -56,9 +58,32 @@ public class JedisClusterConstructorWithListHostAndPortArgInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void onConstruct() throws Exception {
|
||||
interceptor.onConstruct(enhancedInstance, new Object[] {hostAndPortSet});
|
||||
interceptor.onConstruct(enhancedInstance, new Object[]{hostAndPortSet});
|
||||
|
||||
verify(enhancedInstance).setSkyWalkingDynamicField("127.0.0.1:6379;127.0.0.1:16379;");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onHugeClusterConstruct() throws Exception {
|
||||
hostAndPortSet = new LinkedHashSet<HostAndPort>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
hostAndPortSet.add(new HostAndPort("localhost", i));
|
||||
}
|
||||
enhancedInstance = new EnhancedInstance() {
|
||||
private Object v;
|
||||
|
||||
@Override
|
||||
public Object getSkyWalkingDynamicField() {
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSkyWalkingDynamicField(Object value) {
|
||||
this.v = value;
|
||||
}
|
||||
};
|
||||
interceptor.onConstruct(enhancedInstance, new Object[]{hostAndPortSet});
|
||||
Assert.assertTrue(enhancedInstance.getSkyWalkingDynamicField().toString().length() == 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
package org.apache.skywalking.apm.plugin.kafka.v11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.plugin.kafka.v1.ConsumerConstructorInterceptor;
|
||||
|
|
@ -29,6 +27,8 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
|
|||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import org.apache.skywalking.apm.agent.core.context.util.PeerFormat;
|
||||
import org.redisson.config.*;
|
||||
import org.redisson.connection.ConnectionManager;
|
||||
|
||||
|
|
@ -60,24 +61,24 @@ public class ConnectionManagerInterceptor implements InstanceMethodsAroundInterc
|
|||
|
||||
if (sentinelServersConfig != null) {
|
||||
appendAddresses(peer, sentinelServersConfig.getSentinelAddresses());
|
||||
retInst.setSkyWalkingDynamicField(peer.toString());
|
||||
retInst.setSkyWalkingDynamicField(PeerFormat.shorten(peer.toString()));
|
||||
return ret;
|
||||
}
|
||||
if (masterSlaveServersConfig != null) {
|
||||
URI masterAddress = masterSlaveServersConfig.getMasterAddress();
|
||||
peer.append(masterAddress.getHost()).append(":").append(masterAddress.getPort());
|
||||
appendAddresses(peer, masterSlaveServersConfig.getSlaveAddresses());
|
||||
retInst.setSkyWalkingDynamicField(peer.toString());
|
||||
retInst.setSkyWalkingDynamicField(PeerFormat.shorten(peer.toString()));
|
||||
return ret;
|
||||
}
|
||||
if (clusterServersConfig != null) {
|
||||
appendAddresses(peer, clusterServersConfig.getNodeAddresses());
|
||||
retInst.setSkyWalkingDynamicField(peer.toString());
|
||||
retInst.setSkyWalkingDynamicField(PeerFormat.shorten(peer.toString()));
|
||||
return ret;
|
||||
}
|
||||
if (replicatedServersConfig != null) {
|
||||
appendAddresses(peer, replicatedServersConfig.getNodeAddresses());
|
||||
retInst.setSkyWalkingDynamicField(peer.toString());
|
||||
retInst.setSkyWalkingDynamicField(PeerFormat.shorten(peer.toString()));
|
||||
return ret;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import io.lettuce.core.RedisURI;
|
|||
import io.lettuce.core.cluster.RedisClusterClient;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import org.apache.skywalking.apm.agent.core.context.util.PeerFormat;
|
||||
|
||||
/**
|
||||
* @author zhaoyuguang
|
||||
|
|
@ -39,6 +40,6 @@ public class RedisClusterClientConstructorInterceptor implements InstanceConstru
|
|||
peer.append(redisURI.getHost()).append(":").append(redisURI.getPort()).append(";");
|
||||
}
|
||||
EnhancedInstance optionsInst = (EnhancedInstance) redisClusterClient.getOptions();
|
||||
optionsInst.setSkyWalkingDynamicField(peer.toString());
|
||||
optionsInst.setSkyWalkingDynamicField(PeerFormat.shorten(peer.toString()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.skywalking.apm.plugin.lettuce.v5;
|
||||
|
||||
import io.lettuce.core.RedisURI;
|
||||
import io.lettuce.core.protocol.Command;
|
||||
import io.lettuce.core.protocol.CommandType;
|
||||
import io.lettuce.core.protocol.RedisCommand;
|
||||
|
|
@ -32,6 +33,8 @@ 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.lettuce.v5.mock.MockRedisClusterClient;
|
||||
import org.apache.skywalking.apm.plugin.lettuce.v5.mock.MockRedisClusterClientConstructorInterceptor;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.hamcrest.core.Is;
|
||||
|
|
@ -43,6 +46,7 @@ import org.mockito.Mock;
|
|||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
|
@ -109,4 +113,17 @@ public class RedisChannelWriterInterceptorTest {
|
|||
assertThat(tags.get(0).getValue(), is("Redis"));
|
||||
assertThat(SpanHelper.getLayer(spans.get(0)), CoreMatchers.is(SpanLayer.CACHE));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOnHugeClusterConsumerConfig() {
|
||||
List<RedisURI> redisURIs = new ArrayList<>(100);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
redisURIs.add(RedisURI.create("localhost", i));
|
||||
}
|
||||
MockRedisClusterClient mockRedisClusterClient = new MockRedisClusterClient();
|
||||
MockRedisClusterClientConstructorInterceptor constructorInterceptor = new MockRedisClusterClientConstructorInterceptor();
|
||||
constructorInterceptor.onConstruct(mockRedisClusterClient, new Object[]{null, redisURIs});
|
||||
assertThat(mockRedisClusterClient.getOptions().getSkyWalkingDynamicField().toString().length(), Is.is(200));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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.lettuce.v5.mock;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
|
||||
/**
|
||||
* @author zhaoyuguang
|
||||
*/
|
||||
|
||||
public class MockRedisClusterClient implements EnhancedInstance {
|
||||
|
||||
private Object ms;
|
||||
|
||||
private EnhancedInstance options = new EnhancedInstance() {
|
||||
private Object os;
|
||||
|
||||
@Override
|
||||
public Object getSkyWalkingDynamicField() {
|
||||
return os;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSkyWalkingDynamicField(Object value) {
|
||||
this.os = value;
|
||||
}
|
||||
};
|
||||
|
||||
public EnhancedInstance getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
public void setOptions(EnhancedInstance options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSkyWalkingDynamicField() {
|
||||
return ms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSkyWalkingDynamicField(Object value) {
|
||||
this.ms = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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.lettuce.v5.mock;
|
||||
|
||||
import io.lettuce.core.RedisURI;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import org.apache.skywalking.apm.agent.core.context.util.PeerFormat;
|
||||
|
||||
/**
|
||||
* @author zhaoyuguang
|
||||
*/
|
||||
|
||||
public class MockRedisClusterClientConstructorInterceptor implements InstanceConstructorInterceptor {
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterable<RedisURI> redisURIs = (Iterable<RedisURI>) allArguments[1];
|
||||
MockRedisClusterClient redisClusterClient = (MockRedisClusterClient) objInst;
|
||||
StringBuilder peer = new StringBuilder();
|
||||
for (RedisURI redisURI : redisURIs) {
|
||||
peer.append(redisURI.getHost()).append(":").append(redisURI.getPort()).append(";");
|
||||
}
|
||||
EnhancedInstance optionsInst = redisClusterClient.getOptions();
|
||||
optionsInst.setSkyWalkingDynamicField(PeerFormat.shorten(peer.toString()));
|
||||
}
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ property key | Description | Default |
|
|||
`agent.is_open_debugging_class`|If true, skywalking agent will save all instrumented classes files in `/debugging` folder.Skywalking team may ask for these files in order to resolve compatible problem.|Not set|
|
||||
`agent.active_v2_header`|Active V2 header in default.|`true`|
|
||||
`agent.instance_uuid` |Instance uuid is the identity of an instance, skywalking treat same instance uuid as one instance.if empty, skywalking agent will generate an 32-bit uuid. |`""`|
|
||||
`agent.cause_exception_depth`|How depth the agent goes, when log all cause exceptions.|5|
|
||||
`agent.cause_exception_depth`|How depth the agent goes, when log all cause exceptions.|`5`|
|
||||
`agent.active_v1_header `|Deactive V1 header in default.|`false`|
|
||||
`collector.grpc_channel_check_interval`|grpc channel status check interval.|`30`|
|
||||
`collector.app_and_service_register_check_interval`|application and service registry check interval.|`3`|
|
||||
|
|
@ -79,6 +79,7 @@ property key | Description | Default |
|
|||
`buffer.buffer_size`|The buffer size.|`300`|
|
||||
`dictionary.service_code_buffer_size`|The buffer size of application codes and peer|`10 * 10000`|
|
||||
`dictionary.endpoint_name_buffer_size`|The buffer size of endpoint names and peer|`1000 * 10000`|
|
||||
`plugin.peer_max_length `|Peer maximum description limit.|`200`|
|
||||
`plugin.mongodb.trace_param`|If true, trace all the parameters in MongoDB access, default is false. Only trace the operation, not include parameters.|`false`|
|
||||
`plugin.elasticsearch.trace_dsl`|If true, trace all the DSL(Domain Specific Language) in ElasticSearch access, default is false.|`false`|
|
||||
`plugin.springmvc.use_qualified_name_as_endpoint_name`|If true, the fully qualified method name will be used as the endpoint name instead of the request URL, default is false.|`false`|
|
||||
|
|
|
|||
Loading…
Reference in New Issue