Skip to content

Commit 1f1fe71

Browse files
committed
fix disabling consumergroup or topic collection
1 parent 2d34cf1 commit 1f1fe71

File tree

7 files changed

+32
-10
lines changed

7 files changed

+32
-10
lines changed

docs/reference-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ minion:
9090
# take precedence over allowed groups.
9191
ignoredGroups: [ ]
9292
topics:
93+
# Enabled can be set to false in order to disable collecting any topic metrics.
94+
enabled: true
9395
# Granularity can be per topic or per partition. If you want to reduce the number of exported metric series and
9496
# you aren't interested in per partition metrics you could choose "topic".
9597
granularity: partition

go.sum

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,8 @@ golang.org/x/net v0.0.0-20220725212005-46097bf591d3/go.mod h1:AaygXjzTFtRAg2ttMY
366366
golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
367367
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
368368
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
369+
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
369370
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
370-
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
371-
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
372371
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
373372
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
374373
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

minion/config_topic_config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const (
1010
)
1111

1212
type TopicConfig struct {
13+
// Enabled can be set to false in order to not collect any topic metrics at all.
14+
Enabled bool `koanf:"enabled"`
15+
1316
// Granularity can be per topic or per partition. If you want to reduce the number of exported metric series and
1417
// you aren't interested in per partition metrics you could choose "topic".
1518
Granularity string `koanf:"granularity"`
@@ -60,6 +63,7 @@ func (c *TopicConfig) Validate() error {
6063

6164
// SetDefaults for topic config
6265
func (c *TopicConfig) SetDefaults() {
66+
c.Enabled = true
6367
c.Granularity = TopicGranularityPartition
6468
c.AllowedTopics = []string{"/.*/"}
6569
c.InfoMetric = InfoMetricConfig{ConfigKeys: []string{"cleanup.policy"}}

minion/service.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import (
1010
"sync"
1111
"time"
1212

13-
"github.com/cloudhut/kminion/v2/kafka"
1413
"github.com/twmb/franz-go/pkg/kgo"
1514
"github.com/twmb/franz-go/pkg/kmsg"
1615
"github.com/twmb/franz-go/pkg/kversion"
1716
"go.uber.org/zap"
1817
"golang.org/x/sync/singleflight"
18+
19+
"github.com/cloudhut/kminion/v2/kafka"
1920
)
2021

2122
type Service struct {
@@ -47,7 +48,7 @@ func NewService(cfg Config, logger *zap.Logger, kafkaSvc *kafka.Service, metrics
4748
kgoOpts := []kgo.Opt{
4849
kgo.WithHooks(minionHooks),
4950
}
50-
if cfg.ConsumerGroups.ScrapeMode == ConsumerGroupScrapeModeOffsetsTopic {
51+
if cfg.ConsumerGroups.Enabled && cfg.ConsumerGroups.ScrapeMode == ConsumerGroupScrapeModeOffsetsTopic {
5152
kgoOpts = append(kgoOpts,
5253
kgo.ConsumeResetOffset(kgo.NewOffset().AtStart()),
5354
kgo.ConsumeTopics("__consumer_offsets"))
@@ -94,7 +95,7 @@ func (s *Service) Start(ctx context.Context) error {
9495
return fmt.Errorf("failed to check feature compatibility against Kafka: %w", err)
9596
}
9697

97-
if s.Cfg.ConsumerGroups.ScrapeMode == ConsumerGroupScrapeModeOffsetsTopic {
98+
if s.Cfg.ConsumerGroups.Enabled && s.Cfg.ConsumerGroups.ScrapeMode == ConsumerGroupScrapeModeOffsetsTopic {
9899
go s.startConsumingOffsets(ctx)
99100
}
100101

prometheus/collect_consumer_group_lags.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package prometheus
22

33
import (
44
"context"
5-
"github.com/cloudhut/kminion/v2/minion"
5+
"math"
6+
"strconv"
7+
68
"github.com/prometheus/client_golang/prometheus"
79
"github.com/twmb/franz-go/pkg/kerr"
810
"github.com/twmb/franz-go/pkg/kmsg"
911
"go.uber.org/zap"
10-
"math"
11-
"strconv"
12+
13+
"github.com/cloudhut/kminion/v2/minion"
1214
)
1315

1416
type waterMark struct {
@@ -19,6 +21,10 @@ type waterMark struct {
1921
}
2022

2123
func (e *Exporter) collectConsumerGroupLags(ctx context.Context, ch chan<- prometheus.Metric) bool {
24+
if !e.minionSvc.Cfg.ConsumerGroups.Enabled {
25+
return true
26+
}
27+
2228
// Low Watermarks (at the moment they are not needed at all, they could be used to calculate the lag on partitions
2329
// that don't have any active offsets)
2430
lowWaterMarks, err := e.minionSvc.ListOffsetsCached(ctx, -2)

prometheus/collect_topic_info.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import (
1010
)
1111

1212
func (e *Exporter) collectTopicInfo(ctx context.Context, ch chan<- prometheus.Metric) bool {
13+
if !e.minionSvc.Cfg.Topics.Enabled {
14+
return true
15+
}
16+
1317
metadata, err := e.minionSvc.GetMetadataCached(ctx)
1418
if err != nil {
1519
e.logger.Error("failed to get metadata", zap.Error(err))

prometheus/collect_topic_partition_offsets.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ package prometheus
22

33
import (
44
"context"
5-
"github.com/cloudhut/kminion/v2/minion"
5+
"strconv"
6+
67
"github.com/prometheus/client_golang/prometheus"
78
"github.com/twmb/franz-go/pkg/kerr"
89
"go.uber.org/zap"
9-
"strconv"
10+
11+
"github.com/cloudhut/kminion/v2/minion"
1012
)
1113

1214
func (e *Exporter) collectTopicPartitionOffsets(ctx context.Context, ch chan<- prometheus.Metric) bool {
15+
if !e.minionSvc.Cfg.Topics.Enabled {
16+
return true
17+
}
18+
1319
isOk := true
1420

1521
// Low Watermarks

0 commit comments

Comments
 (0)