From 12f2c5679b1d66e5ac8bdf059bde603573fa9a7a Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 21 Jan 2024 05:11:05 +0200 Subject: [PATCH] all: consistently clear prompbmarshal.Label by assigning an empty struct instead of zeroing Name and Value individually --- lib/promrelabel/relabel.go | 4 +--- lib/promscrape/scrapework.go | 6 ++---- lib/promutils/labels.go | 4 +--- lib/protoparser/opentelemetry/stream/streamparser.go | 4 +--- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/promrelabel/relabel.go b/lib/promrelabel/relabel.go index be3c5f6fa..d48dde26a 100644 --- a/lib/promrelabel/relabel.go +++ b/lib/promrelabel/relabel.go @@ -592,9 +592,7 @@ func GetLabelByName(labels []prompbmarshal.Label, name string) *prompbmarshal.La // This should help GC cleaning up label.Name and label.Value strings. func CleanLabels(labels []prompbmarshal.Label) { for i := range labels { - label := &labels[i] - label.Name = "" - label.Value = "" + labels[i] = prompbmarshal.Label{} } } diff --git a/lib/promscrape/scrapework.go b/lib/promscrape/scrapework.go index a5fa45aa5..a516354f3 100644 --- a/lib/promscrape/scrapework.go +++ b/lib/promscrape/scrapework.go @@ -736,11 +736,9 @@ func (wc *writeRequestCtx) resetNoRows() { labels := wc.labels for i := range labels { - label := &labels[i] - label.Name = "" - label.Value = "" + labels[i] = prompbmarshal.Label{} } - wc.labels = wc.labels[:0] + wc.labels = labels[:0] wc.samples = wc.samples[:0] } diff --git a/lib/promutils/labels.go b/lib/promutils/labels.go index b4f9216eb..75c223539 100644 --- a/lib/promutils/labels.go +++ b/lib/promutils/labels.go @@ -282,9 +282,7 @@ func (x *Labels) RemoveLabelsWithDoubleUnderscorePrefix() { func cleanLabels(labels []prompbmarshal.Label) { for i := range labels { - label := &labels[i] - label.Name = "" - label.Value = "" + labels[i] = prompbmarshal.Label{} } } diff --git a/lib/protoparser/opentelemetry/stream/streamparser.go b/lib/protoparser/opentelemetry/stream/streamparser.go index be5f21e4d..9d4dab2cc 100644 --- a/lib/protoparser/opentelemetry/stream/streamparser.go +++ b/lib/protoparser/opentelemetry/stream/streamparser.go @@ -252,9 +252,7 @@ func (wr *writeContext) reset() { func resetLabels(labels []prompbmarshal.Label) []prompbmarshal.Label { for i := range labels { - label := &labels[i] - label.Name = "" - label.Value = "" + labels[i] = prompbmarshal.Label{} } return labels[:0] }