Skip to content

Commit

Permalink
mssql: set windows_exporter_collector_success to 0, if errors occurs (#…
Browse files Browse the repository at this point in the history
…1777)

Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke authored Nov 26, 2024
1 parent 64bf0a6 commit a2db814
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/collector/mssql/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a2db814

Please sign in to comment.