[0.30] fix: add missing concurrency lock (#2140)

This commit is contained in:
Jan-Otto Kröpke
2025-07-20 08:16:26 +02:00
committed by GitHub
parent 716362d2ee
commit 15156ce444
3 changed files with 23 additions and 7 deletions

View File

@@ -18,6 +18,7 @@ package collector
import (
"fmt"
"log/slog"
"sync"
"time"
"github.com/prometheus/client_golang/prometheus"
@@ -26,6 +27,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
@@ -58,5 +65,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()
}