forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
57 lines (47 loc) · 1.25 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
56
57
package module
import (
"time"
"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
maxStartDelay time.Duration
}
// NewFactory creates new Reloader instance for the given config
func NewFactory(maxStartDelay time.Duration, p beat.Pipeline) *Factory {
return &Factory{
pipeline: p,
maxStartDelay: maxStartDelay,
}
}
func (r *Factory) Create(c *common.Config) (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)
if err != nil {
errs = append(errs, err)
}
w, err := NewWrapper(r.maxStartDelay, c, mb.Registry)
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
}