collector: scope the scrape slot to a collection and report queued scrapes (#2729)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-15 20:54:16 +00:00
committed by GitHub
parent 8b5eb31e4c
commit b914dbbf6e
14 changed files with 248 additions and 58 deletions
-33
View File
@@ -29,13 +29,6 @@ import (
// Interface guard.
var _ prometheus.Collector = (*Handler)(nil)
// scrapeSlot admits one scrape at a time, across all collections.
// We 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 scrapeSlot = make(chan struct{}, 1)
// Handler implements [prometheus.Collector] for a set of Windows Collection.
type Handler struct {
maxScrapeDuration time.Duration
@@ -100,29 +93,3 @@ func (p *Handler) Collect(ch chan<- prometheus.Metric) {
p.collection.collectAll(ctx, ch, p.logger)
}
// acquireScrapeSlot waits for the scrape slot until ctx is done.
func acquireScrapeSlot(ctx context.Context) error {
if err := ctx.Err(); err != nil {
return err
}
select {
case scrapeSlot <- struct{}{}:
case <-ctx.Done():
return ctx.Err()
}
// Both cases may have been ready. Don't start a scrape that nobody waits for anymore.
if err := ctx.Err(); err != nil {
<-scrapeSlot
return err
}
return nil
}
func releaseScrapeSlot() {
<-scrapeSlot
}