Skip to content
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 @@ -68,3 +68,4 @@
- Use shorter hash for application differentiator {pull}18770[18770]
- When not port are specified and the https is used fallback to 443 {pull}18844[18844]
- Agent verifies packages before using them {pull}18876[18876]
- Change stream.* to dataset.* fields {pull}18967[18967]
24 changes: 22 additions & 2 deletions x-pack/elastic-agent/pkg/agent/operation/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,17 @@ func (o *Operator) getMonitoringFilebeatConfig(output interface{}) (map[string]i
"paths": paths,
"index": "logs-agent-default",
"processors": []map[string]interface{}{
map[string]interface{}{
{
"add_fields": map[string]interface{}{
"target": "dataset",
"fields": map[string]interface{}{
"type": "logs",
"name": "agent",
"namespace": "default",
},
},
},
{
"add_fields": map[string]interface{}{
"target": "stream",
"fields": map[string]interface{}{
Expand Down Expand Up @@ -220,7 +230,17 @@ func (o *Operator) getMonitoringMetricbeatConfig(output interface{}) (map[string
"hosts": hosts,
"index": "metrics-agent-default",
"processors": []map[string]interface{}{
map[string]interface{}{
{
"add_fields": map[string]interface{}{
"target": "dataset",
"fields": map[string]interface{}{
"type": "metrics",
"name": "agent",
"namespace": "default",
},
},
},
{
"add_fields": map[string]interface{}{
"target": "stream",
"fields": map[string]interface{}{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ filebeat:
dataset: generic
index: logs-generic-default
processors:
- add_fields:
target: "dataset"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There a small thing missing here: dataset.dataset need to be changed for dataset.name, this will create these fields:

  1. dataset.type
  2. dataset.name
  3. dataset.namespace.

@michalpristas @ruflin The field in the agent configuration will also need to changes? Meaning we will need to adjust the index name generation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in configuration i would expect this

datasources:
  - namespace: testing
    use_output: default
    inputs:
    - type: docker/metrics
      streams:
        - metricset: status
          dataset: docker.status

to become this

datasources:
  - namespace: testing
    use_output: default
    inputs:
    - type: docker/metrics
      datasets:
        - metricset: status
          name: docker.status

is that correct?
but this feels weird as you can have

datasources:
  - namespace: testing
    use_output: default
    inputs:
    - type: docker/metrics
      datasets:
        - metricset: status
          name: docker.status
        - metricset: cpu
          name: docker.status

i dont recall if we agreed to handle configuration change as a separate pack of PRs or the same with this one @ruflin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michalpristas Please handle config changes as a separate PR as it also has effects in Kibana. I plan to open an issue for this. These config changes we should directly in combination with the potential removal of datasources.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and it does not work as expected. The result is:

          "dataset" : {
            "type" : "metrics",
            "dataset" : "system.cpu",
            "namespace" : "default"
          },

But it should be

          "dataset" : {
            "type" : "metrics",
            "name" : "system.cpu",
            "namespace" : "default"
          },

I think the reason is on line 14 where it still states dataset instead of name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right

fields:
type: logs
name: generic
namespace: default
- add_fields:
target: "stream"
fields:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ filebeat:
dataset: generic
index: logs-generic-default
processors:
- add_fields:
target: "dataset"
fields:
type: logs
name: generic
namespace: default
- add_fields:
target: "stream"
fields:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ filebeat:
dataset: generic
index: logs-generic-default
processors:
- add_fields:
target: "dataset"
fields:
type: logs
name: generic
namespace: default
- add_fields:
target: "stream"
fields:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ filebeat:
vars:
var: value
processors:
- add_fields:
target: "dataset"
fields:
type: logs
name: generic
namespace: default
- add_fields:
target: "stream"
fields:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ metricbeat:
index: metrics-docker.status-default
hosts: ["http://127.0.0.1:8080"]
processors:
- add_fields:
target: "dataset"
fields:
type: metrics
name: docker.status
namespace: default
- add_fields:
target: "stream"
fields:
Expand All @@ -16,6 +22,12 @@ metricbeat:
index: metrics-generic-default
hosts: ["http://127.0.0.1:8080"]
processors:
- add_fields:
target: "dataset"
fields:
type: metrics
name: generic
namespace: default
- add_fields:
target: "stream"
fields:
Expand All @@ -30,12 +42,19 @@ metricbeat:
- add_fields:
fields:
should_be: first
- add_fields:
target: "dataset"
fields:
type: metrics
name: generic
namespace: testing
- add_fields:
target: "stream"
fields:
type: metrics
dataset: generic
namespace: testing

output:
elasticsearch:
hosts: [127.0.0.1:9200, 127.0.0.1:9300]
Expand Down
18 changes: 16 additions & 2 deletions x-pack/elastic-agent/pkg/agent/transpiler/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,29 @@ func (r *InjectStreamProcessorRule) Apply(ast *AST) error {
}

processorMap := &Dict{value: make([]Node, 0)}
processorMap.value = append(processorMap.value, &Key{name: "target", value: &StrVal{value: "stream"}})
processorMap.value = append(processorMap.value, &Key{name: "target", value: &StrVal{value: "dataset"}})
processorMap.value = append(processorMap.value, &Key{name: "fields", value: &Dict{value: []Node{
&Key{name: "type", value: &StrVal{value: r.Type}},
&Key{name: "namespace", value: &StrVal{value: namespace}},
&Key{name: "dataset", value: &StrVal{value: dataset}},
&Key{name: "name", value: &StrVal{value: dataset}},
}}})

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

// add this for backwards compatibility remove later
streamProcessorMap := &Dict{value: make([]Node, 0)}
streamProcessorMap.value = append(streamProcessorMap.value, &Key{name: "target", value: &StrVal{value: "stream"}})
streamProcessorMap.value = append(streamProcessorMap.value, &Key{name: "fields", value: &Dict{value: []Node{
&Key{name: "type", value: &StrVal{value: r.Type}},
&Key{name: "namespace", value: &StrVal{value: namespace}},
&Key{name: "dataset", value: &StrVal{value: dataset}},
}}})

streamAddFieldsMap := &Dict{value: []Node{&Key{"add_fields", streamProcessorMap}}}

processorsList.value = mergeStrategy(r.OnConflict).InjectItem(processorsList.value, streamAddFieldsMap)
// end of backward compatibility section
}
}
}
Expand Down