forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make kubernetes indexers/matchers pluggable (elastic#4151)
- Loading branch information
Showing
3 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
p "github.com/elastic/beats/libbeat/plugin" | ||
) | ||
|
||
var ( | ||
indexerKey = "libbeat.processor.kubernetes.indexer" | ||
matcherKey = "libbeat.processor.kubernetes.matcher" | ||
) | ||
|
||
type indexerPlugin struct { | ||
name string | ||
constructor IndexerConstructor | ||
} | ||
|
||
func IndexerPlugin(name string, c IndexerConstructor) map[string][]interface{} { | ||
return p.MakePlugin(indexerKey, indexerPlugin{name, c}) | ||
} | ||
|
||
type matcherPlugin struct { | ||
name string | ||
constructor MatcherConstructor | ||
} | ||
|
||
func MatcherPlugin(name string, m MatcherConstructor) map[string][]interface{} { | ||
return p.MakePlugin(matcherKey, matcherPlugin{name, m}) | ||
} | ||
|
||
func init() { | ||
p.MustRegisterLoader(indexerKey, func(ifc interface{}) error { | ||
i, ok := ifc.(indexerPlugin) | ||
if !ok { | ||
return errors.New("plugin does not match output plugin type") | ||
} | ||
|
||
name := i.name | ||
if Indexing.indexers[name] != nil { | ||
return fmt.Errorf("indexer type %v already registered", name) | ||
} | ||
|
||
Indexing.AddIndexer(name, i.constructor) | ||
return nil | ||
}) | ||
|
||
p.MustRegisterLoader(matcherKey, func(ifc interface{}) error { | ||
m, ok := ifc.(matcherPlugin) | ||
if !ok { | ||
return errors.New("plugin does not match output plugin type") | ||
} | ||
|
||
name := m.name | ||
if Indexing.indexers[name] != nil { | ||
return fmt.Errorf("matcher type %v already registered", name) | ||
} | ||
|
||
Indexing.AddMatcher(name, m.constructor) | ||
return nil | ||
}) | ||
} |