Files
akvorado/common/kafka/logs.go
Vincent Bernat 756e4a8fbd */kafka: switch to franz-go
The concurrency of this library is easier to handle than Sarama.
Notably, it is more compatible with the new model of "almost share
nothing" we use for the inlet and the outlet. The lock for workers in
outlet is removed. We can now use sync.Pool to allocate slice of bytes
in inlet.

It may also be more performant.

In the future, we may want to commit only when pushing data to
ClickHouse. However, this does not seem easy when there is a rebalance.
In case of rebalance, we need to do something when a partition is
revoked to avoid duplicating data. For example, we could flush the
current batch to ClickHouse. Have a look at the
`example/mark_offsets/main.go` file in franz-go repository for a
possible approach. In the meantime, we rely on autocommit.

Another contender could be https://github.com/segmentio/kafka-go. Also
see https://github.com/twmb/franz-go/pull/1064.
2025-07-27 21:44:28 +02:00

44 lines
1017 B
Go

// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
package kafka
import (
"github.com/twmb/franz-go/pkg/kgo"
"akvorado/common/helpers"
"akvorado/common/reporter"
)
// kafkaLogger implements kgo.Logger interface.
type kafkaLogger struct {
r *reporter.Reporter
}
// NewLogger creates a new kafka logger using the provided reporter.
func NewLogger(r *reporter.Reporter) kgo.Logger {
return &kafkaLogger{r: r}
}
// Level returns the current log level.
func (l *kafkaLogger) Level() kgo.LogLevel {
if !helpers.Testing() {
return kgo.LogLevelInfo
}
return kgo.LogLevelDebug
}
// Log logs a message at the specified level.
func (l *kafkaLogger) Log(level kgo.LogLevel, msg string, keyvals ...any) {
switch level {
case kgo.LogLevelError:
l.r.Error().Fields(keyvals).Msg(msg)
case kgo.LogLevelWarn:
l.r.Warn().Fields(keyvals).Msg(msg)
case kgo.LogLevelInfo:
l.r.Info().Fields(keyvals).Msg(msg)
case kgo.LogLevelDebug:
l.r.Debug().Fields(keyvals).Msg(msg)
}
}