未验证 提交 fd02bcd6 编写于 作者: A Ax1an 提交者: GitHub

Support dynamic change agent.ignore_suffix on java agent. (#6272)

上级 c0ed7d88
......@@ -36,6 +36,7 @@ Release Notes.
* Fix RestTemplate plugin recording url tag with wrong port
* Support collecting logs and forwarding through gRPC.
* Support config `agent.sample_n_per_3_secs` can be changed in the runtime.
* Support config `agent.ignore_suffix` 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.
......
......@@ -62,6 +62,7 @@ public class Config {
/**
* If the operation name of the first span is included in this set, this segment should be ignored.
* Multiple values should be separated by `,`.
*/
public static String IGNORE_SUFFIX = ".jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg";
......
......@@ -22,28 +22,36 @@ import org.apache.skywalking.apm.agent.core.boot.BootService;
import org.apache.skywalking.apm.agent.core.boot.DefaultImplementor;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.conf.dynamic.ConfigurationDiscoveryService;
import org.apache.skywalking.apm.agent.core.remote.GRPCChannelListener;
import org.apache.skywalking.apm.agent.core.remote.GRPCChannelManager;
import org.apache.skywalking.apm.agent.core.remote.GRPCChannelStatus;
import org.apache.skywalking.apm.agent.core.sampling.SamplingService;
import org.apache.skywalking.apm.util.StringUtil;
import java.util.Arrays;
@DefaultImplementor
public class ContextManagerExtendService implements BootService, GRPCChannelListener {
private String[] ignoreSuffixArray = new String[0];
private volatile String[] ignoreSuffixArray = new String[0];
private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT;
private IgnoreSuffixPatternsWatcher ignoreSuffixPatternsWatcher;
@Override
public void prepare() {
ServiceManager.INSTANCE.findService(GRPCChannelManager.class).addChannelListener(this);
ignoreSuffixPatternsWatcher = new IgnoreSuffixPatternsWatcher("agent.ignore_suffix", this);
}
@Override
public void boot() {
ignoreSuffixArray = Config.Agent.IGNORE_SUFFIX.split(",");
ServiceManager.INSTANCE.findService(ConfigurationDiscoveryService.class)
.registerAgentConfigChangeWatcher(ignoreSuffixPatternsWatcher);
handleIgnoreSuffixPatternsChanged();
}
@Override
......@@ -84,4 +92,10 @@ public class ContextManagerExtendService implements BootService, GRPCChannelList
public void statusChanged(final GRPCChannelStatus status) {
this.status = status;
}
void handleIgnoreSuffixPatternsChanged() {
if (StringUtil.isNotBlank(ignoreSuffixPatternsWatcher.getIgnoreSuffixPatterns())) {
ignoreSuffixArray = ignoreSuffixPatternsWatcher.getIgnoreSuffixPatterns().split(",");
}
}
}
/*
* 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;
import org.apache.skywalking.apm.agent.core.conf.Config;
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 java.util.concurrent.atomic.AtomicReference;
public class IgnoreSuffixPatternsWatcher extends AgentConfigChangeWatcher {
private static final ILog LOGGER = LogManager.getLogger(IgnoreSuffixPatternsWatcher.class);
private final AtomicReference<String> ignoreSuffixPatterns;
private final ContextManagerExtendService contextManagerExtendService;
public IgnoreSuffixPatternsWatcher(final String propertyKey, ContextManagerExtendService contextManagerExtendService) {
super(propertyKey);
this.ignoreSuffixPatterns = new AtomicReference(getDefaultValue());
this.contextManagerExtendService = contextManagerExtendService;
}
private void activeSetting(String config) {
if (LOGGER.isDebugEnable()) {
LOGGER.debug("Updating using new static config: {}", config);
}
this.ignoreSuffixPatterns.set(config);
contextManagerExtendService.handleIgnoreSuffixPatternsChanged();
}
@Override
public void notify(final ConfigChangeEvent value) {
if (EventType.DELETE.equals(value.getEventType())) {
activeSetting(getDefaultValue());
} else {
activeSetting(value.getNewValue());
}
}
@Override
public String value() {
return ignoreSuffixPatterns.get();
}
private String getDefaultValue() {
return Config.Agent.IGNORE_SUFFIX;
}
public String getIgnoreSuffixPatterns() {
return ignoreSuffixPatterns.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.agent.core.context;
import org.apache.skywalking.apm.agent.core.conf.dynamic.AgentConfigChangeWatcher;
import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
public class IgnoreSuffixPatternsWatcherTest {
@Rule
public AgentServiceRule agentServiceRule = new AgentServiceRule();
private ContextManagerExtendService contextManagerExtendService = new ContextManagerExtendService();
@Before
public void setUp() {
contextManagerExtendService.prepare();
}
@Test
public void testConfigModifyEvent() {
IgnoreSuffixPatternsWatcher ignoreSuffixPatternsWatcher = Whitebox.getInternalState(contextManagerExtendService
, "ignoreSuffixPatternsWatcher");
ignoreSuffixPatternsWatcher.notify(new AgentConfigChangeWatcher.ConfigChangeEvent(
".txt,.log",
AgentConfigChangeWatcher.EventType.MODIFY
));
Assert.assertEquals(".txt,.log", ignoreSuffixPatternsWatcher.getIgnoreSuffixPatterns());
Assert.assertEquals("agent.ignore_suffix", ignoreSuffixPatternsWatcher.getPropertyKey());
}
@Test
public void testConfigDeleteEvent() {
IgnoreSuffixPatternsWatcher ignoreSuffixPatternsWatcher = Whitebox.getInternalState(contextManagerExtendService
, "ignoreSuffixPatternsWatcher");
ignoreSuffixPatternsWatcher.notify(new AgentConfigChangeWatcher.ConfigChangeEvent(
null,
AgentConfigChangeWatcher.EventType.DELETE
));
Assert.assertEquals("agent.ignore_suffix", ignoreSuffixPatternsWatcher.getPropertyKey());
}
}
......@@ -31,7 +31,7 @@ agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}
# Through this config item, SkyWalking keep your application memory cost estimated.
# agent.span_limit_per_segment=${SW_AGENT_SPAN_LIMIT:150}
# Ignore the segments if their operation names end with these suffix.
# If the operation name of the first span is included in this set, this segment should be ignored. Multiple values should be separated by `,`.
# agent.ignore_suffix=${SW_AGENT_IGNORE_SUFFIX:.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg}
# If true, SkyWalking agent will save all instrumented classes files in `/debugging` folder.
......
......@@ -35,7 +35,7 @@ public class TraceIgnoreExtendService extends SamplingService {
private static final ILog LOGGER = LogManager.getLogger(TraceIgnoreExtendService.class);
private static final String PATTERN_SEPARATOR = ",";
private TracePathMatcher pathMatcher = new FastPathMatcher();
private String[] patterns = new String[] {};
private volatile String[] patterns = new String[] {};
private TraceIgnorePatternWatcher traceIgnorePatternWatcher;
@Override
......
......@@ -25,6 +25,7 @@ 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` |
| agent.ignore_suffix | If the operation name of the first span is included in this set, this segment should be ignored. Multiple values should be separated by `,` | `.txt,.log` | - |
| 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.
先完成此消息的编辑!
想要评论请 注册