comments on proxy metrics

This commit is contained in:
William Banfield
2021-10-13 12:40:12 -04:00
parent 791868b7ef
commit 7d93e72a6a
2 changed files with 11 additions and 0 deletions

View File

@@ -242,6 +242,10 @@ func (app *appConnSnapshot) ApplySnapshotChunkSync(
return app.appConn.ApplySnapshotChunkSync(ctx, req)
}
// addTimeSample returns a function that, when called, adds an observation to m.
// The observation added to m is the number of seconds ellapsed since addTimeSample
// was initially called. addTimeSample is meant to be called in a defer to calculate
// the amount of time a function takes to complete.
func addTimeSample(m metrics.Histogram) func() {
start := time.Now()
return func() { m.Observe(time.Since(start).Seconds()) }

View File

@@ -13,10 +13,15 @@ const (
MetricsSubsystem = "abci_connection"
)
// Metrics contains the prometheus metrics exposed by the proxy package.
type Metrics struct {
MethodTiming metrics.Histogram
}
// PrometheusMetrics constructs a Metrics instance that collects metrics samples.
// The resulting metrics will be prefixed with namespace and labeled with the
// defaultLabelsAndValues. defaultLabelsAndValues must be a list of string pairs
// where the first of each pair is the label and the second is the value.
func PrometheusMetrics(namespace string, defaultLabelsAndValues ...string) *Metrics {
defaultLabels := []string{}
for i := 0; i < len(defaultLabelsAndValues); i += 2 {
@@ -33,6 +38,8 @@ func PrometheusMetrics(namespace string, defaultLabelsAndValues ...string) *Metr
}
}
// NopMetrics constructs a Metrics instance that discards all samples and is suitable
// for testing.
func NopMetrics() *Metrics {
return &Metrics{
MethodTiming: discard.NewHistogram(),