fix: add missing concurrency lock (#2098)

This commit is contained in:
Jan-Otto Kröpke
2025-07-04 11:14:49 +02:00
committed by GitHub
parent 7377d48f07
commit c3043693df
3 changed files with 23 additions and 7 deletions

View File

@@ -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()
}