Skip to content

Commit

Permalink
chore(output.kinesis): Log kinesis consumer events (#15843)
Browse files Browse the repository at this point in the history
Co-authored-by: Mikhail <mikhail.k@flp.studio>
  • Loading branch information
mskonovalov and Mikhail authored Sep 16, 2024
1 parent 0ba7ce8 commit 336a5e2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 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,26 @@ func (k *KinesisConsumer) SetParser(parser telegraf.Parser) {
k.parser = parser
}

type TelegrafLoggerWrapper struct {
telegraf.Logger
}

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

func (t *TelegrafLoggerWrapper) Logf(classification logging.Classification, format string, v ...interface{}) {
switch classification {
case logging.Debug:
format = "DEBUG " + format
case logging.Warn:
format = "WARN" + format
default:
format = "INFO " + format
}
t.Logger.Tracef(format, v...)
}

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

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

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

0 comments on commit 336a5e2

Please sign in to comment.