未验证 提交 0884c876 编写于 作者: J Jared Tan 提交者: GitHub

Support dynamic change agent.trace.ignore_path on java agent within CDS. (#6266)

上级 3cf31455
......@@ -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.
......
......@@ -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);
}
}
}
/*
* 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();
}
}
/*
* 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());
}
}
......@@ -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.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册