Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metrics: expose pebble fsync latency as prometheus metric
Leverage the metric callback exposed in pebble to update the store’s histogram. However since the callbacks must be setup in `pebble.Open` but the metric to update is part of the `kvserver/metric.go`. We store the callbacks on the `pebble.onMetricEvent pebble.MetricEventListener` and craft a struct that wraps the callbacks with a `nil` check to ensure that they have been set inside of `kvserver/store.go` store start method:`Store.Start()`. This allows for deferring the setting of the callback handlers until we have access to the metrics to update. Diagram of the above description: ``` type Pebble struct { onMetricEvent struct { +---> SomeCallback func(duration time.Duration) <--------------+ | } | | } | | | Checks | func NewPebble(...) { | | ... | | cfg.Opts.MetricEventListener = pebble.MetricEventListener{ | | SomeCallback: func(duration time.Duration) { | S | if p.onMetricEvent.SomeCallback != nil { +-------------^ e | p.onMetricEvent.SomeCallback(duration) +-------------v t | } | s | }, | | } | | | | db, err := pebble.Open(cfg.StorageConfig.Dir, cfg.Opts) | | ... | Calls | } | | | | func (s *Store) Start(...) { | | ... | ^--- s.engine.RegisterMetricEventListener( | pebble.MetricEventListener{ | SomeCallback: func(duration time.Duration) { | s.metrics.FsyncLatency.RecordValue(duration)<--------v } }) ... } ``` Release note: None
- Loading branch information