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 0884c87 Support dynamic change agent.trace.ignore_path on java agent
within CDS. (#6266)
0884c87 is described below
commit 0884c876fa2ec2575c0c7e6a2284ab2a95c38f2e
Author: Jared Tan <[email protected]>
AuthorDate: Thu Jan 28 12:09:59 2021 +0800
Support dynamic change agent.trace.ignore_path on java agent within CDS.
(#6266)
---
CHANGES.md | 1 +
.../trace/ignore/TraceIgnoreExtendService.java | 23 ++++++--
.../trace/ignore/TraceIgnorePatternWatcher.java | 69 ++++++++++++++++++++++
.../ignore/TraceIgnorePatternWatcherTest.java | 57 ++++++++++++++++++
.../java-agent/configuration-discovery.md | 1 +
5 files changed, 147 insertions(+), 4 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 0850f34..178fe2e 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -37,6 +37,7 @@ Release Notes.
* Support collecting logs and forwarding through gRPC.
* Support config `agent.sample_n_per_3_secs` can be changed in the runtime.
* Support DNS periodic resolving mechanism to update backend service.
+* Support config `agent.trace.ignore_path` can be changed in the runtime.
#### OAP-Backend
* Make meter receiver support MAL.
diff --git
a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnoreExtendService.java
b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnoreExtendService.java
index baaac8b..22e74c8 100644
---
a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnoreExtendService.java
+++
b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnoreExtendService.java
@@ -19,6 +19,8 @@
package org.apache.skywalking.apm.plugin.trace.ignore;
import org.apache.skywalking.apm.agent.core.boot.OverrideImplementor;
+import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
+import
org.apache.skywalking.apm.agent.core.conf.dynamic.ConfigurationDiscoveryService;
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import org.apache.skywalking.apm.agent.core.sampling.SamplingService;
@@ -34,6 +36,13 @@ public class TraceIgnoreExtendService extends
SamplingService {
private static final String PATTERN_SEPARATOR = ",";
private TracePathMatcher pathMatcher = new FastPathMatcher();
private String[] patterns = new String[] {};
+ private TraceIgnorePatternWatcher traceIgnorePatternWatcher;
+
+ @Override
+ public void prepare() {
+ super.prepare();
+ traceIgnorePatternWatcher = new
TraceIgnorePatternWatcher("agent.trace.ignore_path", this);
+ }
@Override
public void boot() {
@@ -43,11 +52,11 @@ public class TraceIgnoreExtendService extends
SamplingService {
if (StringUtil.isNotEmpty(IgnoreConfig.Trace.IGNORE_PATH)) {
patterns = IgnoreConfig.Trace.IGNORE_PATH.split(PATTERN_SEPARATOR);
}
- }
- @Override
- public void prepare() {
- super.prepare();
+
ServiceManager.INSTANCE.findService(ConfigurationDiscoveryService.class)
+
.registerAgentConfigChangeWatcher(traceIgnorePatternWatcher);
+
+ handleTraceIgnorePatternsChanged();
}
@Override
@@ -76,4 +85,10 @@ public class TraceIgnoreExtendService extends
SamplingService {
public void forceSampled() {
super.forceSampled();
}
+
+ void handleTraceIgnorePatternsChanged() {
+ if
(StringUtil.isNotBlank(traceIgnorePatternWatcher.getTraceIgnorePathPatterns()))
{
+ patterns =
traceIgnorePatternWatcher.getTraceIgnorePathPatterns().split(PATTERN_SEPARATOR);
+ }
+ }
}
diff --git
a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnorePatternWatcher.java
b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnorePatternWatcher.java
new file mode 100644
index 0000000..d34f512
--- /dev/null
+++
b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnorePatternWatcher.java
@@ -0,0 +1,69 @@
+/*
+ * 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.trace.ignore;
+
+import java.util.concurrent.atomic.AtomicReference;
+import
org.apache.skywalking.apm.agent.core.conf.dynamic.AgentConfigChangeWatcher;
+import org.apache.skywalking.apm.agent.core.logging.api.ILog;
+import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
+import org.apache.skywalking.apm.plugin.trace.ignore.conf.IgnoreConfig;
+
+public class TraceIgnorePatternWatcher extends AgentConfigChangeWatcher {
+ private static final ILog LOGGER =
LogManager.getLogger(TraceIgnorePatternWatcher.class);
+
+ private final AtomicReference<String> traceIgnorePathPatterns;
+ private final TraceIgnoreExtendService traceIgnoreExtendService;
+
+ public TraceIgnorePatternWatcher(final String propertyKey,
TraceIgnoreExtendService traceIgnoreExtendService) {
+ super(propertyKey);
+ this.traceIgnorePathPatterns = new AtomicReference(getDefaultValue());
+ this.traceIgnoreExtendService = traceIgnoreExtendService;
+ }
+
+ private void activeSetting(String config) {
+ if (LOGGER.isDebugEnable()) {
+ LOGGER.debug("Updating using new static config: {}", config);
+ }
+
+ this.traceIgnorePathPatterns.set(config);
+ traceIgnoreExtendService.handleTraceIgnorePatternsChanged();
+ }
+
+ @Override
+ public void notify(final ConfigChangeEvent value) {
+ if (EventType.DELETE.equals(value.getEventType())) {
+ activeSetting(getDefaultValue());
+ } else {
+ activeSetting(value.getNewValue());
+ }
+ }
+
+ @Override
+ public String value() {
+ return traceIgnorePathPatterns.get();
+ }
+
+ private String getDefaultValue() {
+ return IgnoreConfig.Trace.IGNORE_PATH;
+ }
+
+ public String getTraceIgnorePathPatterns() {
+ return traceIgnorePathPatterns.get();
+ }
+}
diff --git
a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnorePatternWatcherTest.java
b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnorePatternWatcherTest.java
new file mode 100644
index 0000000..b37361f
--- /dev/null
+++
b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnorePatternWatcherTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.trace.ignore;
+
+import
org.apache.skywalking.apm.agent.core.conf.dynamic.AgentConfigChangeWatcher;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.powermock.reflect.Whitebox;
+
+public class TraceIgnorePatternWatcherTest {
+ private TraceIgnoreExtendService traceIgnoreExtendService = new
TraceIgnoreExtendService();
+
+ @Before
+ public void setUp() {
+ traceIgnoreExtendService.prepare();
+ }
+
+ @Test
+ public void testConfigModifyEvent() {
+ TraceIgnorePatternWatcher traceIgnorePatternWatcher =
Whitebox.getInternalState(traceIgnoreExtendService
+ , "traceIgnorePatternWatcher");
+ traceIgnorePatternWatcher.notify(new
AgentConfigChangeWatcher.ConfigChangeEvent(
+ "/eureka/apps/**",
+ AgentConfigChangeWatcher.EventType.MODIFY
+ ));
+ Assert.assertEquals("/eureka/apps/**",
traceIgnorePatternWatcher.getTraceIgnorePathPatterns());
+ Assert.assertEquals("agent.trace.ignore_path",
traceIgnorePatternWatcher.getPropertyKey());
+ }
+
+ @Test
+ public void testConfigDeleteEvent() {
+ TraceIgnorePatternWatcher traceIgnorePatternWatcher =
Whitebox.getInternalState(traceIgnoreExtendService
+ , "traceIgnorePatternWatcher");
+ traceIgnorePatternWatcher.notify(new
AgentConfigChangeWatcher.ConfigChangeEvent(
+ null,
+ AgentConfigChangeWatcher.EventType.DELETE
+ ));
+ Assert.assertEquals("agent.trace.ignore_path",
traceIgnorePatternWatcher.getPropertyKey());
+ }
+}
diff --git a/docs/en/setup/service-agent/java-agent/configuration-discovery.md
b/docs/en/setup/service-agent/java-agent/configuration-discovery.md
index ffd6bc1..cc61ecc 100644
--- a/docs/en/setup/service-agent/java-agent/configuration-discovery.md
+++ b/docs/en/setup/service-agent/java-agent/configuration-discovery.md
@@ -25,5 +25,6 @@ Java agent supports the following dynamic configurations.
| Config Key | Value Description
| Value Format Example | Required Plugin(s) |
| :-----------------------: |
:----------------------------------------------------------: |
:-------------------: | :----------------: |
| agent.sample_n_per_3_secs | The number of sampled traces per 3
seconds | -1 | - |
+| agent.trace.ignore_path | The value is the path that you need to
ignore, multiple paths should be separated by `,` [more
details](./agent-optional-plugins/trace-ignore-plugin.md) |
`/your/path/1/**,/your/path/2/**` | `apm-trace-ignore-plugin` |
* `Required plugin(s)`, the configuration affects only when the required
plugins activated.