Skip to content

Commit

Permalink
[Elastic Agent] Add event.dataset to all events (elastic#20076)
Browse files Browse the repository at this point in the history
* Inject add_fields event.dataset along side dataset.

* Add event.dataset to all published events.

* Add changelog.
  • Loading branch information
blakerouse authored and melchiormoulin committed Oct 14, 2020
1 parent 02ab2b8 commit 5acd447
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,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

0 comments on commit 5acd447

Please sign in to comment.