Commit 37891f1
authored
fix(sampling): format _dd.p.ksr to 6 decimal places, not 6 significant digits (#2086)
# What does this PR do?
The cross-tracer spec for _dd.p.ksr is "up to 6 decimal digits of precision, with trailing zeros stripped" — i.e. Go's `strconv.FormatFloat(rate, 'f', 6, 64)`. The previous implementation rounded to 6 *significant* digits ('g', 6, 64), which gave the right answer for every value in the original unit test but diverged for very small rates: 0.0000001 produced "0.0000001" instead of "0", and 0.00000051 produced "0.00000051" instead of "0.000001".
System-tests PR DataDog/system-tests#6466 added explicit cases for those two inputs (below_precision_rounds_to_zero, rounds_up_to_one_millionth), which started failing for dd-trace-rs once it bumped to a libdatadog containing this code (PR DataDog/dd-trace-rs#180, now living here after the sampling move-out refactor).
Replace the bespoke significant-digit rounding with a plain `{rate:.6}` format followed by trailing-zero strip; this gives the right rounding for free (including the "0" case, since "0.000000" trims down to "0").
Co-authored-by: igor.unanua <igor.unanua@datadoghq.com>1 parent d85861b commit 37891f1
1 file changed
Lines changed: 17 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | | - | |
| 190 | + | |
191 | 191 | | |
192 | | - | |
| 192 | + | |
| 193 | + | |
193 | 194 | | |
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
198 | 199 | | |
| 200 | + | |
| 201 | + | |
199 | 202 | | |
200 | 203 | | |
201 | 204 | | |
202 | 205 | | |
203 | 206 | | |
204 | 207 | | |
205 | 208 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
| 209 | + | |
| 210 | + | |
229 | 211 | | |
230 | 212 | | |
231 | 213 | | |
| |||
1178 | 1160 | | |
1179 | 1161 | | |
1180 | 1162 | | |
1181 | | - | |
| 1163 | + | |
1182 | 1164 | | |
1183 | 1165 | | |
1184 | 1166 | | |
| |||
1190 | 1172 | | |
1191 | 1173 | | |
1192 | 1174 | | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
1193 | 1184 | | |
1194 | 1185 | | |
1195 | 1186 | | |
| |||
0 commit comments