fix(scheduler): replace deprecated strings.Title with cases.Title#4783
fix(scheduler): replace deprecated strings.Title with cases.Title#4783mvanhorn wants to merge 4 commits intoarmadaproject:masterfrom
Conversation
Greptile SummaryThis PR replaces the deprecated
Confidence Score: 5/5Safe to merge — the fix is correct and complete, with only a trivial style nit remaining. The deprecated strings.Title() calls are correctly replaced at both call sites. The previous concurrency concern (package-level Caser) was addressed by inlining the calls. The only remaining finding is a cosmetic extra blank line (P2), which does not affect correctness. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Phase string from protobuf\n(e.g. 'JOB_RUN_STATE_RUNNING')"] --> B["strings.ToLower()\n→ 'job_run_state_running'"]
B --> C["cases.Title(language.English).String()\n→ 'Job_Run_State_Running'"]
C --> D["Used as Prometheus metric label\n(phase field in key struct)"]
Greploops — Automatically fix all review issues by running Reviews (5): Last reviewed commit: "Merge branch 'master' into fix/replace-d..." | Re-trigger Greptile |
Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
423a122 to
8039618
Compare
internal/scheduler/metrics.go
Outdated
| // titleCaser is a reusable, concurrency-safe caser for title-casing strings. | ||
| var titleCaser = cases.Title(language.English) |
There was a problem hiding this comment.
cases.Caser is not concurrency-safe — the comment is incorrect
The golang.org/x/text/cases package documentation explicitly states that a Caser "may be stateful and should therefore not be shared between goroutines." Only cases.Fold is documented as stateless; cases.Title, cases.Upper, and cases.Lower are all potentially stateful.
The comment here claims the opposite (concurrency-safe), which is incorrect. Because titleCaser is a package-level variable, any concurrent calls to titleCaser.String(...) — whether from multiple test goroutines or multiple MetricsCollector instances — constitute a data race.
The simplest safe fix is to remove the package-level variable entirely and call cases.Title(language.English).String(...) directly at each call site (lines 489 and 498). That removes any sharing concern altogether.
There was a problem hiding this comment.
Done in dd1a072. Removed the package-level titleCaser and inlined cases.Title(language.English).String() at both call sites.
cases.Caser is documented as potentially stateful and not safe for concurrent use. Remove the package-level titleCaser variable and call cases.Title(language.English).String() at each call site. Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Summary
Replace deprecated
strings.Title()(deprecated since Go 1.18) withcases.Title(language.English).String()fromgolang.org/x/textin the scheduler metrics code.Changes
titleCaservariable usingcases.Title(language.English)(safe for concurrent use)strings.Title()calls ininternal/scheduler/metrics.gogolang.org/x/text/casesandgolang.org/x/text/languageFixes #4776
This contribution was developed with AI assistance (Claude Code).