Skip to content

Commit

Permalink
Merge pull request #20 from zerodha/refactor-config
Browse files Browse the repository at this point in the history
Add a few refactors
  • Loading branch information
knadh authored Apr 11, 2024
2 parents 511e9f3 + d5d7940 commit 38d15df
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 216 deletions.
6 changes: 4 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ before:

builds:
- env:
- CGO_ENABLED=1
- CGO_ENABLED=0
binary: kaf-relay
goos:
- linux
goarch:
- amd64
ldflags:
- -s -w -X "main.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }})" -X "main.versionString={{ .Tag }}"

archives:
- format: tar.gz
files:
- config.toml.sample
- README.md
- LICENSE
- LICENSE
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Git version for injecting into Go bins.
LAST_COMMIT := $(shell git rev-parse --short HEAD)
LAST_COMMIT_DATE := $(shell git show -s --format=%ci ${LAST_COMMIT})
VERSION := $(shell git describe --tags)
BUILDSTR := ${VERSION} (Commit: ${LAST_COMMIT_DATE} (${LAST_COMMIT}), Build: $(shell date +"%Y-%m-%d% %H:%M:%S %z"))
# Try to get the commit hash from 1) git 2) the VERSION file 3) fallback.
LAST_COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),$(shell head -n 1 VERSION | grep -oP -m 1 "^[a-z0-9]+$$"),"")

BIN := kaf-relay.bin
DIST := dist
# Try to get the semver from 1) git 2) the VERSION file 3) fallback.
VERSION := $(or $(LISTMONK_VERSION),$(shell git describe --tags --abbrev=0 2> /dev/null),$(shell grep -oP 'tag: \Kv\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?' VERSION),"v0.0.0")
BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z"))

.PHONY: dist
dist:
mkdir -p ${DIST}
CGO_ENABLED=1 go build -o ${BIN} --ldflags="-X 'main.buildString=${BUILDSTR}'"
cp ${BIN} ${DIST}
BIN := kaf-relay

.PHONY: build
build: $(BIN)

$(BIN):
CGO_ENABLED=0 go build -o ${BIN} --ldflags="-X 'main.buildString=${BUILDSTR}'"

.PHONY: clean
clean:
rm -rf ${DIST}
rm -rf ${BIN}
12 changes: 6 additions & 6 deletions consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type consumer struct {
offsetMgr *offsetManager
nodeTracker *NodeTracker

l *slog.Logger
log *slog.Logger
}

// offsetManager is a holder for the topic offsets.
Expand Down Expand Up @@ -74,27 +74,27 @@ func (c *consumer) GetHealthy(ctx context.Context) (int, error) {

// reinit reinitializes the consumer group
func (c *consumer) Connect(ctx context.Context, cfg ConsumerGroupCfg) error {
c.l.Debug("reinitializing consumer group", "broker", cfg.BootstrapBrokers)
c.log.Debug("reinitializing consumer group", "broker", cfg.BootstrapBrokers)

// tcp health check
if ok := healthcheck(ctx, cfg.BootstrapBrokers, c.maxReqTime); !ok {
return ErrorNoHealthy
}

cl, err := initConsumerGroup(ctx, cfg, c.l)
cl, err := initConsumerGroup(ctx, cfg, c.log)
if err != nil {
return err
}

offsets := c.GetOffsets()
if offsets != nil {
err = leaveAndResetOffsets(ctx, cl, cfg, offsets, c.l)
err = leaveAndResetOffsets(ctx, cl, cfg, offsets, c.log)
if err != nil {
c.l.Error("error resetting offsets", "err", err)
c.log.Error("error resetting offsets", "err", err)
return err
}

cl, err = initConsumerGroup(ctx, cfg, c.l)
cl, err = initConsumerGroup(ctx, cfg, c.log)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
require (
github.com/knadh/koanf/parsers/toml v0.1.0
github.com/knadh/koanf/providers/file v0.1.0
github.com/knadh/koanf/providers/posflag v0.1.0
github.com/knadh/koanf/v2 v2.0.1
github.com/spf13/pflag v1.0.5
github.com/twmb/franz-go v1.15.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ github.com/knadh/koanf/parsers/toml v0.1.0 h1:S2hLqS4TgWZYj4/7mI5m1CQQcWurxUz6OD
github.com/knadh/koanf/parsers/toml v0.1.0/go.mod h1:yUprhq6eo3GbyVXFFMdbfZSo928ksS+uo0FFqNMnO18=
github.com/knadh/koanf/providers/file v0.1.0 h1:fs6U7nrV58d3CFAFh8VTde8TM262ObYf3ODrc//Lp+c=
github.com/knadh/koanf/providers/file v0.1.0/go.mod h1:rjJ/nHQl64iYCtAW2QQnF0eSmDEX/YZ/eNFj5yR6BvA=
github.com/knadh/koanf/providers/posflag v0.1.0 h1:mKJlLrKPcAP7Ootf4pBZWJ6J+4wHYujwipe7Ie3qW6U=
github.com/knadh/koanf/providers/posflag v0.1.0/go.mod h1:SYg03v/t8ISBNrMBRMlojH8OsKowbkXV7giIbBVgbz0=
github.com/knadh/koanf/v2 v2.0.1 h1:1dYGITt1I23x8cfx8ZnldtezdyaZtfAuRtIFOiRzK7g=
github.com/knadh/koanf/v2 v2.0.1/go.mod h1:ZeiIlIDXTE7w1lMT6UVcNiRAS2/rCeLn/GdLNvY1Dus=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
Expand Down
Loading

0 comments on commit 38d15df

Please sign in to comment.