From 1b852fe17901b5989920f9cdf1996a29f3262533 Mon Sep 17 00:00:00 2001 From: Adi Muraru Date: Mon, 20 Sep 2021 14:23:25 +0300 Subject: [PATCH] [INTERNAL] Export number of members and assigned partitions for each topic in a consumer group ADDENDUM Lower cardinality by not exporting group size for un-stable groups --- prometheus/collect_consumer_groups.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/prometheus/collect_consumer_groups.go b/prometheus/collect_consumer_groups.go index 5fdde4d..f107679 100644 --- a/prometheus/collect_consumer_groups.go +++ b/prometheus/collect_consumer_groups.go @@ -53,12 +53,14 @@ func (e *Exporter) collectConsumerGroups(ctx context.Context, ch chan<- promethe ) // total number of members in consumer groups - ch <- prometheus.MustNewConstMetric( - e.consumerGroupMembers, - prometheus.GaugeValue, - float64(len(group.Members)), - group.Group, - ) + if len(group.Members) > 0 { + ch <- prometheus.MustNewConstMetric( + e.consumerGroupMembers, + prometheus.GaugeValue, + float64(len(group.Members)), + group.Group, + ) + } // iterate all members and build two maps: // - {topic -> number-of-consumers} @@ -103,7 +105,7 @@ func (e *Exporter) collectConsumerGroups(ctx context.Context, ch chan<- promethe } // number of members with no assignment in a stable consumer group - if membersWithEmptyAssignment > 0 { + if membersWithEmptyAssignment > 0 && group.State == "Stable" { ch <- prometheus.MustNewConstMetric( e.consumerGroupMembersEmpty, prometheus.GaugeValue,