From f387a4169ca5a375e6deed03304c24309bd6b78d 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 438dae6..fdcc90f 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} @@ -108,7 +110,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,