Skip to content

Commit

Permalink
chore: log kinesis consumer events
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail committed Sep 4, 2024
1 parent 88bca70 commit 0591228
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions plugins/inputs/kinesis_consumer/kinesis_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
"sync"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/kinesis"
"github.com/aws/smithy-go/logging"
consumer "github.com/harlow/kinesis-consumer"
"github.com/harlow/kinesis-consumer/store/ddb"

Expand Down Expand Up @@ -89,6 +91,25 @@ func (k *KinesisConsumer) SetParser(parser telegraf.Parser) {
k.parser = parser
}

type TelegrafLoggerWrapper struct {
telegraf.Logger
}

func (t *TelegrafLoggerWrapper) Log(args ...interface{}) {
t.Debug(args)
}

func (t *TelegrafLoggerWrapper) Logf(classification logging.Classification, format string, v ...interface{}) {
switch classification {
case logging.Debug:
t.Logger.Debugf(format, v...)
case logging.Warn:
t.Logger.Warnf(format, v...)
default:
t.Logger.Infof(format, v...)
}
}

func (k *KinesisConsumer) connect(ac telegraf.Accumulator) error {
cfg, err := k.CredentialConfig.Credentials()
if err != nil {
Expand All @@ -98,6 +119,9 @@ func (k *KinesisConsumer) connect(ac telegraf.Accumulator) error {
if k.EndpointURL != "" {
cfg.BaseEndpoint = &k.EndpointURL
}

cfg.Logger = &TelegrafLoggerWrapper{k.Log}
cfg.ClientLogMode = aws.LogRetries
client := kinesis.NewFromConfig(cfg)

k.checkpoint = &noopStore{}
Expand All @@ -119,6 +143,7 @@ func (k *KinesisConsumer) connect(ac telegraf.Accumulator) error {
consumer.WithClient(client),
consumer.WithShardIteratorType(k.ShardIteratorType),
consumer.WithStore(k),
consumer.WithLogger(&TelegrafLoggerWrapper{k.Log}),
)
if err != nil {
return err
Expand Down

0 comments on commit 0591228

Please sign in to comment.