wu-sheng commented on a change in pull request #7554: URL: https://github.com/apache/skywalking/pull/7554#discussion_r697882053
########## File path: oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/TraceSamplingPolicyWatcher.java ########## @@ -0,0 +1,217 @@ +/* + * 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.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +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.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 org.apache.skywalking.oap.server.library.util.yaml.ClassFilterConstructor; +import org.yaml.snakeyaml.Yaml; + +import java.io.Reader; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +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<SamplePolicySettings> samplePolicySettings = new AtomicReference<>(null); + private final AnalyzerModuleConfig moduleConfig; + + public TraceSamplingPolicyWatcher(AnalyzerModuleConfig moduleConfig, ModuleProvider provider) { + super(AnalyzerModule.NAME, provider, "traceSamplingPolicy"); + this.moduleConfig = moduleConfig; + loadDefaultPolicy(); + } + + @Override + public void notify(ConfigChangeEvent value) { + if (EventType.DELETE.equals(value.getEventType())) { + this.settingsString.set(""); + log.info("[trace-sampling-policy] Delete trace-sample-policy,use default config"); + loadDefaultPolicy(); + } else { + activeSetting(value.getNewValue()); + } + } + + @Override + public String value() { + return this.settingsString.get(); + } + + public SamplePolicy getSamplePolicy(String service) { + return this.samplePolicySettings.get().getPolicy(service); + } + + public int getSampleRate() { + return this.samplePolicySettings.get().global.rate; + } + + public int getSlowTraceSegmentThreshold() { Review comment: This is only used in the test, which is wrong. Only `#getSamplePolicy` should be used in runtime and UTs. -- 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]
