wu-sheng commented on a change in pull request #7554:
URL: https://github.com/apache/skywalking/pull/7554#discussion_r697881970
##########
File path:
oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/TraceSegmentSampler.java
##########
@@ -18,20 +18,41 @@
package
org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener;
-import
org.apache.skywalking.oap.server.analyzer.provider.trace.TraceSampleRateWatcher;
+import org.apache.skywalking.apm.network.language.agent.v3.SegmentObject;
+import
org.apache.skywalking.oap.server.analyzer.provider.trace.TraceSamplingPolicyWatcher;
/**
* The sampler makes the sampling mechanism works at backend side. Sample
result: [0,sampleRate) sampled, (sampleRate,~)
* ignored
*/
public class TraceSegmentSampler {
- private TraceSampleRateWatcher traceSampleRateWatcher;
+ private TraceSamplingPolicyWatcher traceSamplingPolicyWatcher;
- public TraceSegmentSampler(TraceSampleRateWatcher traceSampleRateWatcher) {
- this.traceSampleRateWatcher = traceSampleRateWatcher;
+ public TraceSegmentSampler(TraceSamplingPolicyWatcher
traceSamplingPolicyWatcher) {
+ this.traceSamplingPolicyWatcher = traceSamplingPolicyWatcher;
}
- public boolean shouldSample(String traceId) {
- return Math.abs(traceId.hashCode()) % 10000 <
traceSampleRateWatcher.getSampleRate();
+ public boolean shouldSample(SegmentObject segmentObject, int duration) {
+ int sample = Math.abs(segmentObject.getTraceId().hashCode()) % 10000;
+ String serviceName = segmentObject.getService();
+ TraceSamplingPolicyWatcher.SamplePolicy sampleConfig =
traceSamplingPolicyWatcher.getSamplePolicy(serviceName);
+ if (sampleConfig != null) {
+ if (shouldSampleService(sampleConfig, sample, duration)) {
+ return true;
+ }
+ }
+ return sample < traceSamplingPolicyWatcher.getSampleRate();
Review comment:
L39 check and L44 should not exist. You already have fail safe mechanism
in the watcher. This is a duplicate mechanism. Also, at the same time,
`traceSamplingPolicyWatcher#getSampleRate` is not needed.
--
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]