Skip to content

Commit

Permalink
Add plugin support for autodiscover builders, providers
Browse files Browse the repository at this point in the history
  • Loading branch information
vjsamuel committed Feb 23, 2018
1 parent 326c68f commit 1035959
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
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)
})
}

0 comments on commit 1035959

Please sign in to comment.