[SLO] Localize percent formatting; make SLO_PRECISION the single precision policy - #2836
Conversation
PR Reviewer Guide 🔍(Review updated until commit ef0e16b)Here are some key observations to aid the review process:
|
|
Persistent review updated to latest commit 72a23e7 |
PR Code Suggestions ✨Latest suggestions up to ef0e16b
Previous suggestionsSuggestions up to commit 72a23e7
|
Localize formatPct (CLAR10): use Intl.NumberFormat percent style keyed on i18n.getLocale() so the % sign, grouping, and decimal separator follow locale conventions, and default the empty-value fallback to a translatable glyph (EMPTY_VALUE_FALLBACK via i18n.translate). Preserves fixed-precision rounding and the existing en-locale output (e.g. 99.95%) plus the non-finite fallback. Document SLO_PRECISION as the single source of truth for SLO numeric precision (CLAR3), clarifying which render surface uses which key; call sites migrate separately. formatPct's default decimals=1 left unchanged to avoid altering existing callers. Refs: CLAR10, CLAR3 Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
The comment claimed the Intl.NumberFormat switch "keeps the previous fixed-precision rounding" — it doesn't. Intl uses half-expand rounding, which can differ in the last digit from the old toFixed at exact half-way inputs (e.g. 0.99985/2 → 99.99% vs 99.98%). The change is intentional and no caller parses the formatted string back to a number, so the comment now states the rounding-mode difference plainly instead of misrepresenting it. Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
72a23e7 to
3a530ba
Compare
|
Persistent review updated to latest commit 3a530ba |
Worth addressing
Nits
|
… test - Perf: formatPct is wired into ECharts axis/tooltip formatters that fire on every render/hover, and constructing an Intl.NumberFormat is far heavier than the old toFixed. Memoize the formatter per (locale, decimals) so it's built once and reused; keying on locale keeps a runtime setLocale correct (different key, not a stale formatter). - Test: the de-locale divergence assertions assumed full ICU. Detect real de support (comma decimal separator) and skip when a small-ICU build silently falls back to en, so the test can't fail for an ICU-availability reason unrelated to the code (CI's full-ICU Node 22 still exercises the real path). Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
|
Persistent review updated to latest commit ef0e16b |
…urfaces at SLO_PRECISION.budget The budget-remaining chart tooltip/axis/threshold label and the budget sparkline called formatPct() with no decimals (default 1), while the budget panel renders the same value at SLO_PRECISION.budget (2) — so 0.5 read '50.0%' in the chart but '50.00%' in the panel. Route all these budget-value formatPct calls through SLO_PRECISION.budget so every budget surface reads from the single precision policy. Tests updated for the 2-decimal output. Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
|
Thanks @TackAdam:
2 & 4. |
| * `100%` / `100.0%` / `100.00%` was the original offender. | ||
| * SLO numeric precision policy (audit P1 #12, CLAR3). THE single source of | ||
| * truth for how many decimal places each SLO surface renders — pass the | ||
| * relevant key as `formatPct`'s `decimals` so the same value reads identically |
There was a problem hiding this comment.
p2: the precision-policy doc tells callers to pass burnRate through formatPct, which misrenders
The added policy comment says to pass the relevant SLO_PRECISION key as formatPct's decimals, and lists burnRate (a 3.2x multiplier). But formatPct forces percent style and multiplies by 100, so formatPct(3.2, { decimals: SLO_PRECISION.burnRate }) renders 320.0% instead of 3.2x. Could we scope the 'pass to formatPct' instruction to the percent surfaces, and note that burnRate (and eventsRatio if ever shown as a raw ratio) is a precision-only key formatted elsewhere?
ps48
left a comment
There was a problem hiding this comment.
slo percent formatting review
Verified at head ef0e16b, scoped to common/slo/format.ts and its new test. formatPct moves to Intl.NumberFormat percent style with the raw ratio and pinned fraction digits (no double-multiply), EMPTY_VALUE_FALLBACK is an i18n-translatable glyph, and SLO_PRECISION is the single precision policy, all correctly kept in common/ where server and client share them. The per-locale:decimals formatter cache is a sensible bounded perf guard. Tests cover en defaults, fixed precision, the no-double-multiply invariant, grouping, non-finite fallback, and a real de-locale divergence. No new deps, routes, console, or dead code.
One small doc nit inline. No p0/p1.
What & why
Localizes the
%suffix and the—fallback and makesSLO_PRECISIONthe single source of precision. en-US output is unchanged for SLO value ranges (|value| < 10, i.e. percentages< 1000%, which covers all real SLO data); the change surfaces under non-en locales (localized grouping/decimal separators) and adds a grouping comma only for percentages≥ 1000%.Findings: CLAR10, CLAR3.
Before / after
Before / after (SLO listing; identical under en-US by design — see note)
Flow
Testing
format.test.tsincl. ade-locale assertion. Note: no visible change under en-US.Review
Independent review agent: APPROVE —
SLO_PRECISIONvalues byte-identical to main; i18n id unique.Regression check
The before/after above is a full-viewport capture, so adjacent components on the same surface are visible and unchanged — the diff is scoped to what's called out. Cross-component safety is also verified centrally: this change is file-disjoint from the other in-flight audit fixes (no file overlap, so it merges cleanly with them), and the affected plugin test suites pass with 0 new type errors vs
main. Aside from the merge-order note below, it can be reviewed, merged, and reverted independently.Dependency
No dependencies — can merge independently. Consumers migrate to
SLO_PRECISIONin #2830 and #2833.