-
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
refactor: replace go-multierror with native std go errors #39837
Conversation
Go 1.20 added errors.Join allowing for multierrors. Replace go-multierror usage with native go errors and drop the extra dependency on github.com/hashicorp/go-multierror
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
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.
@kruskall, thanks for the PR! That's a great refactoring I'd love to see merged.
However, as it is, I believe it will break the logic on our, there are a couple of places we rely the multierror.MultiError
API:
beats/x-pack/libbeat/management/managerV2.go
Lines 818 to 847 in db9406b
if err := obj.Reload(inputBeatCfgs); err != nil { | |
merror := &multierror.MultiError{} | |
realErrors := multierror.Errors{} | |
// At the moment this logic is tightly bound to the current RunnerList | |
// implementation from libbeat/cfgfile/list.go and Input.loadStates from | |
// filebeat/input/log/input.go. | |
// If they change the way they report errors, this will break. | |
// TODO (Tiago): update all layers to use the most recent features from | |
// the standard library errors package. | |
if errors.As(err, &merror) { | |
for _, err := range merror.Errors { | |
causeErr := errors.Unwrap(err) | |
// A Log input is only marked as finished when all events it | |
// produced are acked by the acker so when we see this error, | |
// we just retry until the new input can be started. | |
// This is the same logic used by the standalone configuration file | |
// reloader implemented on libbeat/cfgfile/reload.go | |
inputNotFinishedErr := &common.ErrInputNotFinished{} | |
if ok := errors.As(causeErr, &inputNotFinishedErr); ok { | |
cm.logger.Debugf("file '%s' is not finished, will retry starting the input soon", inputNotFinishedErr.File) | |
cm.forceReload = true | |
cm.logger.Debug("ForceReload set to TRUE") | |
continue | |
} | |
// This is an error that cannot be ignored, so we report it | |
realErrors = append(realErrors, err) | |
} | |
} |
beats/x-pack/libbeat/management/managerV2.go
Lines 676 to 687 in db9406b
if err := cm.reloadInputs(inputUnits); err != nil { | |
merror := &multierror.MultiError{} | |
if errors.As(err, &merror) { | |
for _, err := range merror.Errors { | |
unitErr := cfgfile.UnitError{} | |
if errors.As(err, &unitErr) { | |
unitErrors[unitErr.UnitID] = append(unitErrors[unitErr.UnitID], unitErr.Err) | |
delete(healthyInputs, unitErr.UnitID) | |
} | |
} | |
} | |
} |
Those bits would need updating as part of this PR.
Thanks for the feedback! 🙇 I think the code you linked is using |
You're right 🤦♂️. I forgot we use two multierror libs... Let me check with the team if anybody can think of any unseen issue with this change. |
Proposed commit message
Go 1.20 added errors.Join allowing for multierrors. Replace go-multierror usage with native go errors and drop the extra dependency on github.com/hashicorp/go-multierror
Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Disruptive User Impact
Author's Checklist
How to test this PR locally
Related issues
Use cases
Screenshots
Logs