wu-sheng commented on a change in pull request #7554:
URL: https://github.com/apache/skywalking/pull/7554#discussion_r697882352
##########
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();
+ }
+
+ private boolean
shouldSampleService(TraceSamplingPolicyWatcher.SamplePolicy sampleConfig, int
sample, int duration) {
Review comment:
This method is out of scope. It belongs to `SamplePolicySettings`.
--
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]