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

Add plugin support for autodiscover builders, providers #6457

Merged
merged 1 commit into from
Feb 25, 2018
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.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- The node name can be discovered automatically by machine-id matching when beat deployed outside kubernetes cluster. {pull}6146[6146]
- Panics will be written to the logger before exiting. {pull}6199[6199]
- Add builder support for autodiscover and annotations builder {pull}6408[6408]
- Add plugin support for autodiscover builders, providers {pull}6457[6457]

*Auditbeat*

Expand Down
31 changes: 31 additions & 0 deletions libbeat/autodiscover/builder/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package builder

import (
"errors"

"github.com/elastic/beats/libbeat/autodiscover"
p "github.com/elastic/beats/libbeat/plugin"
)

type builderPlugin struct {
name string
builder autodiscover.BuilderConstructor
}

var pluginKey = "libbeat.autodiscover.builder"

// Plugin accepts a BuilderConstructor to be registered as a plugin
func Plugin(name string, b autodiscover.BuilderConstructor) map[string][]interface{} {
return p.MakePlugin(pluginKey, builderPlugin{name, b})
}

func init() {
p.MustRegisterLoader(pluginKey, func(ifc interface{}) error {
b, ok := ifc.(builderPlugin)
if !ok {
return errors.New("plugin does not match processor plugin type")
}

return autodiscover.Registry.AddBuilder(b.name, b.builder)
})
}
31 changes: 31 additions & 0 deletions libbeat/autodiscover/providers/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package providers

import (
"errors"

"github.com/elastic/beats/libbeat/autodiscover"
p "github.com/elastic/beats/libbeat/plugin"
)

type providerPlugin struct {
name string
provider autodiscover.ProviderBuilder
}

var pluginKey = "libbeat.autodiscover.provider"

// Plugin accepts a ProviderBuilder to be registered as a plugin
func Plugin(name string, provider autodiscover.ProviderBuilder) map[string][]interface{} {
return p.MakePlugin(pluginKey, providerPlugin{name, provider})
}

func init() {
p.MustRegisterLoader(pluginKey, func(ifc interface{}) error {
prov, ok := ifc.(providerPlugin)
if !ok {
return errors.New("plugin does not match processor plugin type")
}

return autodiscover.Registry.AddProvider(prov.name, prov.provider)
})
}