From b95c66dedbd525a1b3d0f6b851d4fd351887fa23 Mon Sep 17 00:00:00 2001 From: Jay Yu <103467857+jayy04@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:09:36 -0400 Subject: [PATCH] comments --- store/iavl/store.go | 2 +- telemetry/metrics.go | 8 ++++---- telemetry/wrapper.go | 21 --------------------- 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/store/iavl/store.go b/store/iavl/store.go index e7fc71983dc7..77f611380535 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -202,7 +202,7 @@ func (st *Store) Set(key, value []byte) { // Implements types.KVStore. func (st *Store) Get(key []byte) []byte { - defer telemetry.MeasureSinceWithSampling(time.Now(), 0.01, "store", "iavl", "get") + defer telemetry.MeasureSince(time.Now(), "store", "iavl", "get") value, err := st.tree.Get(key) if err != nil { panic(err) diff --git a/telemetry/metrics.go b/telemetry/metrics.go index c27dd5c5aed3..40914ccdb494 100644 --- a/telemetry/metrics.go +++ b/telemetry/metrics.go @@ -98,7 +98,7 @@ func New(cfg Config) (_ *Metrics, rerr error) { }() m := &Metrics{memSink: memSink} - fanout := metrics.FanoutSink{} + var sink metrics.MetricSink if cfg.PrometheusRetentionTime > 0 { m.prometheusEnabled = true @@ -111,12 +111,12 @@ func New(cfg Config) (_ *Metrics, rerr error) { return nil, err } - fanout = append(fanout, promSink) + sink = promSink } else { - fanout = append(fanout, memSink) + sink = memSink } - if _, err := metrics.NewGlobal(metricsConf, fanout); err != nil { + if _, err := metrics.NewGlobal(metricsConf, sink); err != nil { return nil, err } diff --git a/telemetry/wrapper.go b/telemetry/wrapper.go index 7a429b7ee93c..fa6aae10221a 100644 --- a/telemetry/wrapper.go +++ b/telemetry/wrapper.go @@ -1,7 +1,6 @@ package telemetry import ( - "math/rand" "time" "github.com/armon/go-metrics" @@ -20,18 +19,6 @@ func NewLabel(name, value string) metrics.Label { return metrics.Label{Name: name, Value: value} } -// ModuleMeasureSinceWithSampling samples latency metrics given the sample rate. -// This is intended to be used in hot code paths. -func ModuleMeasureSinceWithSampling(module string, start time.Time, sampleRate float64, keys ...string) { - if rand.Float64() < sampleRate { - metrics.MeasureSinceWithLabels( - keys, - start.UTC(), - append([]metrics.Label{NewLabel(MetricLabelNameModule, module)}, globalLabels...), - ) - } -} - // ModuleMeasureSince provides a short hand method for emitting a time measure // metric for a module with a given set of keys. If any global labels are defined, // they will be added to the module label. @@ -83,11 +70,3 @@ func SetGaugeWithLabels(keys []string, val float32, labels []metrics.Label) { func MeasureSince(start time.Time, keys ...string) { metrics.MeasureSinceWithLabels(keys, start.UTC(), globalLabels) } - -// MeasureSinceWithSampling provides a wrapper functionality for emitting a a time measure -// metric with sampling. -func MeasureSinceWithSampling(start time.Time, sampleRate float64, keys ...string) { - if rand.Float64() < sampleRate { - metrics.MeasureSinceWithLabels(keys, start.UTC(), globalLabels) - } -}