From 863436dd08fae1f05519d4d16de8821517d32813 Mon Sep 17 00:00:00 2001 From: Eugene Ma Date: Thu, 31 Oct 2024 22:09:50 -0700 Subject: [PATCH] move Reset() to reset internal call --- exporter/prometheusremotewriteexporter/exporter.go | 1 - pkg/translator/prometheusremotewrite/metrics_to_prw.go | 3 ++- pkg/translator/prometheusremotewrite/metrics_to_prw_test.go | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/exporter/prometheusremotewriteexporter/exporter.go b/exporter/prometheusremotewriteexporter/exporter.go index fc058c9328db..2f856dfc5e0e 100644 --- a/exporter/prometheusremotewriteexporter/exporter.go +++ b/exporter/prometheusremotewriteexporter/exporter.go @@ -179,7 +179,6 @@ func (prwe *prwExporter) PushMetrics(ctx context.Context, md pmetric.Metrics) er return errors.New("shutdown has been called") default: converter := converterPool.Get().(*prometheusremotewrite.PrometheusConverter) - converter.Reset() defer converterPool.Put(converter) tsMap, err := converter.FromMetrics(md, prwe.exporterSettings) diff --git a/pkg/translator/prometheusremotewrite/metrics_to_prw.go b/pkg/translator/prometheusremotewrite/metrics_to_prw.go index e5c01efd25be..9766c0a2fdc2 100644 --- a/pkg/translator/prometheusremotewrite/metrics_to_prw.go +++ b/pkg/translator/prometheusremotewrite/metrics_to_prw.go @@ -28,6 +28,7 @@ type Settings struct { // FromMetrics converts pmetric.Metrics to Prometheus remote write format. func (c *PrometheusConverter) FromMetrics(md pmetric.Metrics, settings Settings) (map[string]*prompb.TimeSeries, error) { + c.reset() errs := c.fromMetrics(md, settings) tss := c.timeSeries() out := make(map[string]*prompb.TimeSeries, len(tss)) @@ -60,7 +61,7 @@ func NewPrometheusConverter() *PrometheusConverter { } } -func (c *PrometheusConverter) Reset() { +func (c *PrometheusConverter) reset() { clear(c.labels) c.labels = c.labels[:0] clear(c.unique) diff --git a/pkg/translator/prometheusremotewrite/metrics_to_prw_test.go b/pkg/translator/prometheusremotewrite/metrics_to_prw_test.go index 4e622df5b95f..420e6afa70f0 100644 --- a/pkg/translator/prometheusremotewrite/metrics_to_prw_test.go +++ b/pkg/translator/prometheusremotewrite/metrics_to_prw_test.go @@ -41,7 +41,6 @@ func BenchmarkFromMetrics(b *testing.B) { tsMap, err := c.FromMetrics(payload.Metrics(), Settings{}) require.NoError(b, err) require.NotNil(b, tsMap) - c.Reset() } }) } @@ -79,7 +78,7 @@ func BenchmarkPrometheusConverter_FromMetrics(b *testing.B) { for i := 0; i < b.N; i++ { require.NoError(b, c.fromMetrics(payload.Metrics(), Settings{})) require.NotNil(b, c.timeSeries()) - c.Reset() + c.reset() } }) }