fix (unified-storage): stop registering unified storage metrics in global state (#101322)

* move prometheus.register for unified storage metrics into metrics.go and do most of the plumbing to get it to work

* convert StorageApiMetrics to pointer and check for nil before using it

* rename type and variables to something more sensible

---------

Co-authored-by: Jean-Philippe Quéméner <jeanphilippe.quemener@grafana.com>
This commit is contained in:
Will Assis
2025-02-28 09:39:39 -03:00
committed by GitHub
parent 7fb0d1b3e6
commit f5e5824bab
15 changed files with 108 additions and 106 deletions

View File

@ -31,8 +31,9 @@ type pollingNotifier struct {
pollingInterval time.Duration
watchBufferSize int
log log.Logger
tracer trace.Tracer
log log.Logger
tracer trace.Tracer
storageMetrics *resource.StorageMetrics
bulkLock *bulkLock
listLatestRVs func(ctx context.Context) (groupResourceRV, error)
@ -46,8 +47,9 @@ type pollingNotifierConfig struct {
pollingInterval time.Duration
watchBufferSize int
log log.Logger
tracer trace.Tracer
log log.Logger
tracer trace.Tracer
storageMetrics *resource.StorageMetrics
bulkLock *bulkLock
listLatestRVs func(ctx context.Context) (groupResourceRV, error)
@ -101,6 +103,7 @@ func newPollingNotifier(cfg *pollingNotifierConfig) (*pollingNotifier, error) {
listLatestRVs: cfg.listLatestRVs,
historyPoll: cfg.historyPoll,
done: cfg.done,
storageMetrics: cfg.storageMetrics,
}, nil
}
@ -172,7 +175,9 @@ func (p *pollingNotifier) poll(ctx context.Context, grp string, res string, sinc
if err != nil {
return 0, fmt.Errorf("poll history: %w", err)
}
resource.NewStorageMetrics().PollerLatency.Observe(time.Since(start).Seconds())
if p.storageMetrics != nil {
p.storageMetrics.PollerLatency.Observe(time.Since(start).Seconds())
}
var nextRV int64
for _, rec := range records {