-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
add AddError method to accumulator #1536
Conversation
return | ||
} | ||
atomic.AddUint64(&ac.errCount, 1) | ||
log.Printf("ERROR in input [%s]: %s", ac.inputConfig.Name, 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.
reading ac.inputConfig.Name could produce a race condition here. Since this bit of code shouldn't be hugely high-traffic, I would remove the atomic
package, add a sync.Mutex to the accumulator, and change to:
if err == nil {
return
}
ac.Lock()
ac.errCount++
log.Printf("ERROR in input [%s]: %s", ac.inputConfig.Name, err)
ac.Unlock()
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.
The only place where inputConfig.Name
is touched is in internal/config/config.go:798 (during initialization). It is never read or written to ever again (prior to this PR it was an unused variable). Thus there's no need to protect it.
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.
yes but this function is reading it, so unless you make the function a value receiver, there can be a race condition here. nevermind, not sure why I was under the impression that reading struct fields was not thread-safe, should be fine...
How do you want to handle all the failures due to test mocks not having the |
You shouldn't have to update a bunch of test mocks, just add the AddError function to the testutil struct: https://github.com/influxdata/telegraf/blob/master/testutil/accumulator.go#L27 |
Ah, didn't look into the issue too deeply (at all really). Will do that then :-) |
Updated PR with the testutil changes. |
looks great, thanks @phemmer |
This adds an
AddError()
method to the accumulator. Ref #1446As opposed to the original POC in #1446, I instead just implemented it so that
AddError()
immediately writes out to the log instead of sending it into achan
just so that a goroutine could then write it out to the log. This approach is much simpler.I also added an
errCount
to the accumulator which will increment each time an error is generated. This was done for 2 reasons:Test()
function could tell if any errors were generated during the run.It would be very useful to know when a plugin starts throwing errors. You could then write a kapacitor alert to trigger when such starts happening.
Haven't updated CHANGELOG since the code in this PR is unused, and thus there is no user visible change.