Fix KafkaContextManagerExtendService boot error of kafka plugin. (#6410)
This commit is contained in:
parent
3d2fba3c40
commit
430a85df07
|
|
@ -12,6 +12,7 @@ Release Notes.
|
|||
* Remove invalid mysql configuration in agent.config.
|
||||
* Add net.bytebuddy.agent.builder.AgentBuilder.RedefinitionStrategy.Listener to show detail message when redefine errors occur.
|
||||
* Fix ClassCastException of log4j gRPC reporter.
|
||||
* Fix NPE when Kafka reporter activated.
|
||||
|
||||
#### OAP-Backend
|
||||
* Allow user-defined `JAVA_OPTS` in the startup script.
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.skywalking.apm.agent.core.context;
|
||||
|
||||
import java.util.Arrays;
|
||||
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;
|
||||
|
|
@ -29,13 +30,11 @@ 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 volatile String[] ignoreSuffixArray = new String[0];
|
||||
|
||||
|
||||
private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT;
|
||||
|
||||
private IgnoreSuffixPatternsWatcher ignoreSuffixPatternsWatcher;
|
||||
|
|
@ -43,14 +42,14 @@ public class ContextManagerExtendService implements BootService, GRPCChannelList
|
|||
@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(",");
|
||||
ignoreSuffixPatternsWatcher = new IgnoreSuffixPatternsWatcher("agent.ignore_suffix", this);
|
||||
ServiceManager.INSTANCE.findService(ConfigurationDiscoveryService.class)
|
||||
.registerAgentConfigChangeWatcher(ignoreSuffixPatternsWatcher);
|
||||
.registerAgentConfigChangeWatcher(ignoreSuffixPatternsWatcher);
|
||||
handleIgnoreSuffixPatternsChanged();
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +73,8 @@ public class ContextManagerExtendService implements BootService, GRPCChannelList
|
|||
}
|
||||
|
||||
int suffixIdx = operationName.lastIndexOf(".");
|
||||
if (suffixIdx > -1 && Arrays.stream(ignoreSuffixArray).anyMatch(a -> a.equals(operationName.substring(suffixIdx)))) {
|
||||
if (suffixIdx > -1 && Arrays.stream(ignoreSuffixArray)
|
||||
.anyMatch(a -> a.equals(operationName.substring(suffixIdx)))) {
|
||||
context = new IgnoredTracerContext();
|
||||
} else {
|
||||
SamplingService samplingService = ServiceManager.INSTANCE.findService(SamplingService.class);
|
||||
|
|
|
|||
|
|
@ -53,11 +53,11 @@ public class SamplingService implements BootService {
|
|||
|
||||
@Override
|
||||
public void prepare() {
|
||||
samplingRateWatcher = new SamplingRateWatcher("agent.sample_n_per_3_secs", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void boot() {
|
||||
samplingRateWatcher = new SamplingRateWatcher("agent.sample_n_per_3_secs", this);
|
||||
ServiceManager.INSTANCE.findService(ConfigurationDiscoveryService.class)
|
||||
.registerAgentConfigChangeWatcher(samplingRateWatcher);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@
|
|||
|
||||
package org.apache.skywalking.apm.agent.core.context;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.apache.skywalking.apm.agent.core.conf.dynamic.AgentConfigChangeWatcher;
|
||||
import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
|
@ -31,20 +33,25 @@ public class IgnoreSuffixPatternsWatcherTest {
|
|||
@Rule
|
||||
public AgentServiceRule agentServiceRule = new AgentServiceRule();
|
||||
|
||||
private ContextManagerExtendService contextManagerExtendService = new ContextManagerExtendService();
|
||||
private ContextManagerExtendService contextManagerExtendService;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
contextManagerExtendService.prepare();
|
||||
contextManagerExtendService = ServiceManager.INSTANCE.findService(ContextManagerExtendService.class);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
ServiceManager.INSTANCE.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigModifyEvent() {
|
||||
IgnoreSuffixPatternsWatcher ignoreSuffixPatternsWatcher = Whitebox.getInternalState(contextManagerExtendService
|
||||
, "ignoreSuffixPatternsWatcher");
|
||||
, "ignoreSuffixPatternsWatcher");
|
||||
ignoreSuffixPatternsWatcher.notify(new AgentConfigChangeWatcher.ConfigChangeEvent(
|
||||
".txt,.log",
|
||||
AgentConfigChangeWatcher.EventType.MODIFY
|
||||
".txt,.log",
|
||||
AgentConfigChangeWatcher.EventType.MODIFY
|
||||
));
|
||||
Assert.assertEquals(".txt,.log", ignoreSuffixPatternsWatcher.getIgnoreSuffixPatterns());
|
||||
Assert.assertEquals("agent.ignore_suffix", ignoreSuffixPatternsWatcher.getPropertyKey());
|
||||
|
|
@ -53,10 +60,10 @@ public class IgnoreSuffixPatternsWatcherTest {
|
|||
@Test
|
||||
public void testConfigDeleteEvent() {
|
||||
IgnoreSuffixPatternsWatcher ignoreSuffixPatternsWatcher = Whitebox.getInternalState(contextManagerExtendService
|
||||
, "ignoreSuffixPatternsWatcher");
|
||||
, "ignoreSuffixPatternsWatcher");
|
||||
ignoreSuffixPatternsWatcher.notify(new AgentConfigChangeWatcher.ConfigChangeEvent(
|
||||
null,
|
||||
AgentConfigChangeWatcher.EventType.DELETE
|
||||
null,
|
||||
AgentConfigChangeWatcher.EventType.DELETE
|
||||
));
|
||||
Assert.assertEquals("agent.ignore_suffix", ignoreSuffixPatternsWatcher.getPropertyKey());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,18 +18,31 @@
|
|||
|
||||
package org.apache.skywalking.apm.agent.core.sampling;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.apache.skywalking.apm.agent.core.conf.dynamic.AgentConfigChangeWatcher;
|
||||
import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
public class SamplingRateWatcherTest {
|
||||
private SamplingService samplingService = new SamplingService();
|
||||
|
||||
@Rule
|
||||
public AgentServiceRule agentServiceRule = new AgentServiceRule();
|
||||
|
||||
private SamplingService samplingService;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
samplingService.prepare();
|
||||
samplingService = ServiceManager.INSTANCE.findService(SamplingService.class);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
ServiceManager.INSTANCE.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ public class TraceIgnoreExtendService extends SamplingService {
|
|||
@Override
|
||||
public void prepare() {
|
||||
super.prepare();
|
||||
traceIgnorePatternWatcher = new TraceIgnorePatternWatcher("agent.trace.ignore_path", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -53,6 +52,7 @@ public class TraceIgnoreExtendService extends SamplingService {
|
|||
patterns = IgnoreConfig.Trace.IGNORE_PATH.split(PATTERN_SEPARATOR);
|
||||
}
|
||||
|
||||
traceIgnorePatternWatcher = new TraceIgnorePatternWatcher("agent.trace.ignore_path", this);
|
||||
ServiceManager.INSTANCE.findService(ConfigurationDiscoveryService.class)
|
||||
.registerAgentConfigChangeWatcher(traceIgnorePatternWatcher);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,18 +18,27 @@
|
|||
|
||||
package org.apache.skywalking.apm.plugin.trace.ignore;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.apache.skywalking.apm.agent.core.conf.dynamic.AgentConfigChangeWatcher;
|
||||
import org.apache.skywalking.apm.agent.core.sampling.SamplingService;
|
||||
import org.apache.skywalking.apm.agent.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 TraceIgnorePatternWatcherTest {
|
||||
private TraceIgnoreExtendService traceIgnoreExtendService = new TraceIgnoreExtendService();
|
||||
|
||||
@Rule
|
||||
public AgentServiceRule agentServiceRule = new AgentServiceRule();
|
||||
|
||||
private TraceIgnoreExtendService traceIgnoreExtendService;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
traceIgnoreExtendService.prepare();
|
||||
traceIgnoreExtendService =
|
||||
(TraceIgnoreExtendService) ServiceManager.INSTANCE.findService(SamplingService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue