Skip to content

Commit

Permalink
fix: data race of NetClassCollector metrics initialization when multi…
Browse files Browse the repository at this point in the history
…ple requests happen (prometheus#2995)

Signed-off-by: John Guo <john@johng.cn>
  • Loading branch information
gqcn authored and gitperr committed Apr 30, 2024
1 parent 28355a3 commit 670e785
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions collector/netclass_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net"
"os"
"regexp"
"sync"

"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
Expand All @@ -41,6 +42,7 @@ type netClassCollector struct {
subsystem string
ignoredDevicesPattern *regexp.Regexp
metricDescs map[string]*prometheus.Desc
metricDescsMu sync.Mutex
logger log.Logger
}

Expand Down Expand Up @@ -136,6 +138,9 @@ func (c *netClassCollector) netClassSysfsUpdate(ch chan<- prometheus.Metric) err
}

func (c *netClassCollector) getFieldDesc(name string) *prometheus.Desc {
c.metricDescsMu.Lock()
defer c.metricDescsMu.Unlock()

fieldDesc, exists := c.metricDescs[name]

if !exists {
Expand Down

0 comments on commit 670e785

Please sign in to comment.