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

Introduce event.duration and event.dataset for backward compatiblity #9393

Merged
merged 5 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ https://github.com/elastic/beats/compare/v6.5.0...6.x[Check the HEAD diff]
- Add setting to disable docker cpu metrics per core. {pull}9194[9194]
- The `elasticsearch/node` metricset now reports the Elasticsearch cluster UUID. {pull}8771[8771]
- Add `host.os.name` field to add_host_metadata processor. {issue}8948[8948] {pull}9405[9405]
- Add field `event.dataset` which is `{module}.{metricset).

*Packetbeat*

Expand All @@ -131,6 +132,8 @@ https://github.com/elastic/beats/compare/v6.5.0...6.x[Check the HEAD diff]

*Metricbeat*

- Deprecate field `metricset.rtt`. Replaced by `event.duration` which is in nano instead of micro seconds.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's no update to the definition for metricset.rtt to mark it as deprecated. I think it would make sense to add it in this PR. WDYT?

Copy link
Member Author

@ruflin ruflin Dec 11, 2018

Choose a reason for hiding this comment

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

Good point, added it to the fields definition.

*Packetbeat*

- Support new TLS version negotiation introduced in TLS 1.3. {issue}8647[8647].
Expand Down
10 changes: 10 additions & 0 deletions metricbeat/_meta/fields.common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@
example: elasticsearch
description: >
Name of the service metricbeat fetches the data from.

- name: event.duration
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why this is not named with the unit, like event.duration.ns?

Copy link
Member Author

Choose a reason for hiding this comment

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

This field comes from ECS: https://github.com/elastic/ecs#event

A more general note: I have second thoughts for how we deal with units in our current convention and hope in the future Elasticsearch can partially deal with it: elastic/elasticsearch#31244

type: long
description: >
Duration of the event in nano seconds.

- name: event.dataset
cwurm marked this conversation as resolved.
Show resolved Hide resolved
type: keyword
description: >
Event dataset name.
20 changes: 20 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,26 @@ example: elasticsearch
Name of the service metricbeat fetches the data from.


--

*`event.duration`*::
+
--
type: long

Duration of the event in nano seconds.


--

*`event.dataset`*::
+
--
type: keyword

Event dataset name.


--

[[exported-fields-couchbase]]
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/include/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion metricbeat/include/fields/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions metricbeat/mb/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package mb

import (
"fmt"
"time"

"github.com/elastic/beats/libbeat/beat"
Expand Down Expand Up @@ -116,14 +117,21 @@ func AddMetricSetInfo(module, metricset string, event *Event) {
if event.Host != "" {
info["host"] = event.Host
}
if event.Took > 0 {
info["rtt"] = event.Took / time.Microsecond
}

if event.Namespace != "" {
info["namespace"] = event.Namespace
}
info = common.MapStr{
"metricset": info,
"event": common.MapStr{
"dataset": fmt.Sprintf("%s.%s", module, metricset),
},
}

if event.Took > 0 {
// rtt is deprecated and will be removed in 7.0. Replaced by event.duration.
info.Put("metricset.rtt", event.Took/time.Microsecond)
info.Put("event.duration", event.Took/time.Nanosecond)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: here you have an innocuous race condition. The time.Nanosecond could happen later enough that trunc(event.duration) != metricset.rtt. It would be cleaner to populate event.duration, then truncate it to populate metricset.rtt.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure i can follow. event.Took is a value and it's not calculated here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, didn't look up what event.Took was, sorry. Never mind this :-)

}

if event.RootFields == nil {
Expand Down
7 changes: 7 additions & 0 deletions metricbeat/mb/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ func TestAddMetricSetInfo(t *testing.T) {
"name": metricSetName,
"rtt": time.Duration(500000),
},
"event": common.MapStr{
"duration": time.Duration(500000000),
"dataset": moduleName + "." + metricSetName,
},
}, e.RootFields)
})

Expand All @@ -193,6 +197,9 @@ func TestAddMetricSetInfo(t *testing.T) {
"module": moduleName,
"name": metricSetName,
},
"event": common.MapStr{
"dataset": moduleName + "." + metricSetName,
},
}, e.RootFields)
})
}
Expand Down
5 changes: 5 additions & 0 deletions metricbeat/mb/module/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func ExampleWrapper() {
defer wg.Done()
for event := range output {
event.Fields.Put("metricset.rtt", 111)
event.Fields.Put("event.duration", 111000)

output, err := encodeEvent(event)
if err == nil {
Expand All @@ -90,6 +91,10 @@ func ExampleWrapper() {
// "version": "1.2.3"
// },
// "@timestamp": "2016-05-10T23:27:58.485Z",
// "event": {
// "dataset": "fake.eventfetcher",
// "duration": 111000
// },
// "fake": {
// "eventfetcher": {
// "metric": 1
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/tests/system/metricbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from beat.beat import TestCase

COMMON_FIELDS = ["@timestamp", "beat", "metricset.name", "metricset.host",
"metricset.module", "metricset.rtt", "host.name"]
"metricset.module", "metricset.rtt", "host.name", "event"]

INTEGRATION_TESTS = os.environ.get('INTEGRATION_TESTS', False)

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/tests/system/test_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_drop_fields(self):
print(evt.keys())
self.assertItemsEqual(self.de_dot([
'beat', '@timestamp', 'system', 'metricset.module',
'metricset.rtt', 'metricset.name', 'host'
'metricset.rtt', 'metricset.name', 'host', 'event'
]), evt.keys())
cpu = evt["system"]["cpu"]
print(cpu.keys())
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/tests/system/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_module_processors(self):
Test local processors for Redis info event.
"""
fields = ["clients", "cpu"]
eventFields = ['beat', 'metricset']
eventFields = ['beat', 'metricset', 'event']
eventFields += ['redis.info.' + f for f in fields]
self.render_config_template(modules=[{
"name": "redis",
Expand Down