From a4c96d9e6d4b3444f9b8cda3d6f9c9f81a510ed8 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 14 Jul 2020 12:15:25 +0300 Subject: [PATCH] lib/protoparser: properly update `vm_protoparser_rows_read_total{type="promscrape"}` metric --- lib/protoparser/prometheus/parser.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protoparser/prometheus/parser.go b/lib/protoparser/prometheus/parser.go index b18a79b230..c36a105cf8 100644 --- a/lib/protoparser/prometheus/parser.go +++ b/lib/protoparser/prometheus/parser.go @@ -150,18 +150,18 @@ func (r *Row) unmarshal(s string, tagsPool []Tag, noEscapes bool) ([]Tag, error) var rowsReadScrape = metrics.NewCounter(`vm_protoparser_rows_read_total{type="promscrape"}`) func unmarshalRows(dst []Row, s string, tagsPool []Tag, noEscapes bool, errLogger func(s string)) ([]Row, []Tag) { + dstLen := len(dst) for len(s) > 0 { n := strings.IndexByte(s, '\n') if n < 0 { // The last line. dst, tagsPool = unmarshalRow(dst, s, tagsPool, noEscapes, errLogger) break - } else { - dst, tagsPool = unmarshalRow(dst, s[:n], tagsPool, noEscapes, errLogger) - s = s[n+1:] } + dst, tagsPool = unmarshalRow(dst, s[:n], tagsPool, noEscapes, errLogger) + s = s[n+1:] } - rowsReadScrape.Add(len(dst)) + rowsReadScrape.Add(len(dst) - dstLen) return dst, tagsPool }