@@ -10,6 +10,7 @@ import (
1010 "fmt"
1111 "net/url"
1212 "reflect"
13+ "slices"
1314 "strings"
1415 "time"
1516
@@ -27,7 +28,6 @@ import (
2728
2829type esToOTelOptions struct {
2930 elasticsearch.ElasticsearchConfig `config:",inline"`
30- outputs.HostWorkerCfg `config:",inline"`
3131
3232 Index string `config:"index"`
3333 Preset string `config:"preset"`
@@ -38,9 +38,6 @@ var defaultOptions = esToOTelOptions{
3838
3939 Index : "" , // Dynamic routing is disabled if index is set
4040 Preset : "custom" , // default is custom if not set
41- HostWorkerCfg : outputs.HostWorkerCfg {
42- Workers : 1 ,
43- },
4441}
4542
4643// ToOTelConfig converts a Beat config into OTel elasticsearch exporter config
@@ -97,13 +94,19 @@ func ToOTelConfig(output *config.C, logger *logp.Logger) (map[string]any, error)
9794 }
9895
9996 // Create url using host name, protocol and path
97+ outputHosts , err := outputs .ReadHostList (output )
98+ if err != nil {
99+ return nil , fmt .Errorf ("error reading host list: %w" , err )
100+ }
100101 hosts := []string {}
101- for _ , h := range escfg . Hosts {
102+ for _ , h := range outputHosts {
102103 esURL , err := common .MakeURL (escfg .Protocol , escfg .Path , h , 9200 )
103104 if err != nil {
104105 return nil , fmt .Errorf ("cannot generate ES URL from host %w" , err )
105106 }
106- hosts = append (hosts , esURL )
107+ if ! slices .Contains (hosts , esURL ) {
108+ hosts = append (hosts , esURL )
109+ }
107110 }
108111
109112 otelYAMLCfg := map [string ]any {
@@ -114,7 +117,7 @@ func ToOTelConfig(output *config.C, logger *logp.Logger) (map[string]any, error)
114117 // where it could spin as many goroutines as it liked.
115118 // Given that batcher implementation can change and it has a history of such changes,
116119 // let's keep max_conns_per_host setting for now and remove it once exporterhelper is stable.
117- "max_conns_per_host" : getTotalNumWorkers (escfg ), // num_workers * len(hosts) if loadbalance is true
120+ "max_conns_per_host" : getTotalNumWorkers (output ), // num_workers * len(hosts) if loadbalance is true
118121
119122 // Retry
120123 "retry" : map [string ]any {
@@ -135,7 +138,7 @@ func ToOTelConfig(output *config.C, logger *logp.Logger) (map[string]any, error)
135138 "queue_size" : getQueueSize (logger , output ),
136139 "block_on_overflow" : true ,
137140 "wait_for_result" : true ,
138- "num_consumers" : getTotalNumWorkers (escfg ), // num_workers * len(hosts) if loadbalance is true
141+ "num_consumers" : getTotalNumWorkers (output ), // num_workers * len(hosts) if loadbalance is true
139142 },
140143
141144 "mapping" : map [string ]any {
@@ -171,13 +174,14 @@ func ToOTelConfig(output *config.C, logger *logp.Logger) (map[string]any, error)
171174 return otelYAMLCfg , nil
172175}
173176
174- func getTotalNumWorkers (escfg esToOTelOptions ) int {
175- // calculate total workers
176- totalWorkers := escfg .NumWorkers ()
177- if escfg .LoadBalance && len (escfg .Hosts ) > 1 {
178- totalWorkers = (escfg .NumWorkers () * len (escfg .Hosts ))
177+ // getTotalNumWorkers returns the number of hosts that beats would
178+ // have used taking into account hosts, loadbalance and worker
179+ func getTotalNumWorkers (cfg * config.C ) int {
180+ hostList , err := outputs .ReadHostList (cfg )
181+ if err != nil {
182+ return 1
179183 }
180- return totalWorkers
184+ return len ( hostList )
181185}
182186
183187// log warning for unsupported config
0 commit comments