Add metrics for VM flush duration and obj count

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-11-11 17:05:08 +01:00
parent c40c513508
commit 336aa95ab5
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
2 changed files with 20 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import (
"time"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/metrics"
block "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
@ -16,6 +17,7 @@ import (
logging "github.com/ipfs/go-log/v2"
mh "github.com/multiformats/go-multihash"
cbg "github.com/whyrusleeping/cbor-gen"
"go.opencensus.io/stats"
"go.opencensus.io/trace"
"golang.org/x/xerrors"
@ -618,7 +620,7 @@ func (vm *VM) Flush(ctx context.Context) (cid.Cid, error) {
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
}
if err := Copy(ctx, from, to, root); err != nil {
if err := Copy(context.WithValue(ctx, "vm-flush", true), from, to, root); err != nil {
return cid.Undef, xerrors.Errorf("copying tree: %w", err)
}
@ -675,6 +677,7 @@ func linksForObj(blk block.Block, cb func(cid.Cid)) error {
func Copy(ctx context.Context, from, to blockstore.Blockstore, root cid.Cid) error {
ctx, span := trace.StartSpan(ctx, "vm.Copy") // nolint
defer span.End()
start := time.Now()
var numBlocks int
var totalCopySize int
@ -708,6 +711,10 @@ func Copy(ctx context.Context, from, to blockstore.Blockstore, root cid.Cid) err
trace.Int64Attribute("numBlocks", int64(numBlocks)),
trace.Int64Attribute("copySize", int64(totalCopySize)),
)
if yes, ok := ctx.Value("vm-flush").(bool); yes && ok {
took := metrics.SinceInMilliseconds(start)
stats.Record(ctx, metrics.VMFlushCopyCount.M(int64(numBlocks)), metrics.VMFlushCopyDuration.M(took))
}
return nil
}

View File

@ -53,6 +53,8 @@ var (
PubsubSendRPC = stats.Int64("pubsub/send_rpc", "Counter for total sent RPCs", stats.UnitDimensionless)
PubsubDropRPC = stats.Int64("pubsub/drop_rpc", "Counter for total dropped RPCs", stats.UnitDimensionless)
APIRequestDuration = stats.Float64("api/request_duration_ms", "Duration of API requests", stats.UnitMilliseconds)
VMFlushCopyDuration = stats.Float64("vm/flush_copy_ms", "Time spent in VM Flush Copy", stats.UnitMilliseconds)
VMFlushCopyCount = stats.Int64("vm/flush_copy_count", "Number of copied objects", stats.UnitDimensionless)
)
var (
@ -146,6 +148,14 @@ var (
Aggregation: defaultMillisecondsDistribution,
TagKeys: []tag.Key{APIInterface, Endpoint},
}
VMFlushCopyDurationView = &view.View{
Measure: VMFlushCopyDuration,
Aggregation: view.Sum(),
}
VMFlushCopyCountView = &view.View{
Measure: VMFlushCopyCount,
Aggregation: view.Sum(),
}
)
// DefaultViews is an array of OpenCensus views for metric gathering purposes
@ -171,6 +181,8 @@ var DefaultViews = append([]*view.View{
PubsubSendRPCView,
PubsubDropRPCView,
APIRequestDurationView,
VMFlushCopyCountView,
VMFlushCopyDurationView,
},
rpcmetrics.DefaultViews...)