diff --git a/CHANGES.md b/CHANGES.md index 0850f3470fb1645ce2380bb0f5af821df5701b60..178fe2e063b2cc115ecd1a5c1c7becd9240aecc1 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 baaac8bc41ac3b2a0b940f0195717cf6da8fadc1..22e74c8505b325ae441cafb243b88a3753178776 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 0000000000000000000000000000000000000000..d34f512871f3202315493764b2b55bad3136af0d --- /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 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 0000000000000000000000000000000000000000..b37361ff55f366d8cf36a44c8f1e73d639a29cbc --- /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 ffd6bc1f1ac321e214ec58e19642641985349889..cc61ecc1e5effd9682f53f06e9ef09086766b06b 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.