mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-11-23 20:36:21 +01:00
fix: data race of NetClassCollector metrics initialization when multiple requests happen (#2995)
Signed-off-by: John Guo <john@johng.cn>
This commit is contained in:
parent
dc5d3ca0ae
commit
e9e27138a8
@ -22,6 +22,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
@ -41,6 +42,7 @@ type netClassCollector struct {
|
|||||||
subsystem string
|
subsystem string
|
||||||
ignoredDevicesPattern *regexp.Regexp
|
ignoredDevicesPattern *regexp.Regexp
|
||||||
metricDescs map[string]*prometheus.Desc
|
metricDescs map[string]*prometheus.Desc
|
||||||
|
metricDescsMu sync.Mutex
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +138,9 @@ func (c *netClassCollector) netClassSysfsUpdate(ch chan<- prometheus.Metric) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *netClassCollector) getFieldDesc(name string) *prometheus.Desc {
|
func (c *netClassCollector) getFieldDesc(name string) *prometheus.Desc {
|
||||||
|
c.metricDescsMu.Lock()
|
||||||
|
defer c.metricDescsMu.Unlock()
|
||||||
|
|
||||||
fieldDesc, exists := c.metricDescs[name]
|
fieldDesc, exists := c.metricDescs[name]
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
Loading…
Reference in New Issue
Block a user