Skip to content

Commit 313cd53

Browse files
committed
[Elastic Agent] Use Fleet agent ID as agent.id
This updates the inject_agent_info rule to set the `agent.id` field to the value of the Fleet Agent ID. Previously this value was only added to the `elastic_agent.id` field, and the `agent.id` field was a random UUID generated the first time a Beat process was run. And each Beat process would have its own UUID. This change affects metricbeat, filebeat, heartbeat, osquerybeat, and packetbeat (these are the Beats that have an integration with Agent today). Heartbeat's Agent spec was missing the `inject_agent_info` so I added it. Closes #21121
1 parent 87994f4 commit 313cd53

12 files changed

+97
-2
lines changed

x-pack/elastic-agent/CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,4 @@
112112
- Log output of container to $LOGS_PATH/elastic-agent-start.log when LOGS_PATH set {pull}25150[25150]
113113
- Use `filestream` input for internal log collection. {pull}25660[25660]
114114
- Enable agent to send custom headers to kibana/ES {pull}26275[26275]
115+
- Set `agent.id` to the Fleet Agent ID in events published from inputs backed by Beats. {issue}21121[21121] {pull}26394[26394]

x-pack/elastic-agent/pkg/agent/program/supported.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/elastic-agent/pkg/agent/program/testdata/enabled_output_true-filebeat.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ filebeat:
2222
id: agent-id
2323
version: 8.0.0
2424
snapshot: false
25+
- add_fields:
26+
target: "agent"
27+
fields:
28+
id: agent-id
2529
output:
2630
elasticsearch:
2731
enabled: true

x-pack/elastic-agent/pkg/agent/program/testdata/enabled_true-filebeat.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ filebeat:
2323
id: agent-id
2424
version: 8.0.0
2525
snapshot: false
26+
- add_fields:
27+
target: "agent"
28+
fields:
29+
id: agent-id
2630
output:
2731
elasticsearch:
2832
hosts:

x-pack/elastic-agent/pkg/agent/program/testdata/single_config-filebeat.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ filebeat:
2424
id: agent-id
2525
version: 8.0.0
2626
snapshot: false
27+
- add_fields:
28+
target: "agent"
29+
fields:
30+
id: agent-id
2731
- type: log
2832
paths:
2933
- /var/log/hello3.log
@@ -48,6 +52,10 @@ filebeat:
4852
id: agent-id
4953
version: 8.0.0
5054
snapshot: false
55+
- add_fields:
56+
target: "agent"
57+
fields:
58+
id: agent-id
5159
output:
5260
elasticsearch:
5361
hosts:

x-pack/elastic-agent/pkg/agent/program/testdata/single_config-heartbeat.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ inputs:
77
timeout: 16s
88
wait: 1s
99
data_stream.namespace: default
10+
processors:
11+
- add_fields:
12+
target: 'elastic_agent'
13+
fields:
14+
id: agent-id
15+
version: 8.0.0
16+
snapshot: false
17+
- add_fields:
18+
target: 'agent'
19+
fields:
20+
id: agent-id
1021
output:
1122
elasticsearch:
1223
hosts:

x-pack/elastic-agent/pkg/agent/program/testdata/single_config-metricbeat.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ metricbeat:
2121
id: agent-id
2222
version: 8.0.0
2323
snapshot: false
24+
- add_fields:
25+
target: "agent"
26+
fields:
27+
id: agent-id
2428
- module: docker
2529
metricsets: [info]
2630
index: metrics-generic-default
@@ -42,6 +46,10 @@ metricbeat:
4246
id: agent-id
4347
version: 8.0.0
4448
snapshot: false
49+
- add_fields:
50+
target: "agent"
51+
fields:
52+
id: agent-id
4553
- module: apache
4654
metricsets: [info]
4755
index: metrics-generic-testing
@@ -66,6 +74,10 @@ metricbeat:
6674
id: agent-id
6775
version: 8.0.0
6876
snapshot: false
77+
- add_fields:
78+
target: "agent"
79+
fields:
80+
id: agent-id
6981
output:
7082
elasticsearch:
7183
hosts: [127.0.0.1:9200, 127.0.0.1:9300]

