From 892b4f4f1275c29f0b7ee983cd3f3e7e39708243 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 16 Mar 2021 13:58:38 +0300 Subject: [PATCH] [#426] service/object: Fix put duration At object.Put operation node does not transfer any data. It is done in the stream inside, so we should register duration from `object.Put` invocation until `CloseAndRecv` on the stream. Signed-off-by: Alex Vanin --- pkg/services/object/metrics.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/services/object/metrics.go b/pkg/services/object/metrics.go index 8feb8d652..73ea995e3 100644 --- a/pkg/services/object/metrics.go +++ b/pkg/services/object/metrics.go @@ -23,6 +23,7 @@ type ( putStreamMetric struct { stream object.PutObjectStreamer metrics MetricRegister + start time.Time } MetricRegister interface { @@ -72,7 +73,6 @@ func (m MetricCollector) Put(ctx context.Context) (object.PutObjectStreamer, err t := time.Now() defer func() { m.metrics.IncPutReqCounter() - m.metrics.AddPutReqDuration(time.Since(t)) }() stream, err := m.next.Put(ctx) @@ -83,6 +83,7 @@ func (m MetricCollector) Put(ctx context.Context) (object.PutObjectStreamer, err return &putStreamMetric{ stream: stream, metrics: m.metrics, + start: t, }, nil } @@ -155,5 +156,9 @@ func (s putStreamMetric) Send(req *object.PutRequest) error { } func (s putStreamMetric) CloseAndRecv() (*object.PutResponse, error) { + defer func() { + s.metrics.AddPutReqDuration(time.Since(s.start)) + }() + return s.stream.CloseAndRecv() }