diff --git a/store/metrics.gen.go b/store/metrics.gen.go new file mode 100644 index 000000000..68f41bcfc --- /dev/null +++ b/store/metrics.gen.go @@ -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(), + } +} diff --git a/store/metrics.go b/store/metrics.go new file mode 100644 index 000000000..f9a089bd9 --- /dev/null +++ b/store/metrics.go @@ -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"` +} diff --git a/store/store.go b/store/store.go index c56622e47..f0e2e37a2 100644 --- a/store/store.go +++ b/store/store.go @@ -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