[#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 <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-03-16 13:58:38 +03:00 committed by Leonard Lyubich
parent b8e10571c6
commit 892b4f4f12

View file

@ -23,6 +23,7 @@ type (
putStreamMetric struct { putStreamMetric struct {
stream object.PutObjectStreamer stream object.PutObjectStreamer
metrics MetricRegister metrics MetricRegister
start time.Time
} }
MetricRegister interface { MetricRegister interface {
@ -72,7 +73,6 @@ func (m MetricCollector) Put(ctx context.Context) (object.PutObjectStreamer, err
t := time.Now() t := time.Now()
defer func() { defer func() {
m.metrics.IncPutReqCounter() m.metrics.IncPutReqCounter()
m.metrics.AddPutReqDuration(time.Since(t))
}() }()
stream, err := m.next.Put(ctx) stream, err := m.next.Put(ctx)
@ -83,6 +83,7 @@ func (m MetricCollector) Put(ctx context.Context) (object.PutObjectStreamer, err
return &putStreamMetric{ return &putStreamMetric{
stream: stream, stream: stream,
metrics: m.metrics, metrics: m.metrics,
start: t,
}, nil }, nil
} }
@ -155,5 +156,9 @@ func (s putStreamMetric) Send(req *object.PutRequest) error {
} }
func (s putStreamMetric) CloseAndRecv() (*object.PutResponse, error) { func (s putStreamMetric) CloseAndRecv() (*object.PutResponse, error) {
defer func() {
s.metrics.AddPutReqDuration(time.Since(s.start))
}()
return s.stream.CloseAndRecv() return s.stream.CloseAndRecv()
} }