chore(metrics): create storage query series at startup (#1595 stack: 3/4)

What this delivers

This MR is part 3 of 4 of the split of !3348 (merged). A new instance now exports the named-query series of every internal/storage catalog name at 0 before any query runs. With part 2, every catalog query name has its series at startup.

Fix. storage.QueryNames() lists every query constant in internal/storage/queries.go. registerServiceMetrics now seeds slices.Concat(datastore.QueryNames(), storage.QueryNames()).

Specific behavior:

  • TestQueryNames_ListsEveryDeclaredConstant parses queries.go and takes every string constant in it, so it fails when a new constant is missing from QueryNames().
  • TestInstrumentQuery_CoversS06NameSet ranges over QueryNames(). The s06QueryNames fixture, which repeated the same 13 names with nothing to keep the two lists equal, is removed.
  • catalogQueryNames in cmd/artifact-registry/main_test.go returns the names of both catalogs, and fails when a name repeats across the two catalogs or in one catalog. InitQuery accepts a repeated name, and one series would then mean two statements.
  • upload_sessions_commit_tx is a deferred-timer name, so its outcome series now stay at 0 permanently, like the internal/datastore deferred-timer names. docs/dev/database-query-patterns.md and docs/dev/observability.md now describe every catalog name the same way.
  • The labelName budget comment in internal/metrics/cardinality.go now says that startup seeds every catalog name, so the cardinality tests fail when the catalogs pass the budget. The budget value stays at 700. The storage comment lower in the file no longer gives a count of storage query names.

The stack

Part MR Scope
1 !3353 (merged) HTTP server series
2 !3354 (merged) Datastore query series
3 This MR Storage query series
4 !3348 (merged) Job series

Depends on !3354 (merged), which adds metrics.InitQuery and the seed loop that this MR extends. Merge the parts in order. When all four parts merge, the tree is the !3348 (merged) head before the split, 9f5b5285608815c320547be1552405c410687eb9, plus the review fixes that each part carries.

Merge order with other open MRs. !2944 (closed) edits internal/storage/queries.go, internal/storage/queries_test.go and the labelName comment in internal/metrics/cardinality.go. If an MR adds a constant to internal/storage/queries.go, the MR that merges second adds the constant to QueryNames(). If it does not, TestQueryNames_ListsEveryDeclaredConstant fails. This MR removes the s06QueryNames fixture, so when !2944 (closed) rebases, it drops its hunks that rename that fixture, its test and its comment.

Spec coverage

Source: the issue card acceptance list.

# Criterion Tests
AC-3 Query names come from the two catalogs; a test fails when a constant is missing from the exported list TestQueryNames_ListsEveryDeclaredConstant, TestWiring_SeedsHTTPAndQuerySeriesWithNoTraffic
AC-7 The query series are on /-/metrics of a fresh instance with no traffic TestWiring_MetricsEndpointServesSeededSeriesWithNoTraffic
AC-8 AuditCardinality passes with the seeded series present TestWiring_CardinalityAuditPasses, TestIntegration_SeedsMountedRoutesAtStartup

The issue card lists no error case and no security consideration.

E2E scenario catalog

No scenario is added or affected. The row e2e.management.observability.metric-families-registered asserts a subset of families, and a new series breaks nothing.

No customer-visible surface changes, so docs/user/ is not affected.

🤖 Generated with Claude Code

Related to #1595 (closed)

Edited by Pawel Rozlach

Merge request reports

Loading
Loading