Skip to content

Commit d92a331

Browse files
authored
Don't overwrite existing headers when mapping agentInfo headers into elasticsearch output (#9199)
* Don't overwrite existing headers. * Add changelog.
1 parent 83cef65 commit d92a331

File tree

3 files changed

+46
-5
lines changed

3 files changed

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

pkg/component/component.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,10 @@ func toIntermediate(policy map[string]interface{}, aliasMapping map[string]strin
591591
}
592592

593593
for headerName, headerVal := range agentHeaders {
594-
headers[headerName] = headerVal
594+
// only set headers for those that are not already set
595+
if _, ok := headers[headerName]; !ok {
596+
headers[headerName] = headerVal
597+
}
595598
}
596599

597600
output[headersKey] = headers

pkg/component/component_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,7 +2166,8 @@ func TestToComponents(t *testing.T) {
21662166
"type": "elasticsearch",
21672167
"enabled": true,
21682168
"headers": map[string]interface{}{
2169-
"header-two": "val-2",
2169+
"header-two": "val-2",
2170+
"header-three": "val-3",
21702171
},
21712172
},
21722173
},
@@ -2195,8 +2196,9 @@ func TestToComponents(t *testing.T) {
21952196
Config: MustExpectedConfig(map[string]interface{}{
21962197
"type": "elasticsearch",
21972198
"headers": map[string]interface{}{
2198-
"header-two": "val-2",
2199-
"header-one": "val-1",
2199+
"header-two": "val-2",
2200+
"header-one": "val-1",
2201+
"header-three": "val-3",
22002202
},
22012203
}),
22022204
},
@@ -2214,7 +2216,8 @@ func TestToComponents(t *testing.T) {
22142216
},
22152217
},
22162218
headers: &testHeadersProvider{headers: map[string]string{
2217-
"header-one": "val-1",
2219+
"header-one": "val-1",
2220+
"header-three": "val-3-diff",
22182221
}},
22192222
},
22202223
{
@@ -2227,6 +2230,7 @@ func TestToComponents(t *testing.T) {
22272230
"enabled": true,
22282231
"headers": map[string]interface{}{
22292232
"cloud1": "beat1",
2233+
"cloud3": "beat3",
22302234
},
22312235
},
22322236
},
@@ -2257,6 +2261,7 @@ func TestToComponents(t *testing.T) {
22572261
"headers": map[string]interface{}{
22582262
"cloud1": "beat1",
22592263
"cloud2": "beat2",
2264+
"cloud3": "beat3",
22602265
},
22612266
}),
22622267
},
@@ -2275,6 +2280,7 @@ func TestToComponents(t *testing.T) {
22752280
},
22762281
headers: &testHeadersProvider{headers: map[string]string{
22772282
"cloud2": "beat2",
2283+
"cloud3": "beat3-diff",
22782284
}},
22792285
},
22802286
{

0 commit comments

Comments
 (0)