mi: make timeout configurable for build functions (#2377)

This commit is contained in:
Jan-Otto Kröpke
2026-03-30 18:32:58 +02:00
committed by GitHub
parent 792ef67c4e
commit 43f83573ef
75 changed files with 322 additions and 143 deletions

View File

@@ -23,6 +23,7 @@ import (
"log/slog"
"regexp"
"strings"
"time"
"github.com/alecthomas/kingpin/v2"
"github.com/prometheus-community/windows_exporter/internal/mi"
@@ -183,14 +184,14 @@ type wmiPrintJob struct {
Status string `mi:"Status"`
}
func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
func (c *Collector) Collect(ch chan<- prometheus.Metric, maxScrapeDuration time.Duration) error {
var errs []error
if err := c.collectPrinterStatus(ch); err != nil {
errs = append(errs, fmt.Errorf("failed to collect printer status metrics: %w", err))
}
if err := c.collectPrinterJobStatus(ch); err != nil {
if err := c.collectPrinterJobStatus(ch, maxScrapeDuration); err != nil {
errs = append(errs, fmt.Errorf("failed to collect printer job status metrics: %w", err))
}
@@ -199,7 +200,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
func (c *Collector) collectPrinterStatus(ch chan<- prometheus.Metric) error {
var printers []wmiPrinter
if err := c.miSession.Query(&printers, mi.NamespaceRootCIMv2, c.miQueryPrinter); err != nil {
if err := c.miSession.Query(&printers, mi.NamespaceRootCIMv2, c.miQueryPrinter, 0); err != nil {
return fmt.Errorf("WMI query failed: %w", err)
}
@@ -235,9 +236,9 @@ func (c *Collector) collectPrinterStatus(ch chan<- prometheus.Metric) error {
return nil
}
func (c *Collector) collectPrinterJobStatus(ch chan<- prometheus.Metric) error {
func (c *Collector) collectPrinterJobStatus(ch chan<- prometheus.Metric, maxScrapeDuration time.Duration) error {
var printJobs []wmiPrintJob
if err := c.miSession.Query(&printJobs, mi.NamespaceRootCIMv2, c.miQueryPrinterJobs); err != nil {
if err := c.miSession.Query(&printJobs, mi.NamespaceRootCIMv2, c.miQueryPrinterJobs, maxScrapeDuration); err != nil {
return fmt.Errorf("WMI query failed: %w", err)
}