Skip to content

Commit dd24201

Browse files
[9.1] (backport #11394) [otel config translate] allow hosts to be string not just slice (#11431)
* [otel config translate] allow hosts to be string not just slice (#11394) * [otel config translate] allow hosts to be string not just slice * update changelog to bugfix (cherry picked from commit 70ef801) # Conflicts: # internal/pkg/otel/translate/output_elasticsearch.go # internal/pkg/otel/translate/output_elasticsearch_test.go * fix merge conflicts * remove test cases that shouldn't have been backported --------- Co-authored-by: Lee E Hinman <[email protected]> Co-authored-by: Lee E. Hinman <[email protected]>
1 parent ff228f3 commit dd24201

File tree

2 files changed

+70
-12
lines changed

2 files changed

+70
-12
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# REQUIRED
2+
# Kind can be one of:
3+
# - breaking-change: a change to previously-documented behavior
4+
# - deprecation: functionality that is being removed in a later release
5+
# - bug-fix: fixes a problem in a previous version
6+
# - enhancement: extends functionality but does not break or fix existing behavior
7+
# - feature: new functionality
8+
# - known-issue: problems that we are aware of in a given version
9+
# - security: impacts on the security of a product or a user’s deployment.
10+
# - upgrade: important information for someone upgrading from a prior version
11+
# - other: does not fit into any of the other categories
12+
kind: bug-fix
13+
14+
# REQUIRED for all kinds
15+
# Change summary; a 80ish characters long description of the change.
16+
summary: allow host to be a string for otel configuration translation
17+
18+
# REQUIRED for breaking-change, deprecation, known-issue
19+
# Long description; in case the summary is not enough to describe the change
20+
# this field accommodate a description without length limits.
21+
# description:
22+
23+
# REQUIRED for breaking-change, deprecation, known-issue
24+
# impact:
25+
26+
# REQUIRED for breaking-change, deprecation, known-issue
27+
# action:
28+
29+
# REQUIRED for all kinds
30+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
31+
component: elastic-agent
32+
33+
# AUTOMATED
34+
# OPTIONAL to manually add other PR URLs
35+
# PR URL: A link the PR that added the changeset.
36+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
37+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
38+
# Please provide it if you are adding a fragment for a different PR.
39+
pr: https://github.com/elastic/elastic-agent/pull/11394
40+
41+
# AUTOMATED
42+
# OPTIONAL to manually add other issue URLs
43+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
44+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
45+
issue: https://github.com/elastic/elastic-agent/issues/11352
46+

internal/pkg/otel/translate/output_elasticsearch.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2829
type esToOTelOptions struct {
2930
elasticsearch.ElasticsearchConfig `config:",inline"`
30-
outputs.HostWorkerCfg `config:",inline"`
3131

3232
Index string `config:"index"`
3333
Pipeline string `config:"pipeline"`
@@ -36,13 +36,9 @@ type esToOTelOptions struct {
3636

3737
var defaultOptions = esToOTelOptions{
3838
ElasticsearchConfig: elasticsearch.DefaultConfig(),
39-
40-
Index: "", // Dynamic routing is disabled if index is set
41-
Pipeline: "",
42-
Preset: "custom", // default is custom if not set
43-
HostWorkerCfg: outputs.HostWorkerCfg{
44-
Workers: 1,
45-
},
39+
Index: "", // Dynamic routing is disabled if index is set
40+
Pipeline: "",
41+
Preset: "custom", // default is custom if not set
4642
}
4743

4844
// ToOTelConfig converts a Beat config into OTel elasticsearch exporter config
@@ -99,13 +95,19 @@ func ToOTelConfig(output *config.C, logger *logp.Logger) (map[string]any, error)
9995
}
10096

10197
// Create url using host name, protocol and path
98+
outputHosts, err := outputs.ReadHostList(output)
99+
if err != nil {
100+
return nil, fmt.Errorf("error reading host list: %w", err)
101+
}
102102
hosts := []string{}
103-
for _, h := range escfg.Hosts {
103+
for _, h := range outputHosts {
104104
esURL, err := common.MakeURL(escfg.Protocol, escfg.Path, h, 9200)
105105
if err != nil {
106106
return nil, fmt.Errorf("cannot generate ES URL from host %w", err)
107107
}
108-
hosts = append(hosts, esURL)
108+
if !slices.Contains(hosts, esURL) {
109+
hosts = append(hosts, esURL)
110+
}
109111
}
110112

111113
otelYAMLCfg := map[string]any{
@@ -116,7 +118,7 @@ func ToOTelConfig(output *config.C, logger *logp.Logger) (map[string]any, error)
116118
// where it could spin as many goroutines as it liked.
117119
// Given that batcher implementation can change and it has a history of such changes,
118120
// let's keep max_conns_per_host setting for now and remove it once exporterhelper is stable.
119-
"max_conns_per_host": escfg.NumWorkers(),
121+
"max_conns_per_host": getTotalNumWorkers(output), // num_workers * len(hosts) if loadbalance is true
120122

121123
// Retry
122124
"retry": map[string]any{
@@ -137,7 +139,7 @@ func ToOTelConfig(output *config.C, logger *logp.Logger) (map[string]any, error)
137139
"queue_size": getQueueSize(logger, output),
138140
"block_on_overflow": true,
139141
"wait_for_result": true,
140-
"num_consumers": escfg.NumWorkers(),
142+
"num_consumers": getTotalNumWorkers(output), // num_workers * len(hosts) if loadbalance is true
141143
},
142144

143145
"mapping": map[string]any{
@@ -171,6 +173,16 @@ func ToOTelConfig(output *config.C, logger *logp.Logger) (map[string]any, error)
171173
return otelYAMLCfg, nil
172174
}
173175

176+
// getTotalNumWorkers returns the number of hosts that beats would
177+
// have used taking into account hosts, loadbalance and worker
178+
func getTotalNumWorkers(cfg *config.C) int {
179+
hostList, err := outputs.ReadHostList(cfg)
180+
if err != nil {
181+
return 1
182+
}
183+
return len(hostList)
184+
}
185+
174186
// log warning for unsupported config
175187
func checkUnsupportedConfig(cfg *config.C, logger *logp.Logger) error {
176188
if cfg.HasField("indices") {

0 commit comments

Comments
 (0)