Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[agent] fix the inject_headers transpiler rule #27481

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ output:
hosts:
- 127.0.0.1:9200
- 127.0.0.1:9300
headers:
h1: test-header
username: elastic
password: changeme
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ output:
hosts:
- 127.0.0.1:9200
- 127.0.0.1:9300
headers:
h1: test-header
username: elastic
password: changeme
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ fleet:
output:
elasticsearch:
hosts: [ 127.0.0.1:9200, 127.0.0.1:9300 ]
headers:
h1: test-header
username: fleet
password: fleetpassword

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ output:
hosts:
- 127.0.0.1:9200
- 127.0.0.1:9300
headers:
h1: test-header

namespace: test_namespace
username: elastic
password: changeme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ fleet:
output:
elasticsearch:
hosts: [ 127.0.0.1:9200, 127.0.0.1:9300 ]
headers:
h1: test-header
username: fleet
password: fleetpassword

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ metricbeat:
output:
elasticsearch:
hosts: [127.0.0.1:9200, 127.0.0.1:9300]
headers:
h1: test-header

namespace: test_namespace
username: elastic
password: changeme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ output:
hosts:
- 127.0.0.1:9200
- 127.0.0.1:9300
headers:
h1: test-header
username: elastic
password: changeme
bulk_max_size: 23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ fleet:
output:
elasticsearch:
hosts: [ 127.0.0.1:9200, 127.0.0.1:9300 ]
headers:
h1: test-header
username: fleet
password: fleetpassword

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ metricbeat:
output:
elasticsearch:
hosts: [127.0.0.1:9200, 127.0.0.1:9300]
headers:
h1: test-header
username: elastic
password: changeme
bulk_max_size: 23
Expand Down
4 changes: 2 additions & 2 deletions x-pack/elastic-agent/pkg/agent/transpiler/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1638,12 +1638,12 @@ func (r *InjectHeadersRule) Apply(agentInfo AgentInfo, ast *AST) (err error) {
return nil
}

outputsNode, found := Lookup(ast, "outputs")
outputNode, found := Lookup(ast, "output")
if !found {
return nil
}

elasticsearchNode, found := outputsNode.Find("elasticsearch")
elasticsearchNode, found := outputNode.Find("elasticsearch")
if found {
headersNode, found := elasticsearchNode.Find("headers")
if found {
Expand Down
8 changes: 4 additions & 4 deletions x-pack/elastic-agent/pkg/agent/transpiler/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ rest: of

"inject auth headers: no headers": {
givenYAML: `
outputs:
output:
elasticsearch:
hosts:
- "127.0.0.1:9201"
Expand All @@ -734,7 +734,7 @@ outputs:
port: 5
`,
expectedYAML: `
outputs:
output:
elasticsearch:
headers:
h1: test-header
Expand All @@ -753,7 +753,7 @@ outputs:

"inject auth headers: existing headers": {
givenYAML: `
outputs:
output:
elasticsearch:
headers:
sample-header: existing
Expand All @@ -764,7 +764,7 @@ outputs:
port: 5
`,
expectedYAML: `
outputs:
output:
elasticsearch:
headers:
sample-header: existing
Expand Down