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

[Elastic Agent] Add event.dataset to all events #20076

Merged
merged 3 commits into from
Jul 22, 2020
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
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@
- Will retry to enroll if the server return a 429. {pull}19918[19811]
- Allow to specify what artifacts to embed at build times {pull}20019[20019]
- Add --staging option to enroll command {pull}20026[20026]
- Add `event.dataset` to all events {pull}20076[20076]
24 changes: 24 additions & 0 deletions x-pack/elastic-agent/pkg/agent/operation/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ func (o *Operator) getMonitoringFilebeatConfig(output interface{}) (map[string]i
},
},
},
{
"add_fields": map[string]interface{}{
"target": "event",
"fields": map[string]interface{}{
"dataset": "elastic.agent",
},
},
},
},
},
}
Expand All @@ -224,6 +232,14 @@ func (o *Operator) getMonitoringFilebeatConfig(output interface{}) (map[string]i
},
},
},
{
"add_fields": map[string]interface{}{
"target": "event",
"fields": map[string]interface{}{
"dataset": fmt.Sprintf("elastic.agent.%s", name),
},
},
},
},
})
}
Expand Down Expand Up @@ -266,6 +282,14 @@ func (o *Operator) getMonitoringMetricbeatConfig(output interface{}) (map[string
},
},
},
{
"add_fields": map[string]interface{}{
"target": "event",
"fields": map[string]interface{}{
"dataset": fmt.Sprintf("elastic.agent.%s", name),
},
},
},
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ filebeat:
type: logs
name: generic
namespace: default
- add_fields:
target: "event"
fields:
dataset: generic
output:
elasticsearch:
hosts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ filebeat:
type: logs
name: generic
namespace: default
- add_fields:
target: "event"
fields:
dataset: generic
output:
elasticsearch:
enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ filebeat:
type: logs
name: generic
namespace: default
- add_fields:
target: "event"
fields:
dataset: generic
output:
elasticsearch:
hosts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ filebeat:
type: logs
name: generic
namespace: default
- add_fields:
target: "event"
fields:
dataset: generic
- type: log
paths:
- /var/log/hello3.log
Expand All @@ -28,6 +32,10 @@ filebeat:
type: testtype
name: generic
namespace: default
- add_fields:
target: "event"
fields:
dataset: generic
output:
elasticsearch:
hosts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ metricbeat:
type: metrics
name: docker.status
namespace: default
- add_fields:
target: "event"
fields:
dataset: docker.status
- module: docker
metricsets: [info]
index: metrics-generic-default
Expand All @@ -22,6 +26,10 @@ metricbeat:
type: metrics
name: generic
namespace: default
- add_fields:
target: "event"
fields:
dataset: generic
- module: apache
metricsets: [info]
index: metrics-generic-testing
Expand All @@ -36,6 +44,10 @@ metricbeat:
type: metrics
name: generic
namespace: testing
- add_fields:
target: "event"
fields:
dataset: generic

output:
elasticsearch:
Expand Down
9 changes: 8 additions & 1 deletion x-pack/elastic-agent/pkg/agent/transpiler/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,16 @@ func (r *InjectStreamProcessorRule) Apply(ast *AST) error {
&Key{name: "namespace", value: &StrVal{value: namespace}},
&Key{name: "name", value: &StrVal{value: dataset}},
}}})

addFieldsMap := &Dict{value: []Node{&Key{"add_fields", processorMap}}}
processorsList.value = mergeStrategy(r.OnConflict).InjectItem(processorsList.value, addFieldsMap)

processorMap = &Dict{value: make([]Node, 0)}
processorMap.value = append(processorMap.value, &Key{name: "target", value: &StrVal{value: "event"}})
processorMap.value = append(processorMap.value, &Key{name: "fields", value: &Dict{value: []Node{
&Key{name: "dataset", value: &StrVal{value: dataset}},
}}})
addFieldsMap = &Dict{value: []Node{&Key{"add_fields", processorMap}}}
processorsList.value = mergeStrategy(r.OnConflict).InjectItem(processorsList.value, addFieldsMap)
}
}

Expand Down