6
6
package io .opentelemetry .contrib .sampler .consistent56 ;
7
7
8
8
import static io .opentelemetry .contrib .sampler .consistent56 .ConsistentSamplingUtil .calculateSamplingProbability ;
9
+ import static io .opentelemetry .contrib .sampler .consistent56 .ConsistentSamplingUtil .calculateThreshold ;
9
10
import static io .opentelemetry .contrib .sampler .consistent56 .ConsistentSamplingUtil .checkThreshold ;
10
11
import static io .opentelemetry .contrib .sampler .consistent56 .ConsistentSamplingUtil .getInvalidThreshold ;
11
12
import static io .opentelemetry .contrib .sampler .consistent56 .ConsistentSamplingUtil .getMaxThreshold ;
@@ -22,9 +23,20 @@ public class ConsistentFixedThresholdSampler extends ConsistentSampler {
22
23
private final String description ;
23
24
24
25
protected ConsistentFixedThresholdSampler (long threshold ) {
26
+ this .threshold = getThreshold (threshold );
27
+ this .description = getThresholdDescription (threshold );
28
+ }
29
+
30
+ protected ConsistentFixedThresholdSampler (double samplingProbability ) {
31
+ this (calculateThreshold (samplingProbability ));
32
+ }
33
+
34
+ private static long getThreshold (long threshold ) {
25
35
checkThreshold (threshold );
26
- this .threshold = threshold ;
36
+ return threshold ;
37
+ }
27
38
39
+ private static String getThresholdDescription (long threshold ) {
28
40
String thresholdString ;
29
41
if (threshold == getMaxThreshold ()) {
30
42
thresholdString = "max" ;
@@ -35,12 +47,11 @@ protected ConsistentFixedThresholdSampler(long threshold) {
35
47
.toString ();
36
48
}
37
49
38
- this .description =
39
- "ConsistentFixedThresholdSampler{threshold="
40
- + thresholdString
41
- + ", sampling probability="
42
- + calculateSamplingProbability (threshold )
43
- + "}" ;
50
+ return "ConsistentFixedThresholdSampler{threshold="
51
+ + thresholdString
52
+ + ", sampling probability="
53
+ + calculateSamplingProbability (threshold )
54
+ + "}" ;
44
55
}
45
56
46
57
@ Override
0 commit comments