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

[8.x](backport #41857) Don't panic if libbeat processors are registered more than once #41872

Merged
merged 1 commit into from
Dec 4, 2024
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.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Add `translate_ldap_attribute` processor. {pull}41472[41472]
- Remove unnecessary debug logs during idle connection teardown {issue}40824[40824]
- Fix incorrect cloud provider identification in add_cloud_metadata processor using provider priority mechanism {pull}41636[41636]
- Prevent panic if libbeat processors are loaded more than once. {issue}41475[41475] {pull}41857[51857]

*Auditbeat*

Expand Down
11 changes: 8 additions & 3 deletions libbeat/processors/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type pluginer interface {
Plugin() Constructor
}

var (
ErrExistsAlready error = errors.New("exists already")
ErrPluginAlreadyRegistered error = errors.New("non-namespace plugin already registered")
)

func NewNamespace() *Namespace {
return &Namespace{
reg: map[string]pluginer{},
Expand All @@ -47,7 +52,7 @@ func NewNamespace() *Namespace {
func (ns *Namespace) Register(name string, factory Constructor) error {
p := plugin{NewConditional(factory)}
names := strings.Split(name, ".")
if err := ns.add(names, p); err != nil {
if err := ns.add(names, p); err != nil && !errors.Is(err, ErrExistsAlready) && !errors.Is(err, ErrPluginAlreadyRegistered) {
return fmt.Errorf("plugin %s registration fail %w", name, err)
}
return nil
Expand All @@ -59,7 +64,7 @@ func (ns *Namespace) add(names []string, p pluginer) error {
// register plugin if intermediate node in path being processed
if len(names) == 1 {
if _, found := ns.reg[name]; found {
return fmt.Errorf("%v exists already", name)
return fmt.Errorf("%s %w", name, ErrExistsAlready)
}

ns.reg[name] = p
Expand All @@ -71,7 +76,7 @@ func (ns *Namespace) add(names []string, p pluginer) error {
if found {
ns, ok := tmp.(*Namespace)
if !ok {
return errors.New("non-namespace plugin already registered")
return ErrPluginAlreadyRegistered
}
return ns.add(names[1:], p)
}
Expand Down
2 changes: 1 addition & 1 deletion libbeat/processors/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestNamespaceRegisterFail(t *testing.T) {
fatalError(t, err)

err = ns.Register("test", newTestFilterRule)
assert.Error(t, err)
assert.NoError(t, err)
}

func TestNamespaceError(t *testing.T) {
Expand Down
Loading