Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jayy04 committed Oct 11, 2023
1 parent 5402055 commit b95c66d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 26 deletions.
2 changes: 1 addition & 1 deletion store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions telemetry/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
21 changes: 0 additions & 21 deletions telemetry/wrapper.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package telemetry

import (
"math/rand"
"time"

"github.com/armon/go-metrics"
Expand All @@ -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.
Expand Down Expand Up @@ -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)
}
}

0 comments on commit b95c66d

Please sign in to comment.