diff --git a/app/vmagent/common/push_ctx.go b/app/vmagent/common/push_ctx.go index e25ddd03a..950577c07 100644 --- a/app/vmagent/common/push_ctx.go +++ b/app/vmagent/common/push_ctx.go @@ -21,13 +21,7 @@ type PushCtx struct { // Reset resets ctx. func (ctx *PushCtx) Reset() { - tss := ctx.WriteRequest.Timeseries - for i := range tss { - ts := &tss[i] - ts.Labels = nil - ts.Samples = nil - } - ctx.WriteRequest.Timeseries = ctx.WriteRequest.Timeseries[:0] + ctx.WriteRequest.Reset() promrelabel.CleanLabels(ctx.Labels) ctx.Labels = ctx.Labels[:0] diff --git a/app/vmagent/remotewrite/pendingseries.go b/app/vmagent/remotewrite/pendingseries.go index 909085130..efd760e6f 100644 --- a/app/vmagent/remotewrite/pendingseries.go +++ b/app/vmagent/remotewrite/pendingseries.go @@ -122,11 +122,7 @@ func (wr *writeRequest) reset() { wr.wr.Timeseries = nil - for i := range wr.tss { - ts := &wr.tss[i] - ts.Labels = nil - ts.Samples = nil - } + clear(wr.tss) wr.tss = wr.tss[:0] promrelabel.CleanLabels(wr.labels) diff --git a/lib/promscrape/scrapework.go b/lib/promscrape/scrapework.go index 64e8ce3c7..837db6dc5 100644 --- a/lib/promscrape/scrapework.go +++ b/lib/promscrape/scrapework.go @@ -680,11 +680,8 @@ func (wc *writeRequestCtx) reset() { func (wc *writeRequestCtx) resetNoRows() { wc.writeRequest.Reset() - labels := wc.labels - for i := range labels { - labels[i] = prompbmarshal.Label{} - } - wc.labels = labels[:0] + clear(wc.labels) + wc.labels = wc.labels[:0] wc.samples = wc.samples[:0] } diff --git a/lib/protoparser/opentelemetry/stream/streamparser.go b/lib/protoparser/opentelemetry/stream/streamparser.go index bc5512b22..f2e60a820 100644 --- a/lib/protoparser/opentelemetry/stream/streamparser.go +++ b/lib/protoparser/opentelemetry/stream/streamparser.go @@ -238,13 +238,8 @@ type writeContext struct { func (wr *writeContext) reset() { wr.bb.Reset() - tss := wr.tss - for i := range tss { - ts := &tss[i] - ts.Labels = nil - ts.Samples = nil - } - wr.tss = tss[:0] + clear(wr.tss) + wr.tss = wr.tss[:0] wr.baseLabels = resetLabels(wr.baseLabels) wr.pointLabels = resetLabels(wr.pointLabels) @@ -254,9 +249,7 @@ func (wr *writeContext) reset() { } func resetLabels(labels []prompbmarshal.Label) []prompbmarshal.Label { - for i := range labels { - labels[i] = prompbmarshal.Label{} - } + clear(labels) return labels[:0] }