{"record":{"id":"955209bb2d0078d2","repo":"pinpoint-apm/pinpoint","slug":"invalid-samplingrate-955209","errorCode":null,"errorMessage":"Invalid samplingRate ","messagePattern":"Invalid samplingRate ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/sampler/PercentRateSampler.java","lineNumber":40,"sourceCode":"import java.util.concurrent.atomic.AtomicLong;\n\n/**\n * @author emeroad\n * @author yjqg6666\n */\npublic class PercentRateSampler implements Sampler {\n    // Supported range 100% ~ 0.01%\n    public static final long MULTIPLIER = 100;\n    public static final long MAX = 100 * MULTIPLIER;\n\n    private final AtomicLong counter = new AtomicLong(0);\n\n    private final long samplingRate;\n\n    public PercentRateSampler(long samplingRate) {\n        if (samplingRate <= 0 || samplingRate >= MAX) {\n            // Use TrueSampler for 100%\n            throw new IllegalArgumentException(\"Invalid samplingRate \" + samplingRate);\n        }\n        this.samplingRate = samplingRate;\n    }\n\n    @Override\n    public boolean isSampling() {\n        final long seed = counter.addAndGet(samplingRate);\n        final long remainder = MathUtils.floorMod(seed, MAX);\n        if (remainder > 0 && remainder <= samplingRate) {\n            return true;\n        }\n        return false;\n    }\n\n    @Override\n    public String toString() {\n        return \"PercentRateSampler{\" +\n                \"seedGen=\" + counter +","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/sampler/PercentRateSampler.java#L22-L58","documentation":"PercentRateSampler samples a percentage of requests expressed in per-mille-style units bounded by MAX; the constructor rejects samplingRate <= 0 or >= MAX because 100% should use TrueSampler directly. Passing an out-of-range percentage throws IllegalArgumentException.","triggerScenarios":"Constructing new PercentRateSampler(0), a negative value, or a value >= MAX (e.g. 100 when MAX is 100), typically from Profiler.sampling.rate.sampling_rate config set to 0 or 100.","commonSituations":"User configures 100 intending \"always sample\" (must use TrueSampler / sampling type 100% semantics instead), or sets 0 intending \"never\" — both rejected by this constructor.","solutions":["Set the percent rate to a value strictly between 0 and MAX (e.g. 1..99 for percent semantics)","Use TrueSampler (or the sampler factory's 100% path) when full sampling is desired","Use a non-sampling sampler when zero sampling is desired instead of 0"],"exampleFix":"// before\nsampler = new PercentRateSampler(100);\n// after\nsampler = Samplers.newSamplingRateSampler(SamplingType.PERCENT, 99); // or TrueSampler for 100%","handlingStrategy":"validation","validationCode":"long pct = Long.parseLong(props.getProperty(\"profiler.sampling.rate.sampling_rate\"));\nif (pct <= 0 || pct >= 100) throw new IllegalArgumentException(\"percent rate must be 1..99, got \" + pct);","typeGuard":"boolean isValidPercentRate(Long p) { return p != null && p > 0 && p < 100; }","tryCatchPattern":"try { sampler = new PercentRateSampler(pct); } catch (IllegalArgumentException e) { sampler = pct >= 100 ? new TrueSampler() : new FalseSampler(); }","preventionTips":["Use TrueSampler/TrueSamplingRate for 100% and non-sampling for 0% instead of edge values","Clamp config to 1..99 before constructing the sampler","Document percent-rate bounds where the config is edited"],"tags":["java","sampler","configuration"],"backgroundTag":"argument-out-of-range","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}