-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add kafka common fields at the module level #7767
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c2a07c1
Metricbeat: Move common kafka fields to the module level
jsoriano f93a014
Add kafka consumergroup integration test
jsoriano b16057d
Added comment
jsoriano 730c2a3
Extended description of change in changelog
jsoriano eb87b1f
Consumer group created, still no metrics
jsoriano a367375
Use sarama-cluster to create the consumer
jsoriano f87c08e
Fix notice for sarama-cluster
jsoriano f823976
Used advertised address for kafka.broker.address
jsoriano 1ac6cf7
Merge remote-tracking branch 'origin/master' into kafka-common-fields
jsoriano 27e3f1d
Set deprecation versions
jsoriano 7ca1bc8
Fix changelog
jsoriano 5cb5d04
Merge remote-tracking branch 'origin/master' into kafka-common-fields
jsoriano 1a78eb0
Merge remote-tracking branch 'origin/master' into kafka-common-fields
jsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,44 @@ | ||
{ | ||
"@timestamp":"2016-05-23T08:05:34.853Z", | ||
"type":"metricsets", | ||
"beat":{ | ||
"hostname":"localhost", | ||
"name":"localhost", | ||
"version": "6.0.0-alpha1" | ||
"@timestamp": "2017-10-12T08:05:34.853Z", | ||
"beat": { | ||
"hostname": "host.example.com", | ||
"name": "host.example.com" | ||
}, | ||
"metricset":{ | ||
"host":"localhost", | ||
"module":"kafka", | ||
"name":"consumergroup", | ||
"rtt":269 | ||
}, | ||
"kafka":{ | ||
"consumergroup":{ | ||
"id": "group", | ||
"topic": "test", | ||
"partition": 0, | ||
"client": { | ||
"host": "127.0.0.1", | ||
"id": "client0", | ||
"member_id": "client0-d20b677a-5740-433e-a7f8-fbdab1f0f150" | ||
}, | ||
"kafka": { | ||
"broker": { | ||
"address": "172.18.0.2:9092", | ||
"id": 0 | ||
}, | ||
"consumergroup": { | ||
"broker": { | ||
"address": "kafka0:9092", | ||
"address": "172.18.0.2:9092", | ||
"id": 0 | ||
}, | ||
"client": { | ||
"host": "172.18.0.1", | ||
"id": "sarama", | ||
"member_id": "sarama-714cfb8b-39e5-4128-9109-e5056c5e8f56" | ||
}, | ||
"error": { | ||
"code": 0 | ||
"code": 0 | ||
}, | ||
"id": "test-group", | ||
"meta": "", | ||
"offset": 0 | ||
"offset": -1, | ||
"partition": 0, | ||
"topic": "metricbeat-test" | ||
}, | ||
"partition": { | ||
"id": 0 | ||
}, | ||
"topic": { | ||
"name": "metricbeat-test" | ||
} | ||
}, | ||
"metricset": { | ||
"host": "kafka:9092", | ||
"module": "kafka", | ||
"name": "consumergroup", | ||
"rtt": 115 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ package consumergroup | |
import ( | ||
"crypto/tls" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/common/cfgwarn" | ||
"github.com/elastic/beats/libbeat/common/transport/tlscommon" | ||
|
@@ -95,25 +97,37 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { | |
}, nil | ||
} | ||
|
||
func (m *MetricSet) Fetch() ([]common.MapStr, error) { | ||
// Fetch consumer group metrics from kafka | ||
func (m *MetricSet) Fetch(r mb.ReporterV2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method MetricSet.Fetch should have comment or be unexported |
||
if err := m.broker.Connect(); err != nil { | ||
logp.Err("broker connect failed: %v", err) | ||
return nil, err | ||
r.Error(errors.Wrap(err, "broker connection failed")) | ||
return | ||
} | ||
|
||
b := m.broker | ||
defer b.Close() | ||
defer m.broker.Close() | ||
|
||
brokerInfo := common.MapStr{ | ||
"id": b.ID(), | ||
"address": b.AdvertisedAddr(), | ||
"id": m.broker.ID(), | ||
"address": m.broker.AdvertisedAddr(), | ||
} | ||
|
||
var events []common.MapStr | ||
emitEvent := func(event common.MapStr) { | ||
// TODO (deprecation): Remove fields from MetricSetFields moved to ModuleFields | ||
event["broker"] = brokerInfo | ||
events = append(events, event) | ||
r.Event(mb.Event{ | ||
ModuleFields: common.MapStr{ | ||
"broker": brokerInfo, | ||
"topic": common.MapStr{ | ||
"name": event["topic"], | ||
}, | ||
"partition": common.MapStr{ | ||
"id": event["partition"], | ||
}, | ||
}, | ||
MetricSetFields: event, | ||
}) | ||
} | ||
err := fetchGroupInfo(emitEvent, m.broker, m.groups.pred(), m.topics.pred()) | ||
if err != nil { | ||
r.Error(err) | ||
} | ||
err := fetchGroupInfo(emitEvent, b, m.groups.pred(), m.topics.pred()) | ||
return events, err | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, in my laptop the broker address is different for consumergroup and partition metricsets, this is not good for correlations 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using advertised address in both metricsets now, so it can be more easily used for correlations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct behavior. In kafka a broker can fulfill a many tasks. E.g. being the leader of a partition producers write to, or manage a consumer group. Consumer groups can be handled by very different brokers. Yet, the consumer group index used to store committed offsets from consumers is another internal "topic" potentially owned by yet another broker. State is very localized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the problem was that in one metricset we were using the address we use to connect, and on the other the advertised address, so the broker was the same, but different addresses were being collected.