Skip to content

Commit

Permalink
Lock the whole scope of the func
Browse files Browse the repository at this point in the history
  • Loading branch information
hexdigest committed Mar 23, 2023
1 parent 3483cb8 commit 77959ad
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions exporters/prometheus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,21 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) {
}

func() {
c.mu.RLock()
if c.targetInfo != nil || c.disableTargetInfo {
c.mu.RUnlock()
return
}
c.mu.RUnlock()
c.mu.Lock()
defer c.mu.Unlock()

targetInfo, err := createInfoMetric(targetInfoMetricName, targetInfoDescription, metrics.Resource)
if err != nil {
otel.Handle(err)
if c.targetInfo == nil && !c.disableTargetInfo {
targetInfo, err := createInfoMetric(targetInfoMetricName, targetInfoDescription, metrics.Resource)
if err != nil {
// If the target info metric is invalid, disable sending it.
otel.Handle(err)
c.disableTargetInfo = true
return
}

c.targetInfo = targetInfo
}

c.mu.Lock()
// If the target info metric is invalid, disable sending it.
c.disableTargetInfo = (err != nil)
c.targetInfo = targetInfo
c.mu.Unlock()
}()

if !c.disableTargetInfo {
Expand Down

0 comments on commit 77959ad

Please sign in to comment.