x-pack/elastic-agent/pkg/agent/program/testdata/single_config-packetbeat.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ inputs:
77
id: agent-id
88
version: 8.0.0
99
snapshot: false
10+
- add_fields:
11+
target: 'agent'
12+
fields:
13+
id: agent-id
1014
streams:
1115
- type: flow
1216
timeout: 10s

x-pack/elastic-agent/pkg/agent/program/testdata/synthetics_config-heartbeat.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ inputs:
77
timeout: 16s
88
wait: 1s
99
data_stream.namespace: default
10+
processors:
11+
- add_fields:
12+
target: 'elastic_agent'
13+
fields:
14+
id: agent-id
15+
version: 8.0.0
16+
snapshot: false
17+
- add_fields:
18+
target: 'agent'
19+
fields:
20+
id: agent-id
1021
- type: synthetics/tcp
1122
id: unique-tcp-id
1223
name: my-tcp
@@ -15,6 +26,17 @@ inputs:
1526
timeout: 16s
1627
wait: 1s
1728
data_stream.namespace: default
29+
processors:
30+
- add_fields:
31+
target: 'elastic_agent'
32+
fields:
33+
id: agent-id
34+
version: 8.0.0
35+
snapshot: false
36+
- add_fields:
37+
target: 'agent'
38+
fields:
39+
id: agent-id
1840
- type: synthetics/icmp
1941
id: unique-icmp-id
2042
name: my-icmp
@@ -26,6 +48,17 @@ inputs:
2648
timeout: 16s
2749
wait: 1s
2850
data_stream.namespace: default
51+
processors:
52+
- add_fields:
53+
target: 'elastic_agent'
54+
fields:
55+
id: agent-id
56+
version: 8.0.0
57+
snapshot: false
58+
- add_fields:
59+
target: 'agent'
60+
fields:
61+
id: agent-id
2962
output:
3063
elasticsearch:
3164
hosts: [127.0.0.1:9200, 127.0.0.1:9300]

x-pack/elastic-agent/pkg/agent/transpiler/rules.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ func (r *InjectAgentInfoRule) Apply(agentInfo AgentInfo, ast *AST) (err error) {
775775
return errors.New("InjectAgentInfoRule: processors is not a list")
776776
}
777777

778-
// elastic.agent
778+
// elastic_agent
779779
processorMap := &Dict{value: make([]Node, 0)}
780780
processorMap.value = append(processorMap.value, &Key{name: "target", value: &StrVal{value: "elastic_agent"}})
781781
processorMap.value = append(processorMap.value, &Key{name: "fields", value: &Dict{value: []Node{
@@ -785,6 +785,15 @@ func (r *InjectAgentInfoRule) Apply(agentInfo AgentInfo, ast *AST) (err error) {
785785
}}})
786786
addFieldsMap := &Dict{value: []Node{&Key{"add_fields", processorMap}}}
787787
processorsList.value = mergeStrategy("").InjectItem(processorsList.value, addFieldsMap)
788+
789+
// agent.id
790+
processorMap = &Dict{value: make([]Node, 0)}
791+
processorMap.value = append(processorMap.value, &Key{name: "target", value: &StrVal{value: "agent"}})
792+
processorMap.value = append(processorMap.value, &Key{name: "fields", value: &Dict{value: []Node{
793+
&Key{name: "id", value: &StrVal{value: agentInfo.AgentID()}},
794+
}}})
795+
addFieldsMap = &Dict{value: []Node{&Key{"add_fields", processorMap}}}
796+
processorsList.value = mergeStrategy("").InjectItem(processorsList.value, addFieldsMap)
788797
}
789798

790799
return nil

0 commit comments

Comments
 (0)