Skip to content

Commit

Permalink
Switch to RoundRobbinBalancer
Browse files Browse the repository at this point in the history
  • Loading branch information
cyriltovena committed Dec 20, 2024
1 parent f2d524f commit 4a8a644
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/usage/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,18 @@ func NewService(kafkaCfg kafka.Config, consumerGroup string, logger log.Logger,
client, err := client.NewReaderClient(kafkaCfg, kprom, logger,
kgo.ConsumerGroup(consumerGroup),
kgo.ConsumeTopics(topic),
kgo.Balancers(kgo.RoundRobinBalancer()),
kgo.ConsumeResetOffset(kgo.NewOffset().AfterMilli(time.Now().Add(-windowSize).UnixMilli())),
kgo.DisableAutoCommit(),
kgo.OnPartitionsAssigned(func(_ context.Context, _ *kgo.Client, partitions map[string][]int32) {
level.Info(logger).Log("msg", "assigned partitions", "partitions", partitions)
}),
kgo.OnPartitionsRevoked(func(_ context.Context, _ *kgo.Client, partitions map[string][]int32) {
level.Info(logger).Log("msg", "revoked partitions", "partitions", partitions)
}),
kgo.OnPartitionsLost(func(_ context.Context, _ *kgo.Client, partitions map[string][]int32) {
level.Info(logger).Log("msg", "lost partitions", "partitions", partitions)
}),
)
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions pkg/usage/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func (u *usageStats) addEntry(partition int32, tenantID string, streamHash uint6
u.stats[partition] = pStats
}

// If the partition has already processed this offset, skip it
if pStats.offset != 0 && pStats.offset >= offset {
return
}

pStats.offset = offset
pStats.timestamp = timestamp

Expand Down

0 comments on commit 4a8a644

Please sign in to comment.