wu-sheng commented on a change in pull request #7554:
URL: https://github.com/apache/skywalking/pull/7554#discussion_r697982563



##########
File path: 
oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/TraceSamplingPolicyWatcher.java
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.oap.server.analyzer.provider.trace;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.apm.util.StringUtil;
+import org.apache.skywalking.oap.server.analyzer.module.AnalyzerModule;
+import org.apache.skywalking.oap.server.analyzer.provider.AnalyzerModuleConfig;
+import 
org.apache.skywalking.oap.server.analyzer.provider.trace.sampling.SamplingPolicy;
+import 
org.apache.skywalking.oap.server.analyzer.provider.trace.sampling.SamplingPolicySettings;
+import 
org.apache.skywalking.oap.server.analyzer.provider.trace.sampling.SamplingPolicySettingsReader;
+import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
+import org.apache.skywalking.oap.server.core.Const;
+import org.apache.skywalking.oap.server.library.module.ModuleProvider;
+import org.apache.skywalking.oap.server.library.util.ResourceUtils;
+
+import java.io.StringReader;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static java.util.Objects.isNull;
+
+@Slf4j
+public class TraceSamplingPolicyWatcher extends ConfigChangeWatcher {
+
+    private final AtomicReference<String> settingsString = new 
AtomicReference<>(Const.EMPTY_STRING);
+    private final AtomicReference<SamplingPolicySettings> 
samplingPolicySettings = new AtomicReference<>(null);
+    private final SamplingPolicySettings defaultSamplingPolicySettings;
+
+    public TraceSamplingPolicyWatcher(AnalyzerModuleConfig moduleConfig, 
ModuleProvider provider) {
+        super(AnalyzerModule.NAME, provider, "traceSamplingPolicy");
+        SamplingPolicySettings samplingPolicySettings = 
parseFromFile(moduleConfig.getTraceSamplingPolicySettingsFile());
+        this.defaultSamplingPolicySettings = samplingPolicySettings;
+        loadDefaultPolicySettings();
+    }
+
+    @Override
+    public void notify(ConfigChangeEvent value) {
+        if (EventType.DELETE.equals(value.getEventType()) || 
StringUtil.isBlank(value.getNewValue())) {
+            this.settingsString.set("");
+            log.info("[trace-sampling-policy] Delete trace-sampling-policy,use 
default config");
+            loadDefaultPolicySettings();
+        } else {
+            activeSetting(value.getNewValue());
+        }
+    }
+
+    @Override
+    public String value() {
+        return this.settingsString.get();
+    }
+
+    public boolean shouldSample(String service, int sample, int duration) {

Review comment:
       This method should have comments as it is a public method.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to