From 4ad397188ed40a2cd27e7b18754b68af72ce4f4f Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 29 Nov 2021 21:46:52 +0200 Subject: [PATCH] lib/protoparser: do not log `connection reset by peer` error when reading the data via InfluxDB, Graphite and OpenTSDB protocols over plain TCP connections This error is expected, so there is no need in spamming the log with this error. --- docs/CHANGELOG.md | 1 + lib/protoparser/common/lines_reader.go | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 62892e842c..a317c05b94 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -11,6 +11,7 @@ sort: 15 * FEATURE: vmagent: export `vm_persistentqueue_read_duration_seconds_total` and `vm_persistentqueue_write_duration_seconds_total` metrics, which can be used for detecting persistent queue saturation with `rate(vm_persistentqueue_write_duration_seconds_total) > 0.9s` alerting rule. * FEATURE: [vmbackup](https://docs.victoriametrics.com/vmbackup.html), [vmrestore](https://docs.victoriametrics.com/vmrestore.html): add `-s3ForcePathStyle` command-line flag, which can be used for making backups to [Aliyun OSS](https://www.aliyun.com/product/oss). See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/1802). * FEATURE: [vmctl](https://docs.victoriametrics.com/vmctl.html): improve data migration from OpenTSDB. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/1809). Thanks to @johnseekins . +* FEATURE: suppress `connection reset by peer` errors when remote client resets TCP connection to VictoriaMetrics / vmagent while ingesting the data via InfluxDB line protocol, Graphite protocol or OpenTSDB protocol. This error is expected, so there is no need in logging it. * BUGFIX: vmstorage [enterprise](https://victoriametrics.com/enterprise.html): added missing `vm_tenant_used_tenant_bytes` metric, which shows the approximate per-tenant disk usage. See [these docs](https://docs.victoriametrics.com/PerTenantStatistic.html) and [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1605). * BUGFIX: vmauth: properly take into account the value passed to `-maxIdleConnsPerBackend` command-line flag. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1300). diff --git a/lib/protoparser/common/lines_reader.go b/lib/protoparser/common/lines_reader.go index 19395eac47..6e9ed3fb21 100644 --- a/lib/protoparser/common/lines_reader.go +++ b/lib/protoparser/common/lines_reader.go @@ -2,8 +2,10 @@ package common import ( "bytes" + "errors" "fmt" "io" + "strings" "time" "github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil" @@ -50,15 +52,18 @@ again: if err == nil { return dstBuf, tailBuf, fmt.Errorf("no forward progress made") } - if err == io.EOF && len(dstBuf) > 0 { + isEOF := isEOFLikeError(err) + if isEOF && len(dstBuf) > 0 { // Missing newline in the end of stream. This is OK, // so suppress io.EOF for now. It will be returned during the next // call to ReadLinesBlock. // This fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/60 . return dstBuf, tailBuf, nil } - if err != io.EOF { + if !isEOF { err = fmt.Errorf("cannot read a block of data in %.3fs: %w", time.Since(startTime).Seconds(), err) + } else { + err = io.EOF } return dstBuf, tailBuf, err } @@ -86,3 +91,11 @@ again: dstBuf = dstBuf[:nn] return dstBuf, tailBuf, nil } + +func isEOFLikeError(err error) bool { + if errors.Is(err, io.EOF) { + return true + } + s := err.Error() + return strings.Contains(s, "reset by peer") +}