lib/protoparser/promremotewrite: log the time spent on unsuccessful data read from the network

This should help with debugging `connection timed out` errors.
This commit is contained in:
Aliaksandr Valialkin 2020-11-13 17:48:23 +02:00
parent 1364dfdd8c
commit f80d6473e1

View file

@ -9,6 +9,7 @@ import (
"sync" "sync"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil" "github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fasttime"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil" "github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompb" "github.com/VictoriaMetrics/VictoriaMetrics/lib/prompb"
"github.com/VictoriaMetrics/metrics" "github.com/VictoriaMetrics/metrics"
@ -75,10 +76,11 @@ func (ctx *pushCtx) reset() {
func (ctx *pushCtx) Read() error { func (ctx *pushCtx) Read() error {
readCalls.Inc() readCalls.Inc()
lr := io.LimitReader(ctx.br, int64(maxInsertRequestSize.N)+1) lr := io.LimitReader(ctx.br, int64(maxInsertRequestSize.N)+1)
startTime := fasttime.UnixTimestamp()
reqLen, err := ctx.reqBuf.ReadFrom(lr) reqLen, err := ctx.reqBuf.ReadFrom(lr)
if err != nil { if err != nil {
readErrors.Inc() readErrors.Inc()
return fmt.Errorf("cannot read compressed request: %w", err) return fmt.Errorf("cannot read compressed request in %d seconds: %w", fasttime.UnixTimestamp()-startTime, err)
} }
if reqLen > int64(maxInsertRequestSize.N) { if reqLen > int64(maxInsertRequestSize.N) {
readErrors.Inc() readErrors.Inc()