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>
Signed-off-by: Vitaly Zhuravlev <v-zhuravlev@users.noreply.github.com>
  • Loading branch information
gqcn authored and v-zhuravlev committed Nov 1, 2024
1 parent 525140c commit 94a0034
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 94a0034

Please sign in to comment.