Skip to content

Commit

Permalink
hubble: Lock exporters while gathering metrics
Browse files Browse the repository at this point in the history
This code seems to access a variable without holding a lock, when that
variable can be modified at runtime by other logic. Add locking to avoid
weird and wonderful race conditions.

Found by code inspection.

Signed-off-by: Joe Stringer <[email protected]>
  • Loading branch information
joestringer committed Nov 8, 2024
1 parent 98790b2 commit 66c4826
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/hubble/exporter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (d *dynamicExporterGaugeCollector) Describe(ch chan<- *prometheus.Desc) {
func (d *dynamicExporterGaugeCollector) Collect(ch chan<- prometheus.Metric) {
var activeExporters, inactiveExporters float64

d.exporter.mutex.RLock()
for name, me := range d.exporter.managedExporters {
var value float64
if me.config.End == nil || me.config.End.After(time.Now()) {
Expand All @@ -94,6 +95,7 @@ func (d *dynamicExporterGaugeCollector) Collect(ch chan<- prometheus.Metric) {
individualExportersDesc, prometheus.GaugeValue, value, name,
)
}
d.exporter.mutex.RUnlock()

ch <- prometheus.MustNewConstMetric(
exportersDesc, prometheus.GaugeValue, activeExporters, "active",
Expand Down

0 comments on commit 66c4826

Please sign in to comment.