wu-sheng commented on a change in pull request #6232:
URL: https://github.com/apache/skywalking/pull/6232#discussion_r560787599
##########
File path:
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java
##########
@@ -43,34 +45,30 @@
public class SamplingService implements BootService {
private static final ILog LOGGER =
LogManager.getLogger(SamplingService.class);
- private volatile boolean on = false;
private volatile AtomicInteger samplingFactorHolder;
private volatile ScheduledFuture<?> scheduledFuture;
+ private SamplingRateWatcher samplingRateWatcher;
+
+ /**
+ * Avoid multiple registrations in test cases.
+ */
+ private boolean needRegisterAgentConfigChangeWatcher;
+
@Override
public void prepare() {
-
+ samplingRateWatcher = new
SamplingRateWatcher("agent.sample_n_per_3_secs", this);
}
@Override
public void boot() {
- if (scheduledFuture != null) {
- /*
- * If {@link #boot()} invokes twice, mostly in test cases,
- * cancel the old one.
- */
- scheduledFuture.cancel(true);
- }
- if (Config.Agent.SAMPLE_N_PER_3_SECS > 0) {
- on = true;
- this.resetSamplingFactor();
- ScheduledExecutorService service =
Executors.newSingleThreadScheduledExecutor(
- new DefaultNamedThreadFactory("SamplingService"));
- scheduledFuture = service.scheduleAtFixedRate(new
RunnableWithExceptionProtection(
- this::resetSamplingFactor, t -> LOGGER.error("unexpected
exception.", t)), 0, 3, TimeUnit.SECONDS);
- LOGGER.debug(
- "Agent sampling mechanism started. Sample {} traces in 3
seconds.", Config.Agent.SAMPLE_N_PER_3_SECS);
+ if (!needRegisterAgentConfigChangeWatcher) {
Review comment:
Test is not the reason to change the logic. If there is a bug in test,
fix them.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]