Skip to content

feat(storage)!: remove CacheMeterProvider; use otelcache.RegisterCache#94

Merged
achille-roussel merged 1 commit into
metrics-readerfrom
remove-cache-meter-provider
May 19, 2026
Merged

feat(storage)!: remove CacheMeterProvider; use otelcache.RegisterCache#94
achille-roussel merged 1 commit into
metrics-readerfrom
remove-cache-meter-provider

Conversation

@achille-roussel

Copy link
Copy Markdown
Contributor

Stacked on #93. Once that merges, rebase this onto main.

Summary

  • Remove storage.CacheMeterProvider option, the metricsRegistration field on Cache, and the OTel metric import from storage/cache.go. The storage package no longer depends on go.opentelemetry.io/otel/metric.
  • Delete storage/cache_metrics.go (148 lines) — replaced by a single helper in otelcache.
  • Add otelcache.RegisterCache(provider, *storage.Cache, attrs...) that wires all three sub-caches (objects/infos/pages) under one callback. The callback snapshots cache.Stat() once per collection so the three kinds always report a coherent view.
  • Refactor otelcache.Register to share instrument creation with RegisterCache via internal newInstruments / instruments.observe helpers.

Why

PR #93 introduced otelcache to decouple storage/file.Cache from OTel. This finishes the same decoupling for the in-memory storage.Cache.

Breaking change

storage.CacheMeterProvider is removed.

// before
cache := storage.NewCache(storage.CacheMeterProvider(provider))

// after
cache := storage.NewCache()
reg, _ := otelcache.RegisterCache(provider, cache)
defer reg.Unregister()

Metric names, units, descriptions, and the storage.cache.kind attribute are unchanged, so existing dashboards keep working. The storage.cache.id attribute that the old option auto-derived from the cache pointer must now be supplied by the caller (or omitted).

Test plan

  • go test ./storage/...
  • go vet ./...
  • Confirm storage no longer imports otel/metric: go list -f '{{ join .Imports "\n" }}' ./storage | grep otel/metric returns empty.
  • Migrated metric assertions from the deleted cache_metrics_test.go to storage/otelcache/cache_test.go — same 18 (kind, metric) combinations verified.

🤖 Generated with Claude Code

BREAKING CHANGE: storage.CacheMeterProvider is removed. Wire OpenTelemetry
metrics via the new otelcache.RegisterCache helper instead, which mirrors
the file.Cache pattern and keeps the storage package free of OTel imports.

Before:
    cache := storage.NewCache(storage.CacheMeterProvider(provider))

After:
    cache := storage.NewCache()
    reg, _ := otelcache.RegisterCache(provider, cache)
    defer reg.Unregister()

RegisterCache reports all three sub-caches (objects, infos, pages) under
a single callback. The callback snapshots cache.Stat() once per
collection so the three kinds always reflect a coherent view.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@achille-roussel achille-roussel merged commit f25e576 into metrics-reader May 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant