func initConnectionMode( cfg *common.Config, config *logstashConfig, transp *transport.Config, ) (mode.ConnectionMode, error) { sendRetries := config.MaxRetries maxAttempts := sendRetries + 1 if sendRetries < 0 { maxAttempts = 0 } settings := modeutil.Settings{ Failover: !config.LoadBalance, MaxAttempts: maxAttempts, Timeout: config.Timeout, WaitRetry: defaultWaitRetry, MaxWaitRetry: defaultMaxWaitRetry, } if config.Pipelining == 0 { clients, err := modeutil.MakeClients(cfg, makeClientFactory(config, transp)) if err != nil { return nil, err } return modeutil.NewConnectionMode(clients, settings) } clients, err := modeutil.MakeAsyncClients(cfg, makeAsyncClientFactory(config, transp)) if err != nil { return nil, err } return modeutil.NewAsyncConnectionMode(clients, settings) }
func (lj *logstash) init(cfg *common.Config) error { config := defaultConfig if err := cfg.Unpack(&config); err != nil { return err } sendRetries := config.MaxRetries maxAttempts := sendRetries + 1 if sendRetries < 0 { maxAttempts = 0 } tls, err := outputs.LoadTLSConfig(config.TLS) if err != nil { return err } transp := &transport.Config{ Timeout: config.Timeout, Proxy: &config.Proxy, TLS: tls, Stats: &transport.IOStats{ Read: statReadBytes, Write: statWriteBytes, ReadErrors: statReadErrors, WriteErrors: statWriteErrors, }, } logp.Info("Max Retries set to: %v", sendRetries) var m mode.ConnectionMode if config.Pipelining == 0 { clients, err := modeutil.MakeClients(cfg, makeClientFactory(&config, transp)) if err == nil { m, err = modeutil.NewConnectionMode(clients, !config.LoadBalance, maxAttempts, defaultWaitRetry, config.Timeout, defaultMaxWaitRetry) } } else { clients, err := modeutil.MakeAsyncClients(cfg, makeAsyncClientFactory(&config, transp)) if err == nil { m, err = modeutil.NewAsyncConnectionMode(clients, !config.LoadBalance, maxAttempts, defaultWaitRetry, config.Timeout, defaultMaxWaitRetry) } } if err != nil { return err } lj.mode = m lj.index = config.Index return nil }
func (out *elasticsearchOutput) init( cfg *common.Config, topologyExpire int, ) error { config := defaultConfig if err := cfg.Unpack(&config); err != nil { return err } tlsConfig, err := outputs.LoadTLSConfig(config.TLS) if err != nil { return err } err = out.readTemplate(&config.Template) if err != nil { return err } clients, err := modeutil.MakeClients(cfg, makeClientFactory(tlsConfig, &config, out)) if err != nil { return err } maxRetries := config.MaxRetries maxAttempts := maxRetries + 1 // maximum number of send attempts (-1 = infinite) if maxRetries < 0 { maxAttempts = 0 } var waitRetry = time.Duration(1) * time.Second var maxWaitRetry = time.Duration(60) * time.Second out.clients = clients loadBalance := config.LoadBalance m, err := modeutil.NewConnectionMode(clients, !loadBalance, maxAttempts, waitRetry, config.Timeout, maxWaitRetry) if err != nil { return err } out.mode = m out.index = config.Index return nil }
func (lj *logstash) init(cfg *common.Config) error { config := defaultConfig if err := cfg.Unpack(&config); err != nil { return err } sendRetries := config.MaxRetries maxAttempts := sendRetries + 1 if sendRetries < 0 { maxAttempts = 0 } tls, err := outputs.LoadTLSConfig(config.TLS) if err != nil { return err } transp := &transport.Config{ Timeout: config.Timeout, Proxy: &config.Proxy, TLS: tls, } clients, err := modeutil.MakeClients(cfg, makeClientFactory(&config, transp)) if err != nil { return err } logp.Info("Max Retries set to: %v", sendRetries) m, err := modeutil.NewConnectionMode(clients, !config.LoadBalance, maxAttempts, defaultWaitRetry, config.Timeout, defaultMaxWaitRetry) if err != nil { return err } lj.mode = m lj.index = config.Index return nil }
func (r *redisOut) init(cfg *common.Config, expireTopo int) error { config := defaultConfig if err := cfg.Unpack(&config); err != nil { return err } sendRetries := config.MaxRetries maxAttempts := config.MaxRetries + 1 if sendRetries < 0 { maxAttempts = 0 } var dataType redisDataType switch config.DataType { case "", "list": dataType = redisListType case "channel": dataType = redisChannelType default: return errors.New("Bad Redis data type") } index := []byte(config.Index) if len(index) == 0 { return fmt.Errorf("missing %v", cfg.PathOf("index")) } tls, err := outputs.LoadTLSConfig(config.TLS) if err != nil { return err } transp := &transport.Config{ Timeout: config.Timeout, Proxy: &config.Proxy, TLS: tls, Stats: &transport.IOStats{ Read: statReadBytes, Write: statWriteBytes, ReadErrors: statReadErrors, WriteErrors: statWriteErrors, }, } // configure topology support r.topology.init(transp, topoConfig{ host: config.HostTopology, password: config.PasswordTopology, db: config.DbTopology, expire: time.Duration(expireTopo) * time.Second, }) // configure publisher clients clients, err := modeutil.MakeClients(cfg, func(host string) (mode.ProtocolClient, error) { t, err := transport.NewClient(transp, "tcp", host, config.Port) if err != nil { return nil, err } return newClient(t, config.Password, config.Db, index, dataType), nil }) if err != nil { return err } logp.Info("Max Retries set to: %v", sendRetries) m, err := modeutil.NewConnectionMode(clients, !config.LoadBalance, maxAttempts, defaultWaitRetry, config.Timeout, defaultMaxWaitRetry) if err != nil { return err } r.mode = m return nil }
func (r *redisOut) init(cfg *common.Config, expireTopo int) error { config := defaultConfig if err := cfg.Unpack(&config); err != nil { return err } sendRetries := config.MaxRetries maxAttempts := config.MaxRetries + 1 if sendRetries < 0 { maxAttempts = 0 } var dataType redisDataType switch config.DataType { case "", "list": dataType = redisListType case "channel": dataType = redisChannelType default: return errors.New("Bad Redis data type") } if cfg.HasField("index") && !cfg.HasField("key") { s, err := cfg.String("index", -1) if err != nil { return err } if err := cfg.SetString("key", -1, s); err != nil { return err } } if !cfg.HasField("key") { cfg.SetString("key", -1, r.beatName) } key, err := outil.BuildSelectorFromConfig(cfg, outil.Settings{ Key: "key", MultiKey: "keys", EnableSingleOnly: true, FailEmpty: true, }) if err != nil { return err } tls, err := outputs.LoadTLSConfig(config.TLS) if err != nil { return err } transp := &transport.Config{ Timeout: config.Timeout, Proxy: &config.Proxy, TLS: tls, Stats: &transport.IOStats{ Read: statReadBytes, Write: statWriteBytes, ReadErrors: statReadErrors, WriteErrors: statWriteErrors, }, } // configure topology support r.topology.init(transp, topoConfig{ host: config.HostTopology, password: config.PasswordTopology, db: config.DbTopology, expire: time.Duration(expireTopo) * time.Second, }) // configure publisher clients clients, err := modeutil.MakeClients(cfg, func(host string) (mode.ProtocolClient, error) { t, err := transport.NewClient(transp, "tcp", host, config.Port) if err != nil { return nil, err } return newClient(t, config.Password, config.Db, key, dataType), nil }) if err != nil { return err } logp.Info("Max Retries set to: %v", sendRetries) m, err := modeutil.NewConnectionMode(clients, modeutil.Settings{ Failover: !config.LoadBalance, MaxAttempts: maxAttempts, Timeout: config.Timeout, WaitRetry: defaultWaitRetry, MaxWaitRetry: defaultMaxWaitRetry, }) if err != nil { return err } r.mode = m return nil }
func (out *elasticsearchOutput) init( cfg *common.Config, topologyExpire int, ) error { config := defaultConfig if err := cfg.Unpack(&config); err != nil { return err } tlsConfig, err := outputs.LoadTLSConfig(config.TLS) if err != nil { return err } err = out.readTemplate(config.Template) if err != nil { return err } clients, err := modeutil.MakeClients(cfg, makeClientFactory(tlsConfig, &config, out)) if err != nil { return err } maxRetries := config.MaxRetries maxAttempts := maxRetries + 1 // maximum number of send attempts (-1 = infinite) if maxRetries < 0 { maxAttempts = 0 } var waitRetry = time.Duration(1) * time.Second var maxWaitRetry = time.Duration(60) * time.Second out.clients = clients loadBalance := config.LoadBalance m, err := modeutil.NewConnectionMode(clients, !loadBalance, maxAttempts, waitRetry, config.Timeout, maxWaitRetry) if err != nil { return err } if config.SaveTopology { err := out.EnableTTL() if err != nil { logp.Err("Fail to set _ttl mapping: %s", err) // keep trying in the background go func() { for { err := out.EnableTTL() if err == nil { break } logp.Err("Fail to set _ttl mapping: %s", err) time.Sleep(5 * time.Second) } }() } } out.TopologyExpire = 15000 if topologyExpire != 0 { out.TopologyExpire = topologyExpire * 1000 // millisec } out.mode = m out.index = config.Index return nil }
func (out *elasticsearchOutput) init( cfg *common.Config, topologyExpire int, ) error { config := defaultConfig if err := cfg.Unpack(&config); err != nil { return err } index, err := outil.BuildSelectorFromConfig(cfg, outil.Settings{ Key: "index", MultiKey: "indices", EnableSingleOnly: true, FailEmpty: true, }) if err != nil { return err } tlsConfig, err := outputs.LoadTLSConfig(config.TLS) if err != nil { return err } err = out.readTemplate(&config.Template) if err != nil { return err } out.index = index pipeline, err := outil.BuildSelectorFromConfig(cfg, outil.Settings{ Key: "pipeline", MultiKey: "pipelines", EnableSingleOnly: true, FailEmpty: false, }) if err != nil { return err } if !pipeline.IsEmpty() { out.pipeline = &pipeline } clients, err := modeutil.MakeClients(cfg, makeClientFactory(tlsConfig, &config, out)) if err != nil { return err } maxRetries := config.MaxRetries maxAttempts := maxRetries + 1 // maximum number of send attempts (-1 = infinite) if maxRetries < 0 { maxAttempts = 0 } var waitRetry = time.Duration(1) * time.Second var maxWaitRetry = time.Duration(60) * time.Second out.clients = clients loadBalance := config.LoadBalance m, err := modeutil.NewConnectionMode(clients, modeutil.Settings{ Failover: !loadBalance, MaxAttempts: maxAttempts, Timeout: config.Timeout, WaitRetry: waitRetry, MaxWaitRetry: maxWaitRetry, }) if err != nil { return err } out.mode = m return nil }