Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[x-pack][metricbeat][iis] improve error handling on pdh counters in application_pool data stream #42274

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only.
- Fix flaky test in cel and httpjson inputs of filebeat. {issue}40503[40503] {pull}41358[41358]
- Fix documentation and implementation of raw message handling in Filebeat http_endpoint by removing it. {pull}41498[41498]
- Fix flaky test in filebeat Okta entity analytics provider. {issue}42059[42059] {pull}42123[42123]
- Fix IIS module logging errors in case application pool PDH counter is not found. {pull}42274[42274]

==== Added

Expand Down
21 changes: 16 additions & 5 deletions x-pack/metricbeat/module/iis/application_pool/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"strings"
"syscall"

"github.com/elastic/beats/v7/metricbeat/helper/windows/pdh"
"github.com/elastic/elastic-agent-libs/mapstr"
Expand Down Expand Up @@ -111,16 +112,27 @@ func (r *Reader) initAppPools() error {
r.log.Info("no running application pools found")
return nil
}
// Helper function to identify known PDH errors, such as missing counters or instances.
// These errors are expected in certain cases (e.g. "No Managed Code" environments).
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)
}
stefans-elastic marked this conversation as resolved.
Show resolved Hide resolved
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.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) {
// Handle known PDH errors as informational (e.g. missing counters).
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)
stefans-elastic marked this conversation as resolved.
Show resolved Hide resolved
}
continue
}
Expand Down Expand Up @@ -210,7 +222,6 @@ func (r *Reader) mapEvents(values map[string][]pdh.CounterValue) map[string]mb.E
}
}
}

}
}
return events
Expand All @@ -227,7 +238,7 @@ func getApplicationPools(names []string) ([]ApplicationPool, error) {
if err != nil {
return nil, err
}
var appPools = make(map[string][]int)
appPools := make(map[string][]int)
for key, value := range processes {
appPools[value] = append(appPools[value], key)
}
Expand Down
Loading