From 9207315b25d6b3b34f2629c72d2851796e94d5c8 Mon Sep 17 00:00:00 2001 From: lanzafame Date: Fri, 24 Jul 2020 15:47:41 +1000 Subject: [PATCH] Change block validation aggregation type from sum to distribution --- chain/sync.go | 6 ++---- metrics/metrics.go | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/chain/sync.go b/chain/sync.go index 20475171e..22edd4060 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -634,10 +634,8 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er validationStart := build.Clock.Now() defer func() { - dur := time.Since(validationStart) - durMilli := dur.Seconds() * float64(1000) - stats.Record(ctx, metrics.BlockValidationDurationMilliseconds.M(durMilli)) - log.Infow("block validation", "took", dur, "height", b.Header.Height) + stats.Record(ctx, metrics.BlockValidationDurationMilliseconds.M(metrics.SinceInMilliseconds(validationStart))) + log.Infow("block validation", "took", time.Since(validationStart), "height", b.Header.Height) }() ctx, span := trace.StartSpan(ctx, "validateBlock") diff --git a/metrics/metrics.go b/metrics/metrics.go index 0ef63de4f..5ed34a620 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -1,6 +1,8 @@ package metrics import ( + "time" + "go.opencensus.io/stats" "go.opencensus.io/stats/view" "go.opencensus.io/tag" @@ -8,6 +10,9 @@ import ( rpcmetrics "github.com/filecoin-project/go-jsonrpc/metrics" ) +// Distribution +var defaultMillisecondsDistribution = view.Distribution(0.01, 0.05, 0.1, 0.3, 0.6, 0.8, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000, 50000, 100000) + // Global Tags var ( Version, _ = tag.NewKey("version") @@ -66,7 +71,7 @@ var ( } BlockValidationDurationView = &view.View{ Measure: BlockValidationDurationMilliseconds, - Aggregation: view.Sum(), + Aggregation: defaultMillisecondsDistribution, } MessageReceivedView = &view.View{ Measure: MessageReceived, @@ -99,4 +104,11 @@ var DefaultViews = append([]*view.View{ MessageReceivedView, MessageValidationFailureView, MessageValidationSuccessView, - PeerCountView}, rpcmetrics.DefaultViews...) + PeerCountView, + }, + rpcmetrics.DefaultViews...) + +// SinceInMilliseconds returns the duration of time since the provide time as a float64. +func SinceInMilliseconds(startTime time.Time) float64 { + return float64(time.Since(startTime).Nanoseconds()) / 1e6 +} \ No newline at end of file