forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
55 lines (46 loc) · 1.23 KB
/
factory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package module
import (
"github.com/joeshaw/multierror"
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/cfgfile"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/cfgwarn"
"github.com/elastic/beats/metricbeat/mb"
)
// Factory creates new Runner instances from configuration objects.
// It is used to register and reload modules.
type Factory struct {
pipeline beat.Pipeline
options []Option
}
// NewFactory creates new Reloader instance for the given config
func NewFactory(p beat.Pipeline, options ...Option) *Factory {
return &Factory{
pipeline: p,
options: options,
}
}
func (r *Factory) Create(c *common.Config, meta *common.MapStrPointer) (cfgfile.Runner, error) {
var errs multierror.Errors
err := cfgwarn.CheckRemoved5xSettings(c, "filters")
if err != nil {
errs = append(errs, err)
}
connector, err := NewConnector(r.pipeline, c, meta)
if err != nil {
errs = append(errs, err)
}
w, err := NewWrapper(c, mb.Registry, r.options...)
if err != nil {
errs = append(errs, err)
}
if err := errs.Err(); err != nil {
return nil, err
}
client, err := connector.Connect()
if err != nil {
return nil, err
}
mr := NewRunner(client, w)
return mr, nil
}