You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2019/08/28 14:18:19 UTC
[skywalking] branch master updated: ADD: add operationName length
threshold (#3357)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 3d00d83 ADD: add operationName length threshold (#3357)
3d00d83 is described below
commit 3d00d83fc6cea95d443987d17b881bbbbc14746f
Author: Stalary <st...@163.com>
AuthorDate: Wed Aug 28 22:18:11 2019 +0800
ADD: add operationName length threshold (#3357)
* ADD: add operationName length threshold
* MOD:move operationName threshold to Config, simplified code
* MOD:update agent set-up document, clean code
* MOD:add agent.operation_name_threshold conf prefix
---
.../src/main/java/org/apache/skywalking/apm/util/StringUtil.java | 7 +++++++
.../test/java/org/apache/skywalking/apm/util/StringUtilTest.java | 8 ++++++++
.../java/org/apache/skywalking/apm/agent/core/conf/Config.java | 5 +++++
.../apache/skywalking/apm/agent/core/context/ContextManager.java | 6 ++++++
apm-sniffer/config/agent.config | 3 +++
docs/en/setup/service-agent/java-agent/README.md | 1 +
6 files changed, 30 insertions(+)
diff --git a/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/StringUtil.java b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/StringUtil.java
index ce236b4..5c7dc21 100644
--- a/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/StringUtil.java
+++ b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/StringUtil.java
@@ -62,4 +62,11 @@ public final class StringUtil {
}
return true;
}
+
+ public static String cut(String str, int threshold) {
+ if (isEmpty(str) || str.length() <= threshold) {
+ return str;
+ }
+ return str.substring(0, threshold);
+ }
}
diff --git a/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java b/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java
index b918e2e..e5158a3 100644
--- a/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java
+++ b/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java
@@ -53,4 +53,12 @@ public class StringUtilTest {
Assert.assertFalse(StringUtil.substringMatch("", 4770, ""));
}
+ @Test
+ public void testCut() {
+ String str = "aaaaaaabswbswbbsbwbsbbwbsbwbsbwbbsbbebewewewewewewewewewewew";
+ String shortStr = "ab";
+ Assert.assertEquals(10, StringUtil.cut(str, 10).length());
+ Assert.assertEquals(2, StringUtil.cut(shortStr, 10).length());
+ }
+
}
\ No newline at end of file
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java
index 7458995..376ee6b 100755
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java
@@ -105,6 +105,11 @@ public class Config {
* status more than this number. The channel check will call channel.getState(true) to requestConnection.
*/
public static long FORCE_RECONNECTION_PERIOD = 1;
+
+ /**
+ * Limit the length of the operationName to prevent errors when inserting elasticsearch
+ **/
+ public static int OPERATION_NAME_THRESHOLD = 500;
}
public static class Collector {
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java
index 206cb68..9a0dfa6 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java
@@ -26,6 +26,8 @@ import org.apache.skywalking.apm.agent.core.logging.api.*;
import org.apache.skywalking.apm.agent.core.sampling.SamplingService;
import org.apache.skywalking.apm.util.StringUtil;
+import static org.apache.skywalking.apm.agent.core.conf.Config.Agent.OPERATION_NAME_THRESHOLD;
+
/**
* {@link ContextManager} controls the whole context of {@link TraceSegment}. Any {@link TraceSegment} relates to
* single-thread, so this context use {@link ThreadLocal} to maintain the context, and make sure, since a {@link
@@ -89,6 +91,7 @@ public class ContextManager implements BootService {
public static AbstractSpan createEntrySpan(String operationName, ContextCarrier carrier) {
AbstractSpan span;
AbstractTracerContext context;
+ operationName = StringUtil.cut(operationName, OPERATION_NAME_THRESHOLD);
if (carrier != null && carrier.isValid()) {
SamplingService samplingService = ServiceManager.INSTANCE.findService(SamplingService.class);
samplingService.forceSampled();
@@ -103,6 +106,7 @@ public class ContextManager implements BootService {
}
public static AbstractSpan createLocalSpan(String operationName) {
+ operationName = StringUtil.cut(operationName, OPERATION_NAME_THRESHOLD);
AbstractTracerContext context = getOrCreate(operationName, false);
return context.createLocalSpan(operationName);
}
@@ -111,6 +115,7 @@ public class ContextManager implements BootService {
if (carrier == null) {
throw new IllegalArgumentException("ContextCarrier can't be null.");
}
+ operationName = StringUtil.cut(operationName, OPERATION_NAME_THRESHOLD);
AbstractTracerContext context = getOrCreate(operationName, false);
AbstractSpan span = context.createExitSpan(operationName, remotePeer);
context.inject(carrier);
@@ -118,6 +123,7 @@ public class ContextManager implements BootService {
}
public static AbstractSpan createExitSpan(String operationName, String remotePeer) {
+ operationName = StringUtil.cut(operationName, OPERATION_NAME_THRESHOLD);
AbstractTracerContext context = getOrCreate(operationName, false);
AbstractSpan span = context.createExitSpan(operationName, remotePeer);
return span;
diff --git a/apm-sniffer/config/agent.config b/apm-sniffer/config/agent.config
index 3041be1..3507ede 100644
--- a/apm-sniffer/config/agent.config
+++ b/apm-sniffer/config/agent.config
@@ -38,6 +38,9 @@ agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}
# Skywalking team may ask for these files in order to resolve compatible problem.
# agent.is_open_debugging_class = ${SW_AGENT_OPEN_DEBUG:true}
+# The operationName max length
+# agent.operation_name_threshold=${SW_AGENT_OPERATION_NAME_THRESHOLD:500}
+
# Backend service addresses.
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:127.0.0.1:11800}
diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md
index e6d48dd..26e4c79 100755
--- a/docs/en/setup/service-agent/java-agent/README.md
+++ b/docs/en/setup/service-agent/java-agent/README.md
@@ -77,6 +77,7 @@ property key | Description | Default |
`agent.active_v1_header `|Deactivate V1 header in default.|`false`|
`agent.cool_down_threshold `|How long should the agent wait (in minute) before re-registering to the OAP server after receiving reset command.|`10`|
`agent.force_reconnection_period `|Force reconnection period of grpc, based on grpc_channel_check_interval.|`1`|
+`agent.operation_name_threshold `|The operationName max length, setting this value > 500 is not recommended.|`500`|
`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`|
`collector.backend_service`|Collector SkyWalking trace receiver service addresses.|`127.0.0.1:11800`|