Skip to content

Commit

Permalink
move check outside the createResourceAttributes and rename func
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Boten <aboten@lightstep.com>
  • Loading branch information
Alex Boten committed Dec 1, 2023
1 parent 930ff09 commit b7cb11c
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions exporters/prometheus/exporter.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit b7cb11c

Please sign in to comment.