-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
fix: don't fail merticbeat/windows/perfmon when no data is available #42803
base: main
Are you sure you want to change the base?
Changes from all commits
fefed1a
5a8da2a
f74f286
79b36e9
4c55130
14a215f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,8 +98,13 @@ func (re *Reader) Read() ([]mb.Event, error) { | |
if err := re.query.CollectData(); err != nil { | ||
// users can encounter the case no counters are found (services/processes stopped), this should not generate an event with the error message, | ||
//could be the case the specific services are started after and picked up by the next RefreshCounterPaths func | ||
if err == pdh.PDH_NO_COUNTERS { //nolint:errorlint // Bad linter! This is always errno or nil. | ||
if err == pdh.PDH_NO_COUNTERS { //nolint:errorlint // linter complains about comparing error using '==' operator but here error is always of type pdh.PdhErrno (or nil) so `errors.Is` is redundant here | ||
re.log.Warnf("%s %v", collectFailedMsg, err) | ||
} else if err == pdh.PDH_NO_DATA { //nolint:errorlint // the same thing as above ^ | ||
re.log.Warnf("%s %v", collectFailedMsg, err) | ||
|
||
// without the return statement here it still fails when trying to get counter values | ||
return nil, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like for PDH_NO_COUNTERS, we still try to get values, which would return error. IMO, we are doing the right thing by returning when PDH_NO_DATA is hit and not propagating the error to getvalues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure. It is the reason I've implemented it this way (instead of doing something like
WDYT? |
||
} else { | ||
return nil, fmt.Errorf("%v: %w", collectFailedMsg, err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance I could convince you to turn this into a switch statement? Usually once you need an
else if
aswitch
ends up being a little cleaner.