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

feat: add counter metrics for consumer group join/sync and their failures #2003

Merged
merged 1 commit into from
Sep 7, 2021
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
40 changes: 40 additions & 0 deletions consumer_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"sort"
"sync"
"time"

"github.com/rcrowley/go-metrics"
)

// ErrClosedConsumerGroup is the error returned when a method is called on a consumer group that has been closed.
Expand Down Expand Up @@ -212,12 +214,38 @@ func (c *consumerGroup) newSession(ctx context.Context, topics []string, handler
return c.retryNewSession(ctx, topics, handler, retries, true)
}

var (
metricRegistry = c.config.MetricRegistry
consumerGroupJoinTotal metrics.Counter
consumerGroupJoinFailed metrics.Counter
consumerGroupSyncTotal metrics.Counter
consumerGroupSyncFailed metrics.Counter
)

if metricRegistry != nil {
consumerGroupJoinTotal = metrics.GetOrRegisterCounter(fmt.Sprintf("consumer-group-join-total-%s", c.groupID), metricRegistry)
consumerGroupJoinFailed = metrics.GetOrRegisterCounter(fmt.Sprintf("consumer-group-join-failed-%s", c.groupID), metricRegistry)
consumerGroupSyncTotal = metrics.GetOrRegisterCounter(fmt.Sprintf("consumer-group-sync-total-%s", c.groupID), metricRegistry)
consumerGroupSyncFailed = metrics.GetOrRegisterCounter(fmt.Sprintf("consumer-group-sync-failed-%s", c.groupID), metricRegistry)
}

// Join consumer group
join, err := c.joinGroupRequest(coordinator, topics)
if consumerGroupJoinTotal != nil {
consumerGroupJoinTotal.Inc(1)
}
if err != nil {
_ = coordinator.Close()
if consumerGroupJoinFailed != nil {
consumerGroupJoinFailed.Inc(1)
}
return nil, err
}
if join.Err != ErrNoError {
if consumerGroupJoinFailed != nil {
consumerGroupJoinFailed.Inc(1)
}
}
switch join.Err {
case ErrNoError:
c.memberID = join.MemberId
Expand Down Expand Up @@ -256,10 +284,22 @@ func (c *consumerGroup) newSession(ctx context.Context, topics []string, handler

// Sync consumer group
groupRequest, err := c.syncGroupRequest(coordinator, plan, join.GenerationId)
if consumerGroupSyncTotal != nil {
consumerGroupSyncTotal.Inc(1)
}
if err != nil {
_ = coordinator.Close()
if consumerGroupSyncFailed != nil {
consumerGroupSyncFailed.Inc(1)
}
return nil, err
}
if groupRequest.Err != ErrNoError {
if consumerGroupSyncFailed != nil {
consumerGroupSyncFailed.Inc(1)
}
}

switch groupRequest.Err {
case ErrNoError:
case ErrUnknownMemberId, ErrIllegalGeneration: // reset member ID and retry immediately
Expand Down
4 changes: 4 additions & 0 deletions sarama.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ Consumer related metrics:
| Name | Type | Description |
+-------------------------------------------+------------+--------------------------------------------------------------------------------------+
| consumer-batch-size | histogram | Distribution of the number of messages in a batch |
| consumer-group-join-total-<GroupID> | counter | Total count of consumer group join attempts |
| consumer-group-join-failed-<GroupID> | counter | Total count of consumer group join failures |
| consumer-group-sync-total-<GroupID> | counter | Total count of consumer group sync attempts |
| consumer-group-sync-failed-<GroupID> | counter | Total count of consumer group sync failures |
+-------------------------------------------+------------+--------------------------------------------------------------------------------------+

*/
Expand Down