-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongodb.go
40 lines (33 loc) · 964 Bytes
/
mongodb.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
package mongoout
import (
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/outputs"
)
func init() {
outputs.RegisterType("mongodb", makeMongodb)
}
func makeMongodb(
_ outputs.IndexManager,
info beat.Info,
observer outputs.Observer,
cfg *common.Config,
) (outputs.Group, error) {
config := defaultConfig()
if err := cfg.Unpack(&config); err != nil {
return outputs.Fail(err)
}
hosts, err := outputs.ReadHostList(cfg)
if err != nil {
return outputs.Fail(err)
}
clients := make([]outputs.NetworkClient, len(hosts))
for i, h := range hosts {
client, err := newClient(h, config.DB, config.Collection, observer, info, config.Timeout)
if err != nil {
return outputs.Fail(err)
}
clients[i] = newBackoffClient(client, config.Backoff.Init, config.Backoff.Max)
}
return outputs.SuccessNet(config.LoadBalance, config.bulkMaxSize, config.MaxRetries, clients)
}