Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated zfmt (internal to github version) #4

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
run:
skip-dirs:
- docs
- datadog
- kustomize
skip-files:
- 'wire_gen.go'
tests: false
linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
gci:
sections:
- standard
- default
gosimple:
go: '1.17'
govet:
check-shadowing: true
settings:
printf:
funcs:
- (gitlab.zgtools.net/devex/archetypes/gomods/zlog.Logger).Debug
- (gitlab.zgtools.net/devex/archetypes/gomods/zlog.Logger).Info
- (gitlab.zgtools.net/devex/archetypes/gomods/zlog.Logger).Warn
- (gitlab.zgtools.net/devex/archetypes/gomods/zlog.Logger).Error
depguard:
rules:
Main:
files:
- $all
- "!$test"
deny:
- github.com/satori/go.uuid: Prefer "github.com/google/uuid"
disable-all: true
enable:
- asciicheck
- bidichk
- bodyclose
- cyclop
- decorder
- depguard
- deadcode
- dupl
- errcheck
- errchkjson
- errname
- errorlint
- exportloopref
- gci
- gocognit
- goconst
- gocritic
- gocyclo
- gofmt
- gosimple
- govet
- ineffassign
- nolintlint
- prealloc
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Directories containing independent Go modules.
MODULE_DIRS = .

.PHONY: test-no-setup
test-no-setup:
./coverage.sh
Expand All @@ -11,13 +14,22 @@ test-local: setup-test test-no-setup

.PHONY: cover
cover:
go test -v ./... -count=1 -coverprofile=cover.out -covermode atomic && \
go tool cover -html=cover.out -o cover.html
./coverage.sh

.PHONY: example-producer
example-producer:
go run example/producer/producer.go

.PHONY: example-worker
example-worker:
go run example/worker/worker.go
go run example/worker/worker.go

.PHONY: lint
lint: golangci-lint

.PHONY: golangci-lint
golangci-lint:
@$(foreach mod,$(MODULE_DIRS), \
(cd $(mod) && \
echo "[lint] golangci-lint: $(mod)" && \
golangci-lint run --path-prefix $(mod) ./...) &&) true
15 changes: 7 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"sync"

"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
"github.com/zillow/zfmt"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)
Expand Down Expand Up @@ -133,17 +133,16 @@ func (c *Client) Writer(_ context.Context, topicConfig ProducerTopicConfig, opts
}

func getFormatter(topicConfig TopicConfig) (zfmt.Formatter, error) {
var fmtter zfmt.Formatter
switch topicConfig.GetFormatter() {
case CustomFmt:
fmtter = &noopFormatter{}
return &noopFormatter{}, nil
default:
fmtter, _ = zfmt.GetFormatter(topicConfig.GetFormatter(), topicConfig.GetSchemaID())
}
if fmtter == nil {
return nil, fmt.Errorf("unsupported formatter %s", topicConfig.GetFormatter())
f, err := zfmt.GetFormatter(topicConfig.GetFormatter(), topicConfig.GetSchemaID())
if err != nil {
return nil, fmt.Errorf("unsupported formatter %s", topicConfig.GetFormatter())
}
return f, nil
}
return fmtter, nil
}

// Close terminates all cached readers and writers gracefully.
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/require"
"github.com/zillow/zfmt"
mock_confluent "github.com/zillow/zkafka/mocks/confluent"
"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

"github.com/confluentinc/confluent-kafka-go/v2/kafka"
"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
"github.com/zillow/zfmt"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/require"

"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
"github.com/zillow/zfmt"
)

func Test_getDefaultConsumerTopicConfig(t *testing.T) {
Expand Down
17 changes: 3 additions & 14 deletions coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ function quit() {
}
# change to example directory for execution (because it uses hardcoded filepaths, and the testable
# examples don't work when executed outside of that directory
go test -c -coverpkg=$pck1 -covermode=atomic -o "$root_res" -tags integration $pck1
go test -c -coverpkg=$pck1 -covermode=atomic -o "$root_res" $pck1
# convert binary to go formatted
go tool test2json -t "$root_res" -test.v -test.coverprofile "$root_out"

go test -c -coverpkg=$pck1 -covermode=atomic -o "$source_res" -tags integration $pck2
go test -c -coverpkg=$pck1 -covermode=atomic -o "$source_res" $pck2
go tool test2json -t "$source_res" -test.v -test.coverprofile "$source_out"

# delete aggregate file
Expand All @@ -38,15 +38,4 @@ tail -n+2 "$source_out" >> "$omni_out"

# print aggregated results
go tool cover -func="$omni_out"

# we need to create a cobertura.xml file (this is used for code coverage visualization)
# download the tool to convert gocover into covertura
go install github.com/boumenot/gocover-cobertura@latest
gocover-cobertura < $omni_out > coverage.tmp.xml
# the cobertura generated file has two issues. Its source array doesn't include the curdir and
# the class node filepaths aren't relative to the root.
# We'll run two commands
# 1. Remove the prefixed go.mod package name from filenames inside of the cobertura with a brute force replace with empty string
# 2. Add the workingdirectory to the sources array using a find replace (search for sources node, and replace with sources node but new workdir source nod)
pkg=gitlab.zgtools.net/devex/archetypes/gomods/zkafka
sed "s|$pkg/||" coverage.tmp.xml | sed "s|<sources>|<sources>\n<source>$(pwd)</source>|"> coverage.xml
go tool cover -html="$omni_out" -o cover.html
2 changes: 1 addition & 1 deletion example/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"log"

"github.com/zillow/zfmt"
"github.com/zillow/zkafka"
"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion example/producer/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"time"

"github.com/google/uuid"
"github.com/zillow/zfmt"
"github.com/zillow/zkafka"
"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
)

