diff --git a/CHANGES.md b/CHANGES.md index 5972344f25ee094b850e6a568af0587e8bf63386..515d1ab932a8983627698fad23c57db700056372 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManagerExtendService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManagerExtendService.java index 9d718f4b5715b6e0e8f9d7211fd82a746b41fca7..f91d2c47ae82e53d78c1012f5fece05bf5a0cf88 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManagerExtendService.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManagerExtendService.java @@ -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); diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java index d8b598489db7e884e0a3fd0d4815029006f5432e..8ca63e97822f0abb7119fceafa6ae90abd674831 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java @@ -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); diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/IgnoreSuffixPatternsWatcherTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/IgnoreSuffixPatternsWatcherTest.java index 4e6cbc74f26afe859b864f483f4fd33ac50d0bab..a0b2edebae15b425602fba9527bfb2e2df7b6cbc 100644 --- a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/IgnoreSuffixPatternsWatcherTest.java +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/IgnoreSuffixPatternsWatcherTest.java @@ -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()); } diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/sampling/SamplingRateWatcherTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/sampling/SamplingRateWatcherTest.java index 3952b1cc50c2d419eb3dac6fd357722a28e429e6..cf5393f5519c679d41f1405caada6eeaf0763823 100644 --- a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/sampling/SamplingRateWatcherTest.java +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/sampling/SamplingRateWatcherTest.java @@ -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 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 eb872827cdd89aec6fa0c2948c24344cf75c47f4..5f4dc6afd14cf04da1be06181c343a18d4a1e62a 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 @@ -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); 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 index b37361ff55f366d8cf36a44c8f1e73d639a29cbc..ef97e510eede8d5d3894fb83365feea583b12121 100644 --- 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 @@ -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