Skip to content

Commit

Permalink
feat: bump go-dcp-client v0.0.51
Browse files Browse the repository at this point in the history
  • Loading branch information
erayarslan committed May 9, 2023
1 parent c680606 commit cfcab02
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 242 deletions.
54 changes: 17 additions & 37 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ package config

import (
"time"

"github.com/Trendyol/go-dcp-client/logger"

"github.com/gookit/config/v2"
"github.com/gookit/config/v2/yamlv3"
)

type Kafka struct {
Expand All @@ -16,12 +11,12 @@ type Kafka struct {
ScramPassword string `yaml:"scramPassword"`
RootCAPath string `yaml:"rootCAPath"`
Brokers []string `yaml:"brokers"`
ProducerBatchSize int `yaml:"producerBatchSize" default:"2000"`
ProducerBatchBytes int `yaml:"producerBatchBytes" default:"10485760"`
ProducerBatchSize int `yaml:"producerBatchSize"`
ProducerBatchBytes int `yaml:"producerBatchBytes"`
ProducerBatchTickerDuration time.Duration `yaml:"producerBatchTickerDuration"`
ReadTimeout time.Duration `yaml:"readTimeout"`
WriteTimeout time.Duration `yaml:"writeTimeout"`
RequiredAcks int `yaml:"requiredAcks" default:"1"`
RequiredAcks int `yaml:"requiredAcks"`
Compression int8 `yaml:"compression"`
SecureConnection bool `yaml:"secureConnection"`
}
Expand All @@ -37,43 +32,28 @@ type Config struct {
Kafka Kafka `yaml:"kafka"`
}

func Options(opts *config.Options) {
opts.ParseTime = true
opts.Readonly = true
opts.EnableCache = true
opts.ParseDefault = true
}

func applyUnhandledDefaults(_config *Config) {
if _config.Kafka.ReadTimeout == 0 {
_config.Kafka.ReadTimeout = 30 * time.Second
func (c *Config) ApplyDefaults() {
if c.Kafka.ReadTimeout == 0 {
c.Kafka.ReadTimeout = 30 * time.Second
}

if _config.Kafka.WriteTimeout == 0 {
_config.Kafka.WriteTimeout = 30 * time.Second
if c.Kafka.WriteTimeout == 0 {
c.Kafka.WriteTimeout = 30 * time.Second
}

if _config.Kafka.ProducerBatchTickerDuration == 0 {
_config.Kafka.ProducerBatchTickerDuration = 10 * time.Second
if c.Kafka.ProducerBatchTickerDuration == 0 {
c.Kafka.ProducerBatchTickerDuration = 10 * time.Second
}
}

func NewConfig(name string, filePath string, errorLogger logger.Logger) *Config {
conf := config.New(name).WithOptions(Options).WithDriver(yamlv3.Driver)

err := conf.LoadFiles(filePath)
if err != nil {
errorLogger.Printf("error while reading config %v", err)
if c.Kafka.ProducerBatchSize == 0 {
c.Kafka.ProducerBatchSize = 2000
}

_config := &Config{}
err = conf.Decode(_config)

if err != nil {
errorLogger.Printf("error while reading config %v", err)
if c.Kafka.ProducerBatchBytes == 0 {
c.Kafka.ProducerBatchBytes = 10485760
}

applyUnhandledDefaults(_config)

return _config
if c.Kafka.RequiredAcks == 0 {
c.Kafka.RequiredAcks = 1
}
}
24 changes: 22 additions & 2 deletions connector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gokafkaconnectcouchbase

import (
"os"

"github.com/Trendyol/go-dcp-client"
"github.com/Trendyol/go-dcp-client/logger"
"github.com/Trendyol/go-dcp-client/models"
Expand All @@ -10,6 +12,7 @@ import (
"github.com/Trendyol/go-kafka-connect-couchbase/kafka/metadata"
"github.com/Trendyol/go-kafka-connect-couchbase/kafka/producer"
"github.com/Trendyol/go-kafka-connect-couchbase/metric"
"gopkg.in/yaml.v3"
)

var MetadataTypeKafka = "kafka"
Expand Down Expand Up @@ -71,8 +74,25 @@ func NewConnectorWithLoggers(configPath string, mapper Mapper, logger logger.Log
return newConnector(configPath, mapper, logger, errorLogger)
}

func newConnectorConfig(path string) (*config.Config, error) {
file, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var c config.Config
err = yaml.Unmarshal(file, &c)
if err != nil {
return nil, err
}
c.ApplyDefaults()
return &c, nil
}

func newConnector(configPath string, mapper Mapper, logger logger.Logger, errorLogger logger.Logger) (Connector, error) {
c := config.NewConfig("cbgokafka", configPath, errorLogger)
c, err := newConnectorConfig(configPath)
if err != nil {
return nil, err
}

connector := &connector{
mapper: mapper,
Expand All @@ -89,7 +109,7 @@ func newConnector(configPath string, mapper Mapper, logger logger.Logger, errorL
topics = append(topics, topic)
}

err := kafkaClient.CheckTopics(topics)
err = kafkaClient.CheckTopics(topics)
if err != nil {
connector.errorLogger.Printf("collection topic mapping error: %v", err)
return nil, err
Expand Down
39 changes: 14 additions & 25 deletions example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,42 @@ replace github.com/Trendyol/go-kafka-connect-couchbase => ../.
require github.com/Trendyol/go-kafka-connect-couchbase v0.0.0

require (
github.com/Trendyol/go-dcp-client v0.0.48 // indirect
github.com/Trendyol/go-dcp-client v0.0.51 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/ansrivas/fiberprometheus/v2 v2.6.0 // indirect
github.com/avast/retry-go/v4 v4.3.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/couchbase/gocbcore/v10 v10.2.3-0.20230404070112-cab6da1895ae // indirect
github.com/couchbase/gocbcore/v10 v10.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/goccy/go-yaml v1.10.0 // indirect
github.com/gofiber/adaptor/v2 v2.1.32 // indirect
github.com/gofiber/fiber/v2 v2.42.0 // indirect
github.com/gofiber/fiber/v2 v2.44.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gookit/color v1.5.2 // indirect
github.com/gookit/config/v2 v2.2.1 // indirect
github.com/gookit/goutil v0.6.6 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/klauspost/compress v1.16.3 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_golang v1.15.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
Expand All @@ -60,30 +52,27 @@ require (
github.com/segmentio/kafka-go v0.4.39 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.44.0 // indirect
github.com/valyala/fasthttp v1.45.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/xdg/scram v1.0.5 // indirect
github.com/xdg/stringprep v1.0.3 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.26.2 // indirect
k8s.io/apimachinery v0.26.2 // indirect
k8s.io/client-go v0.26.2 // indirect
k8s.io/api v0.27.1 // indirect
k8s.io/apimachinery v0.27.1 // indirect
k8s.io/client-go v0.27.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d // indirect
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a // indirect
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
Expand Down
Loading

0 comments on commit cfcab02

Please sign in to comment.