{"record":{"id":"f1f2ff332509994e","repo":"apache/shenyu","slug":"probability-should-be-between-0-01-and-1-was-probability","errorCode":null,"errorMessage":"probability should be between 0.01 and 1: was ${probability}","messagePattern":"probability should be between 0\\.01 and 1: was (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/sampler/CountSampler.java","lineNumber":112,"sourceCode":"    /**\n     * create a sampler instance.\n     *\n     * @param probability probability\n     * @return sampler instance\n     */\n    public static Sampler create(final String probability) {\n        if (StringUtils.isBlank(probability)) {\n            return ALWAYS_SAMPLE;\n        }\n        if (\"0\".equals(probability)) {\n            return NEVER_SAMPLE;\n        }\n        if (\"1\".equals(probability) || \"1.0\".equals(probability) || \"1.0.0\".equals(probability)) {\n            return ALWAYS_SAMPLE;\n        }\n        float parseProbability = NumberUtils.toFloat(probability, 1);\n        if (parseProbability < 0.01f || parseProbability > 1) {\n            throw new IllegalArgumentException(\n                    \"probability should be between 0.01 and 1: was \" + probability);\n        }\n        return new CountSampler(parseProbability);\n    }\n\n}\n","sourceCodeStart":94,"sourceCodeEnd":119,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/sampler/CountSampler.java#L94-L119","documentation":"CountSampler.create parses a sampling probability string used for trace/log sampling. Values below 0.01 or above 1 cannot produce a meaningful sampling ratio (0 means never sample; the API deliberately floors at 1%), so it throws IllegalArgumentException naming the offending value.","triggerScenarios":"Calling CountSampler.create with a numeric string that parses via NumberUtils.toFloat to a value < 0.01 or > 1 (e.g. \"0\", \"0.001\", \"2.0\"). Non-numeric strings fall back to 1 (always sample) and do NOT trigger this.","commonSituations":"Setting a sampling rate of 0 expecting 'never sample' (0 is rejected; use a rate at or above 0.01 or disable sampling another way); copy-pasting a percentage (50 for 50%); misconfigured plugin logging sampler config in the admin dashboard.","solutions":["Set the probability within [0.01, 1], e.g. 0.1 for 10% sampling.","If you wanted no sampling, disable the logging plugin or the sampler entirely instead of passing 0.","Convert percentages: 50% -> 0.5.","Special-case strings \"1\", \"1.0\", \"1.0.0\" are accepted as always-sample; use one of those for full sampling."],"exampleFix":"// before\nCountSampler.create(\"0\");\n// after\nCountSampler.create(\"0.01\"); // minimum accepted rate","handlingStrategy":"validation","validationCode":"boolean validSamplingProbability(String p) {\n    float v = NumberUtils.toFloat(p, 1);\n    return !(\"0\".equals(p)) && v >= 0.01f && v <= 1f;\n}","typeGuard":null,"tryCatchPattern":"try {\n    sampler = CountSampler.create(probability);\n} catch (IllegalArgumentException e) {\n    sampler = CountSampler.create(\"0.01\"); // safe minimum rate\n    log.warn(\"Invalid sampling probability '{}', falling back to 0.01\", probability);\n}","preventionTips":["Clamp configured sampling rates into [0.01, 1] at config-load time.","Remember 0 is rejected; use plugin disable for 'never sample'.","Convert percentages to fractions before storing config.","Validate sampler config when publishing from the admin dashboard."],"tags":["sampling","configuration","validation","argument"],"backgroundTag":"value-out-of-range","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}