Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
stefans-elastic committed Jan 10, 2025
1 parent c0f1703 commit bcb8e39
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions x-pack/metricbeat/module/iis/application_pool/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,24 @@ func (r *Reader) initAppPools() error {
r.log.Info("no running application pools found")
return nil
}
isPDHError := func(err error) bool {
return errors.Is(err, pdh.PdhErrno(syscall.ERROR_NOT_FOUND)) ||
errors.Is(err, pdh.PDH_CSTATUS_NO_COUNTER) ||
errors.Is(err, pdh.PDH_CSTATUS_NO_COUNTERNAME) ||
errors.Is(err, pdh.PDH_CSTATUS_NO_INSTANCE) ||
errors.Is(err, pdh.PDH_CSTATUS_NO_OBJECT)
}
var newQueries []string
r.workerProcesses = make(map[string]string)
for key, value := range appPoolCounters {
childQueries, err := r.query.GetCounterPaths(value)
if err != nil {
if errors.Is(err, pdh.PdhErrno(syscall.ERROR_NOT_FOUND)) || errors.Is(err, pdh.PDH_CSTATUS_NO_COUNTER) || errors.Is(err, pdh.PDH_CSTATUS_NO_COUNTERNAME) || errors.Is(err, pdh.PDH_CSTATUS_NO_INSTANCE) || errors.Is(err, pdh.PDH_CSTATUS_NO_OBJECT) {
if isPDHError(err) {
r.log.Infow("Ignoring non existent counter", "error", err,
logp.Namespace("application pool"), "query", value)
logp.Namespace("application pool"), "query", value,
)
} else {
r.log.Error(err, `failed to expand counter path (query= "%v")`, value)
r.log.Errorf(`failed to expand counter path (query= "%v"): %w`, value, err)
}
continue
}
Expand Down

0 comments on commit bcb8e39

Please sign in to comment.