This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 230
/
cmd.go
72 lines (66 loc) · 2.49 KB
/
cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package kafka_sasl
import (
"time"
confluent "github.com/confluentinc/confluent-kafka-go/kafka"
"github.com/featurebasedb/featurebase/v3/idk"
"github.com/featurebasedb/featurebase/v3/idk/common"
"github.com/pkg/errors"
)
type Main struct {
idk.Main `flag:"!embed"`
idk.ConfluentCommand `flag:"!embed"`
Group string `help:"Kafka group."`
Topics []string `help:"Kafka topics to read from."`
Timeout time.Duration `help:"Time to wait for more records from Kafka before flushing a batch. 0 to disable."`
SkipOld bool `short:"" help:"Skip to the most recent Kafka message rather than starting at the beginning."`
Header string `help:"Path to the static schema, in JSON header format."`
AllowMissingFields bool `help:"Will proceed with ingest even if a field is missing from a record but specified in the JSON config file. Default false"`
ConfigMap *confluent.ConfigMap `flag:"-"`
}
func (m *Main) CopyIn(config idk.ConfluentCommand) {
m.KafkaSaslUsername = config.KafkaSaslUsername
m.KafkaSaslPassword = config.KafkaSaslPassword
m.KafkaSaslMechanism = config.KafkaSaslMechanism
m.KafkaSecurityProtocol = config.KafkaSecurityProtocol
m.KafkaSslKeyPassword = config.KafkaSslKeyPassword
m.KafkaSslCaLocation = config.KafkaSslCaLocation
m.KafkaSslCertificateLocation = config.KafkaSslCertificateLocation
m.KafkaSslKeyLocation = config.KafkaSslKeyLocation
}
func NewMain() (*Main, error) {
var err error
m := Main{}
m.Main = *idk.NewMain()
m.ConfluentCommand = idk.ConfluentCommand{}
m.KafkaBootstrapServers = []string{"localhost:9092"}
m.Group = "defaultgroup"
m.Topics = []string{"defaulttopic"}
m.Timeout = time.Second
m.OffsetMode = true
m.Main.Namespace = "ingester_kafka_confluent"
m.Main.Pprof = "" // don't initialize pprof until we actually use it in tests
if err != nil {
return nil, err
}
m.NewSource = func() (idk.Source, error) {
source := NewSource()
source.Group = m.Group
source.Topics = m.Topics
source.Log = m.Main.Log()
source.Timeout = m.Timeout
source.SkipOld = m.SkipOld
source.Header = m.Header
source.AllowMissingFields = m.AllowMissingFields
cfg, err := common.SetupConfluent(&m.ConfluentCommand)
if err != nil {
return nil, err
}
source.ConfigMap = cfg
err = source.Open()
if err != nil {
return nil, errors.Wrap(err, "opening source")
}
return source, nil
}
return &m, nil
}