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

Signed-off-by: John Guo <[email protected]>
  • Loading branch information
gqcn committed Apr 19, 2024
1 parent 36e0d1f commit 31113ec
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 31113ec

Please sign in to comment.