Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kafkaAcquisition: add more debug #2609

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions pkg/acquisition/modules/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ func (k *KafkaSource) UnmarshalConfig(yamlConfig []byte) error {
k.Config.Mode = configuration.TAIL_MODE
}

k.logger.Debugf("successfully unmarshaled kafka configuration : %+v", k.Config)

return err
}

func (k *KafkaSource) Configure(yamlConfig []byte, logger *log.Entry) error {
k.logger = logger

k.logger.Debugf("start configuring %s source", dataSourceName)

err := k.UnmarshalConfig(yamlConfig)
if err != nil {
return err
Expand All @@ -95,7 +99,7 @@ func (k *KafkaSource) Configure(yamlConfig []byte, logger *log.Entry) error {
return fmt.Errorf("cannot create %s dialer: %w", dataSourceName, err)
}

k.Reader, err = k.Config.NewReader(dialer)
k.Reader, err = k.Config.NewReader(dialer, k.logger)
if err != nil {
return fmt.Errorf("cannote create %s reader: %w", dataSourceName, err)
}
Expand All @@ -104,6 +108,8 @@ func (k *KafkaSource) Configure(yamlConfig []byte, logger *log.Entry) error {
return fmt.Errorf("cannot create %s reader", dataSourceName)
}

k.logger.Debugf("successfully configured %s source", dataSourceName)

return nil
}

Expand Down Expand Up @@ -143,6 +149,7 @@ func (k *KafkaSource) ReadMessage(out chan types.Event) error {
// Start processing from latest Offset
k.Reader.SetOffsetAt(context.Background(), time.Now())
for {
k.logger.Tracef("reading message from topic '%s'", k.Config.Topic)
m, err := k.Reader.ReadMessage(context.Background())
if err != nil {
if err == io.EOF {
Expand All @@ -158,6 +165,7 @@ func (k *KafkaSource) ReadMessage(out chan types.Event) error {
Process: true,
Module: k.GetName(),
}
k.logger.Tracef("line with message read from topic '%s': %+v", k.Config.Topic, l)
linesRead.With(prometheus.Labels{"topic": k.Config.Topic}).Inc()
var evt types.Event

Expand All @@ -171,6 +179,7 @@ func (k *KafkaSource) ReadMessage(out chan types.Event) error {
}

func (k *KafkaSource) RunReader(out chan types.Event, t *tomb.Tomb) error {
k.logger.Debugf("starting %s datasource reader goroutine with configuration %+v", dataSourceName, k.Config)
t.Go(func() error {
return k.ReadMessage(out)
})
Expand All @@ -188,7 +197,7 @@ func (k *KafkaSource) RunReader(out chan types.Event, t *tomb.Tomb) error {
}

func (k *KafkaSource) StreamingAcquisition(out chan types.Event, t *tomb.Tomb) error {
k.logger.Infof("start reader on topic '%s'", k.Config.Topic)
k.logger.Infof("start reader on brokers '%+v' with topic '%s'", k.Config.Brokers, k.Config.Topic)

t.Go(func() error {
defer trace.CatchPanic("crowdsec/acquis/kafka/live")
Expand Down Expand Up @@ -253,11 +262,13 @@ func (kc *KafkaConfiguration) NewDialer() (*kafka.Dialer, error) {
return dialer, nil
}

func (kc *KafkaConfiguration) NewReader(dialer *kafka.Dialer) (*kafka.Reader, error) {
func (kc *KafkaConfiguration) NewReader(dialer *kafka.Dialer, logger *log.Entry) (*kafka.Reader, error) {
rConf := kafka.ReaderConfig{
Brokers: kc.Brokers,
Topic: kc.Topic,
Dialer: dialer,
Brokers: kc.Brokers,
Topic: kc.Topic,
Dialer: dialer,
Logger: kafka.LoggerFunc(logger.Debugf),
ErrorLogger: kafka.LoggerFunc(logger.Errorf),
}
if kc.GroupID != "" {
rConf.GroupID = kc.GroupID
Expand Down
Loading