mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-08 05:56:37 +00:00
fix: add missing concurrency lock (#2098)
This commit is contained in:
@@ -20,6 +20,7 @@ package collector
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@@ -28,6 +29,12 @@ import (
|
||||
// Interface guard.
|
||||
var _ prometheus.Collector = (*Handler)(nil)
|
||||
|
||||
// We are expose metrics directly from the memory region of the Win32 API.
|
||||
// We should not allow more than one request at a time.
|
||||
//
|
||||
//nolint:gochecknoglobals
|
||||
var concurrencyMu sync.Mutex
|
||||
|
||||
// Handler implements [prometheus.Collector] for a set of Windows Collection.
|
||||
type Handler struct {
|
||||
maxScrapeDuration time.Duration
|
||||
@@ -60,5 +67,7 @@ func (p *Handler) Describe(_ chan<- *prometheus.Desc) {}
|
||||
// Collect sends the collected metrics from each of the Collection to
|
||||
// prometheus.
|
||||
func (p *Handler) Collect(ch chan<- prometheus.Metric) {
|
||||
concurrencyMu.Lock()
|
||||
p.collection.collectAll(ch, p.logger, p.maxScrapeDuration)
|
||||
concurrencyMu.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user