Skip to content

Commit

Permalink
Add kafka fields needed for dashboards (#8504)
Browse files Browse the repository at this point in the history
Kafka dashboards calculate cardinalities of composed
fields, this is expensive in query time, but can be optimized if the
composed fields are precalculated.

Continues with #7767, needed for #8457.

(cherry picked from commit 78ef120)
  • Loading branch information
jsoriano committed Oct 18, 2018
1 parent 8bc6101 commit c7bc9fa
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ https://github.com/elastic/beats/compare/v6.4.0...6.x[Check the HEAD diff]
- Support for Kafka 2.0.0 {pull}8399[8399]
- Added support for query params in configuration {issue}8286[8286] {pull}8292[8292]
- Add container image for docker metricsets. {issue}8214[8214] {pull}8438[8438]
- Precalculate composed id fields for kafka dashboards. {pull}8504[8504]

*Packetbeat*

Expand Down
18 changes: 18 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7108,6 +7108,24 @@ type: long
Partition id.
--
*`kafka.partition.topic_id`*::
+
--
type: keyword
Unique id of the partition in the topic.
--
*`kafka.partition.topic_broker_id`*::
+
--
type: keyword
Unique id of the partition in the topic and the broker.
--
[float]
Expand Down
10 changes: 10 additions & 0 deletions metricbeat/module/kafka/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@
type: long
description: >
Partition id.
- name: partition.topic_id
type: keyword
description:
Unique id of the partition in the topic.

- name: partition.topic_broker_id
type: keyword
description:
Unique id of the partition in the topic and the broker.
7 changes: 4 additions & 3 deletions metricbeat/module/kafka/consumergroup/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"client": {
"host": "172.18.0.1",
"id": "sarama",
"member_id": "sarama-714cfb8b-39e5-4128-9109-e5056c5e8f56"
"member_id": "sarama-fcb5a5db-0474-4f3a-a5af-29e2f14549c5"
},
"error": {
"code": 0
Expand All @@ -29,7 +29,8 @@
"topic": "metricbeat-test"
},
"partition": {
"id": 0
"id": 0,
"topic_id": "0-metricbeat-test"
},
"topic": {
"name": "metricbeat-test"
Expand All @@ -41,4 +42,4 @@
"name": "consumergroup",
"rtt": 115
}
}
}
7 changes: 6 additions & 1 deletion metricbeat/module/kafka/consumergroup/consumergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package consumergroup

import (
"crypto/tls"
"fmt"

"github.com/pkg/errors"

Expand Down Expand Up @@ -111,6 +112,9 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
}

emitEvent := func(event common.MapStr) {
// Helpful IDs to avoid scripts on queries
partitionTopicID := fmt.Sprintf("%d-%s", event["partition"], event["topic"])

// TODO (deprecation): Remove fields from MetricSetFields moved to ModuleFields
event["broker"] = brokerInfo
r.Event(mb.Event{
Expand All @@ -120,7 +124,8 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
"name": event["topic"],
},
"partition": common.MapStr{
"id": event["partition"],
"id": event["partition"],
"topic_id": partitionTopicID,
},
},
MetricSetFields: event,
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/kafka/fields.go

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

9 changes: 6 additions & 3 deletions metricbeat/module/kafka/partition/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"address": "172.18.0.2:9092",
"id": 0
},
"id": 0,
"offset": {
"newest": 0,
"oldest": 0
Expand All @@ -26,11 +27,13 @@
"replica": 0
},
"topic": {
"name": "foo-1532945633-185372965"
}
"name": "foo-1538389014-739473801"
},
"topic_broker_id": "0-foo-1538389014-739473801-0",
"topic_id": "0-foo-1538389014-739473801"
},
"topic": {
"name": "foo-1532945633-185372965"
"name": "foo-1538389014-739473801"
}
},
"metricset": {
Expand Down
13 changes: 10 additions & 3 deletions metricbeat/module/kafka/partition/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package partition
import (
"crypto/tls"
"errors"
"fmt"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/cfgwarn"
Expand Down Expand Up @@ -167,8 +168,17 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
}
}

// Helpful IDs to avoid scripts on queries
partitionTopicID := fmt.Sprintf("%d-%s", partition.ID, topic.Name)
partitionTopicBrokerID := fmt.Sprintf("%s-%d", partitionTopicID, id)

// create event
event := common.MapStr{
// Common `kafka.partition` fields
"id": partition.ID,
"topic_id": partitionTopicID,
"topic_broker_id": partitionTopicBrokerID,

"topic": evtTopic,
"broker": evtBroker,
"partition": partitionEvent,
Expand All @@ -183,9 +193,6 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
ModuleFields: common.MapStr{
"broker": evtBroker,
"topic": evtTopic,
"partition": common.MapStr{
"id": partition.ID,
},
},
MetricSetFields: event,
})
Expand Down

0 comments on commit c7bc9fa

Please sign in to comment.