From b7cb11c2f0b903d335b35af8500c0b050432f20c Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Fri, 1 Dec 2023 06:00:36 -0800 Subject: [PATCH] move check outside the createResourceAttributes and rename func Signed-off-by: Alex Boten --- exporters/prometheus/exporter.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/exporters/prometheus/exporter.go b/exporters/prometheus/exporter.go index c0ade197503..16df309be44 100644 --- a/exporters/prometheus/exporter.go +++ b/exporters/prometheus/exporter.go @@ -190,8 +190,8 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) { ch <- c.targetInfo } - if c.resourceAttributesFilter != nil { - c.resourceAttributes(metrics.Resource) + if c.resourceAttributesFilter != nil && len(c.resourceKeyVals.keys) == 0 { + c.createResourceAttributes(metrics.Resource) } for _, scopeMetrics := range metrics.ScopeMetrics { @@ -492,14 +492,10 @@ func (c *collector) metricType(m metricdata.Metrics) *dto.MetricType { return nil } -func (c *collector) resourceAttributes(res *resource.Resource) { +func (c *collector) createResourceAttributes(res *resource.Resource) { c.mu.Lock() defer c.mu.Unlock() - if len(c.resourceKeyVals.keys) > 0 { - return - } - resourceAttrs, _ := res.Set().Filter(c.resourceAttributesFilter) resourceKeys, resourceValues := getAttrs(resourceAttrs, [2]string{}, [2]string{}, keyVals{}) c.resourceKeyVals = keyVals{keys: resourceKeys, vals: resourceValues}