add basic metrics to the store package

This commit is contained in:
William Banfield
2022-11-28 12:49:12 -05:00
parent e2b96383ab
commit 31c88322fb
3 changed files with 54 additions and 0 deletions

32
store/metrics.gen.go Normal file
View File

@@ -0,0 +1,32 @@
// Code generated by metricsgen. DO NOT EDIT.
package store
import (
"github.com/go-kit/kit/metrics/discard"
prometheus "github.com/go-kit/kit/metrics/prometheus"
stdprometheus "github.com/prometheus/client_golang/prometheus"
)
func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
labels := []string{}
for i := 0; i < len(labelsAndValues); i += 2 {
labels = append(labels, labelsAndValues[i])
}
return &Metrics{
BlockStoreAccessDurationSeconds: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
Namespace: namespace,
Subsystem: MetricsSubsystem,
Name: "block_store_access_duration_seconds",
Help: "The duration of accesses to the state store labeled by which method was called on the store.",
Buckets: stdprometheus.ExponentialBuckets(0.01, 2, 5),
}, append(labels, "method")).With(labelsAndValues...),
}
}
func NopMetrics() *Metrics {
return &Metrics{
BlockStoreAccessDurationSeconds: discard.NewHistogram(),
}
}

20
store/metrics.go Normal file
View File

@@ -0,0 +1,20 @@
package store
import (
"github.com/go-kit/kit/metrics"
)
const (
// MetricsSubsystem is a subsystem shared by all metrics exposed by this
// package.
MetricsSubsystem = "store"
)
//go:generate go run ../scripts/metricsgen -struct=Metrics
// Metrics contains metrics exposed by this package.
type Metrics struct {
// The duration of accesses to the state store labeled by which method
// was called on the store.
BlockStoreAccessDurationSeconds metrics.Histogram `metrics_buckettype:"exp" metrics_bucketsizes:"0.01, 2, 5" metrics_labels:"method"`
}

View File

@@ -35,6 +35,8 @@ The store can be assumed to contain all contiguous blocks between base and heigh
type BlockStore struct {
db dbm.DB
metrics *Metrics
// mtx guards access to the struct fields listed below it. We rely on the database to enforce
// fine-grained concurrency control for its data, and thus this mutex does not apply to
// database contents. The only reason for keeping these fields in the struct is that the data