@@ -11,15 +11,16 @@ import (
1111 "context"
1212 "crypto/tls"
1313 "database/sql"
14- "encoding/json"
1514 "fmt"
1615 "log"
1716 "net/http"
1817
1918 "github.com/ClickHouse/clickhouse-go/v2"
2019 "github.com/twmb/franz-go/pkg/kgo"
21- "github.com/twmb/franz-go/pkg/sasl/scram "
20+ "github.com/twmb/franz-go/pkg/sasl/aws "
2221 "github.com/twmb/franz-go/plugin/kprom"
22+
23+ awsconfig "github.com/aws/aws-sdk-go-v2/config"
2324)
2425
2526type EnricherOption func (* Enricher )
@@ -160,11 +161,31 @@ func (e *Enricher) Run(ctx context.Context) error {
160161 rpOpts := []kgo.Opt {}
161162 rpOpts = append (rpOpts ,
162163 kgo .SeedBrokers (e .rpBroker ),
163- kgo .SASL (scram.Auth {User : e .rpUser , Pass : e .rpPass }.AsSha256Mechanism ()),
164+ //kgo.SASL(scram.Auth{User: e.rpUser, Pass: e.rpPass}.AsSha256Mechanism()),
165+ kgo .SASL (aws .ManagedStreamingIAM (func (ctx context.Context ) (aws.Auth , error ) {
166+ cfg , err := awsconfig .LoadDefaultConfig (ctx )
167+ if err != nil {
168+ return aws.Auth {}, fmt .Errorf ("failed to load aws config: %w" , err )
169+ }
170+
171+ // Retrieve the temporary credentials
172+ creds , err := cfg .Credentials .Retrieve (ctx )
173+ if err != nil {
174+ return aws.Auth {}, fmt .Errorf ("failed to retrieve credentials: %w" , err )
175+ }
176+
177+ // Return them in the format franz-go expects
178+ return aws.Auth {
179+ AccessKey : creds .AccessKeyID ,
180+ SecretKey : creds .SecretAccessKey ,
181+ SessionToken : creds .SessionToken ,
182+ }, nil
183+ })),
164184 kgo .SeedBrokers (e .rpBroker ),
165185 kgo .ConsumeTopics (e .rpConsumerTopic ),
166186 kgo .ConsumerGroup (e .rpConsumerGroup ),
167187 kgo .ConsumeResetOffset (kgo .NewOffset ().AtStart ()),
188+ kgo .DialTLS (),
168189 )
169190 if e .rpTLS {
170191 rpOpts = append (rpOpts , kgo .DialTLSConfig (new (tls.Config )))
@@ -176,7 +197,7 @@ func (e *Enricher) Run(ctx context.Context) error {
176197
177198 go func () {
178199 http .Handle ("/metrics" , metrics .Handler ())
179- log .Fatal (http .ListenAndServe ("localhost:8888 " , nil ))
200+ log .Fatal (http .ListenAndServe ("localhost:2112 " , nil ))
180201 }()
181202 }
182203
@@ -209,32 +230,33 @@ func (e *Enricher) Run(ctx context.Context) error {
209230 })
210231 fetches .EachRecord (func (record * kgo.Record ) {
211232 // unmarshal flow record
212- flow := & FlowSample {}
213- err := json .Unmarshal (record .Value , flow )
214- if err != nil {
215- log .Printf ("error unmarshalling flow record: %v" , err )
216- return
217- }
218- // annotate flow record
219- for _ , a := range e .annotators {
220- if err := a .Annotate (flow ); err != nil {
221- log .Printf ("error annotating flow with %s: %v" , a .String (), err )
222- }
223- }
224- // write flow record back onto topic
225- body , err := json .Marshal (flow )
226- if err != nil {
227- log .Printf ("error marshaling enriched record to json: %v" , err )
228- return
229- }
230- record .Topic = e .rpProducerTopic
231- record .Value = body
232- client .Produce (ctx , record , func (record * kgo.Record , err error ) {
233- if err != nil {
234- // TODO: metric
235- fmt .Printf ("error producing message to redpanda: %v \n " , err )
236- }
237- })
233+ log .Println ("received record for enrichment" )
234+ // flow := &FlowSample{}
235+ // err := json.Unmarshal(record.Value, flow)
236+ // if err != nil {
237+ // log.Printf("error unmarshalling flow record: %v", err)
238+ // return
239+ // }
240+ // // annotate flow record
241+ // for _, a := range e.annotators {
242+ // if err := a.Annotate(flow); err != nil {
243+ // log.Printf("error annotating flow with %s: %v", a.String(), err)
244+ // }
245+ // }
246+ // // write flow record back onto topic
247+ // body, err := json.Marshal(flow)
248+ // if err != nil {
249+ // log.Printf("error marshaling enriched record to json: %v", err)
250+ // return
251+ // }
252+ // record.Topic = e.rpProducerTopic
253+ // record.Value = body
254+ // client.Produce(ctx, record, func(record *kgo.Record, err error) {
255+ // if err != nil {
256+ // // TODO: metric
257+ // fmt.Printf("error producing message to redpanda: %v \n", err)
258+ // }
259+ // })
238260 })
239261 if err := client .CommitUncommittedOffsets (ctx ); err != nil {
240262 // TODO: metric
@@ -255,7 +277,7 @@ type Annotator interface {
255277// Annotators must implement the Annotator interface.
256278func (e * Enricher ) RegisterAnnotators (ctx context.Context ) error {
257279 e .annotators = []Annotator {
258- NewIfNameAnnotator (),
280+ // NewIfNameAnnotator(),
259281 }
260282
261283 for _ , a := range e .annotators {
0 commit comments