func main() {
Expand Down
6 changes: 4 additions & 2 deletions example/worker/bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"time"

"github.com/golang/mock/gomock"
"github.com/zillow/zfmt"
"github.com/zillow/zkafka"
zkafka_mocks "github.com/zillow/zkafka/mocks"
"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
)

func main() {
Expand Down Expand Up @@ -48,7 +48,9 @@ func main() {
)
ctx, c := context.WithTimeout(context.Background(), 2*time.Minute)
defer c()
w.Run(ctx, nil)
if err := w.Run(ctx, nil); err != nil {
log.Panic(err)
}
}

type kafkaProcessorError struct{}
Expand Down
6 changes: 4 additions & 2 deletions example/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"syscall"
"time"

"github.com/zillow/zfmt"
"github.com/zillow/zkafka"
"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
)

// Demonstrates reading from a topic via the zkafka.Work struct which is more convenient, typically, than using the consumer directly
Expand Down Expand Up @@ -61,7 +61,9 @@ func main() {
// Register a processor which is executed per message.
// Speedup is used to create multiple processor goroutines. Order is still maintained with this setup by way of `virtual partitions`
work := wf.Create(topicConfig, &Processor{}, zkafka.Speedup(5))
work.Run(ctx, shutdown)
if err := work.Run(ctx, shutdown); err != nil {
log.Panic(err)
}
}

type Processor struct{}
Expand Down
2 changes: 1 addition & 1 deletion formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package zkafka
import (
"errors"

"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
"github.com/zillow/zfmt"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/sony/gobreaker v1.0.0
github.com/stretchr/testify v1.9.0
gitlab.zgtools.net/devex/archetypes/gomods/zfmt v1.0.68
github.com/zillow/zfmt v1.0.1
go.opentelemetry.io/otel v1.27.0
go.opentelemetry.io/otel/trace v1.27.0
golang.org/x/sync v0.7.0
Expand All @@ -25,6 +25,6 @@ require (
github.com/heetch/avro v0.4.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQ
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
gitlab.zgtools.net/devex/archetypes/gomods/zfmt v1.0.68 h1:EMTWPKIGT8Vh2JwqEbOkSFLFUsB2Cdc5gr0sn7YmUa4=
gitlab.zgtools.net/devex/archetypes/gomods/zfmt v1.0.68/go.mod h1:h8Wbct3spciNuM5Me/BccIu95vo2bpkhCIJvZx4v9sk=
github.com/zillow/zfmt v1.0.1 h1:JLN5WaxoqqoEPUpVWer83uhXhDPAA2nZkfQqgKnWp+w=
github.com/zillow/zfmt v1.0.1/go.mod h1:0PpKh4rWh+5Ghr2bbuN5UvEcqEz6PkHfE0Idgjyxy7Y=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0 h1:RsQi0qJ2imFfCvZabqzM9cNXBG8k6gXMv1A0cXRmH6A=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0/go.mod h1:vsh3ySueQCiKPxFLvjWC4Z135gIa34TQ/NSqkDTZYUM=
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.45.0 h1:2ea0IkZBsWH+HA2GkD+7+hRw2u97jzdFyRtXuO14a1s=
Expand Down Expand Up @@ -385,8 +385,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
3 changes: 2 additions & 1 deletion message.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/confluentinc/confluent-kafka-go/v2/kafka"
"github.com/google/uuid"
"github.com/pkg/errors"
"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
"github.com/zillow/zfmt"
)

// Message is a container for kafka message
Expand Down Expand Up @@ -65,6 +65,7 @@ func makeProducerMessageRaw(_ context.Context, serviceName, topic string, key *s
Key: obsKeyOriginService,
Value: []byte(serviceName),
})
//nolint:errcheck // Its not particularly noteworthy if if host isn't propagated forward. We'll suppress the error
hostname, _ := os.Hostname()
// hn is empty string if there's an error
kafkaMessage.Headers = append(kafkaMessage.Headers, kafka.Header{
Expand Down
2 changes: 1 addition & 1 deletion message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/confluentinc/confluent-kafka-go/v2/kafka"
"github.com/stretchr/testify/require"
"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
"github.com/zillow/zfmt"
)

func Test_makeProducerMessageRaw(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
mock_confluent "github.com/zillow/zkafka/mocks/confluent"

"github.com/golang/mock/gomock"
"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
"github.com/zillow/zfmt"
)

func TestReader_Read_NilReturn(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/zillow/zfmt"
"github.com/zillow/zkafka"
"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
"golang.org/x/sync/errgroup"
)

Expand Down
2 changes: 1 addition & 1 deletion test/work_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/zillow/zfmt"
"github.com/zillow/zkafka"
zkafka_mocks "github.com/zillow/zkafka/mocks"
"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"

"github.com/golang/mock/gomock"
)
Expand Down
2 changes: 1 addition & 1 deletion test/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/confluentinc/confluent-kafka-go/v2/kafka"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"github.com/zillow/zfmt"
"github.com/zillow/zkafka"
mock_confluent "github.com/zillow/zkafka/mocks/confluent"
"gitlab.zgtools.net/devex/archetypes/gomods/zfmt"
)

func TestWriter_Write_LifecycleHooksCalled(t *testing.T) {
Expand Down
Loading
Loading