From a2db81494ecec90c11900bf08a826f1b99ad61e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Wed, 27 Nov 2024 00:14:53 +0100 Subject: [PATCH] mssql: set windows_exporter_collector_success to 0, if errors occurs (#1777) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan-Otto Kröpke --- internal/collector/mssql/mssql.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/collector/mssql/mssql.go b/internal/collector/mssql/mssql.go index b25043a2e..0fac93ea1 100644 --- a/internal/collector/mssql/mssql.go +++ b/internal/collector/mssql/mssql.go @@ -257,13 +257,15 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error { // Result must order, to prevent test failures. sort.Strings(c.config.CollectorsEnabled) + errs := make([]error, 0, len(c.config.CollectorsEnabled)) + for _, name := range c.config.CollectorsEnabled { if _, ok := subCollectors[name]; !ok { return fmt.Errorf("unknown collector: %s", name) } if err := subCollectors[name].build(); err != nil { - return fmt.Errorf("failed to build %s collector: %w", name, err) + errs = append(errs, fmt.Errorf("failed to build %s collector: %w", name, err)) } c.collectorFns = append(c.collectorFns, subCollectors[name].collect) @@ -291,7 +293,7 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error { nil, ) - return nil + return errors.Join(errs...) } // Collect sends the metric values for each metric @@ -408,7 +410,7 @@ func (c *Collector) collect( errs = append(errs, err) success = 0.0 - c.logger.Error(fmt.Sprintf("mssql class collector %s for instance %s failed after %s", collector, sqlInstance, duration), + c.logger.Debug(fmt.Sprintf("mssql class collector %s for instance %s failed after %s", collector, sqlInstance, duration), slog.Any("err", err), ) } else {