From 32e357692c99618685086c2f14a154e79e2f96fe Mon Sep 17 00:00:00 2001 From: Melchior Moulin Date: Tue, 5 Jul 2022 14:20:27 +0200 Subject: [PATCH] run goimports -w -local github.com/strimzi/strimzi-canary/ ./ --- cmd/main.go | 14 ++++++++------ internal/config/canary_config_test.go | 1 + internal/config/dynamic_config_watcher.go | 15 ++++++++------- internal/security/auth.go | 1 + internal/security/auth_test.go | 2 ++ internal/security/security.go | 1 + internal/security/security_test.go | 1 + internal/servers/http_server.go | 1 + internal/services/backoff_test.go | 1 + internal/services/canary_message_test.go | 1 + internal/services/connection_check.go | 1 + internal/services/consumer.go | 6 ++++-- internal/services/producer.go | 4 +++- internal/services/status_check.go | 1 + internal/services/topic.go | 3 ++- internal/services/topic_test.go | 23 +++++++++++++---------- internal/util/util_test.go | 2 +- internal/workers/canary_manager.go | 1 + 18 files changed, 51 insertions(+), 28 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 367e3f1..ee87e9f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -8,12 +8,6 @@ import ( "context" "flag" "fmt" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/exporters/jaeger" - "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" - "go.opentelemetry.io/otel/sdk/resource" - sdktrace "go.opentelemetry.io/otel/sdk/trace" - "go.opentelemetry.io/otel/trace" "io" "log" "os" @@ -22,10 +16,18 @@ import ( "syscall" "time" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/jaeger" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" + "go.opentelemetry.io/otel/sdk/resource" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + "go.opentelemetry.io/otel/trace" + "github.com/Shopify/sarama" "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + "github.com/strimzi/strimzi-canary/internal/config" "github.com/strimzi/strimzi-canary/internal/security" "github.com/strimzi/strimzi-canary/internal/servers" diff --git a/internal/config/canary_config_test.go b/internal/config/canary_config_test.go index c5a9c21..bfd1a7a 100644 --- a/internal/config/canary_config_test.go +++ b/internal/config/canary_config_test.go @@ -3,6 +3,7 @@ // License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). // +//go:build unit_test // +build unit_test // Package config defining the canary configuration parameters diff --git a/internal/config/dynamic_config_watcher.go b/internal/config/dynamic_config_watcher.go index 5c0b1eb..103e71d 100644 --- a/internal/config/dynamic_config_watcher.go +++ b/internal/config/dynamic_config_watcher.go @@ -5,21 +5,22 @@ import ( "encoding/hex" "encoding/json" "errors" - "github.com/golang/glog" "io/ioutil" "os" "sync" "time" + + "github.com/golang/glog" ) -type DynamicConfigWatcher struct { +type DynamicConfigWatcher struct { exists bool hash string closer sync.Once quit chan struct{} } -func NewDynamicConfigWatcher(canaryConfig *CanaryConfig, applyFunc func(config *DynamicCanaryConfig), defaultFunc func() (*DynamicCanaryConfig)) (*DynamicConfigWatcher, error) { +func NewDynamicConfigWatcher(canaryConfig *CanaryConfig, applyFunc func(config *DynamicCanaryConfig), defaultFunc func() *DynamicCanaryConfig) (*DynamicConfigWatcher, error) { dynamicConfigWatcher := &DynamicConfigWatcher{ quit: make(chan struct{}), } @@ -39,7 +40,7 @@ func NewDynamicConfigWatcher(canaryConfig *CanaryConfig, applyFunc func(config * ticker := time.NewTicker(canaryConfig.DynamicConfigWatcherInterval * time.Millisecond) for { select { - case <- ticker.C: + case <-ticker.C: if _, err := os.Stat(canaryConfig.DynamicConfigFile); err == nil { dynamicConfigWatcher.exists = true target, hsh, err := readAndHash(canaryConfig.DynamicConfigFile) @@ -56,7 +57,7 @@ func NewDynamicConfigWatcher(canaryConfig *CanaryConfig, applyFunc func(config * dynamicConfigWatcher.exists = false applyFunc(defaultFunc()) } - case <- dynamicConfigWatcher.quit: + case <-dynamicConfigWatcher.quit: ticker.Stop() return } @@ -67,7 +68,7 @@ func NewDynamicConfigWatcher(canaryConfig *CanaryConfig, applyFunc func(config * return dynamicConfigWatcher, nil } -func (c *DynamicConfigWatcher) Close() { +func (c *DynamicConfigWatcher) Close() { c.closer.Do(func() { close(c.quit) }) @@ -89,6 +90,6 @@ func readAndHash(filename string) (target *DynamicCanaryConfig, h string, err er if err != nil { return } - h = hex.EncodeToString(hasher.Sum(nil)) + h = hex.EncodeToString(hasher.Sum(nil)) return } diff --git a/internal/security/auth.go b/internal/security/auth.go index 478d85f..c999d1e 100644 --- a/internal/security/auth.go +++ b/internal/security/auth.go @@ -11,6 +11,7 @@ import ( "fmt" "github.com/Shopify/sarama" + "github.com/strimzi/strimzi-canary/internal/config" ) diff --git a/internal/security/auth_test.go b/internal/security/auth_test.go index 5994b86..b80b3cc 100644 --- a/internal/security/auth_test.go +++ b/internal/security/auth_test.go @@ -3,6 +3,7 @@ // License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). // +//go:build unit_test // +build unit_test // Package security defining some security related tools @@ -13,6 +14,7 @@ import ( "testing" "github.com/Shopify/sarama" + "github.com/strimzi/strimzi-canary/internal/config" ) diff --git a/internal/security/security.go b/internal/security/security.go index 8f35014..0bbf110 100644 --- a/internal/security/security.go +++ b/internal/security/security.go @@ -13,6 +13,7 @@ import ( "os" "github.com/golang/glog" + "github.com/strimzi/strimzi-canary/internal/config" ) diff --git a/internal/security/security_test.go b/internal/security/security_test.go index 9af8d49..cb9ebe8 100644 --- a/internal/security/security_test.go +++ b/internal/security/security_test.go @@ -3,6 +3,7 @@ // License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). // +//go:build unit_test // +build unit_test // Package security defining some security related tools diff --git a/internal/servers/http_server.go b/internal/servers/http_server.go index 52c6bfb..4f99c22 100644 --- a/internal/servers/http_server.go +++ b/internal/servers/http_server.go @@ -13,6 +13,7 @@ import ( "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/strimzi/strimzi-canary/internal/services" ) diff --git a/internal/services/backoff_test.go b/internal/services/backoff_test.go index 48e2c41..3d4b2a4 100644 --- a/internal/services/backoff_test.go +++ b/internal/services/backoff_test.go @@ -3,6 +3,7 @@ // License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). // +//go:build unit_test // +build unit_test // Package services defines an interface for canary services and related implementations diff --git a/internal/services/canary_message_test.go b/internal/services/canary_message_test.go index 54a6898..a8a1092 100644 --- a/internal/services/canary_message_test.go +++ b/internal/services/canary_message_test.go @@ -3,6 +3,7 @@ // License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). // +//go:build unit_test // +build unit_test // Package services defines an interface for canary services and related implementations diff --git a/internal/services/connection_check.go b/internal/services/connection_check.go index 56350f2..61dcd68 100644 --- a/internal/services/connection_check.go +++ b/internal/services/connection_check.go @@ -15,6 +15,7 @@ import ( "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + "github.com/strimzi/strimzi-canary/internal/config" "github.com/strimzi/strimzi-canary/internal/util" ) diff --git a/internal/services/consumer.go b/internal/services/consumer.go index 1a1fd7a..037cb8b 100644 --- a/internal/services/consumer.go +++ b/internal/services/consumer.go @@ -8,17 +8,19 @@ package services import ( "context" + "strconv" + "time" + "go.opentelemetry.io/contrib/instrumentation/github.com/Shopify/sarama/otelsarama" "go.opentelemetry.io/otel" semconv "go.opentelemetry.io/otel/semconv/v1.10.0" "go.opentelemetry.io/otel/trace" - "strconv" - "time" "github.com/Shopify/sarama" "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + "github.com/strimzi/strimzi-canary/internal/config" "github.com/strimzi/strimzi-canary/internal/util" ) diff --git a/internal/services/producer.go b/internal/services/producer.go index 2304fbb..e34663d 100644 --- a/internal/services/producer.go +++ b/internal/services/producer.go @@ -8,14 +8,16 @@ package services import ( "context" + "strconv" + "go.opentelemetry.io/contrib/instrumentation/github.com/Shopify/sarama/otelsarama" "go.opentelemetry.io/otel" - "strconv" "github.com/Shopify/sarama" "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + "github.com/strimzi/strimzi-canary/internal/config" "github.com/strimzi/strimzi-canary/internal/util" ) diff --git a/internal/services/status_check.go b/internal/services/status_check.go index 5ebf6b4..49254bf 100644 --- a/internal/services/status_check.go +++ b/internal/services/status_check.go @@ -14,6 +14,7 @@ import ( "time" "github.com/golang/glog" + "github.com/strimzi/strimzi-canary/internal/config" "github.com/strimzi/strimzi-canary/internal/util" ) diff --git a/internal/services/topic.go b/internal/services/topic.go index ea66c8f..d82364e 100644 --- a/internal/services/topic.go +++ b/internal/services/topic.go @@ -15,6 +15,7 @@ import ( "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + "github.com/strimzi/strimzi-canary/internal/config" "github.com/strimzi/strimzi-canary/internal/util" ) @@ -347,7 +348,7 @@ func (ts *TopicService) requestedAssignments(currentPartitions int, brokers []*s } else { index := 0 - for ;; { + for { again := false for _, rackName := range rackNames { diff --git a/internal/services/topic_test.go b/internal/services/topic_test.go index 32ed2f7..3ce1978 100644 --- a/internal/services/topic_test.go +++ b/internal/services/topic_test.go @@ -3,6 +3,7 @@ // License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). // +//go:build unit_test // +build unit_test // Package services defines an interface for canary services and related implementations @@ -11,28 +12,30 @@ package services import ( "fmt" - "github.com/Shopify/sarama" - "github.com/strimzi/strimzi-canary/internal/config" "math/rand" "reflect" "testing" "time" "unsafe" + + "github.com/Shopify/sarama" + + "github.com/strimzi/strimzi-canary/internal/config" ) func TestRequestedAssignments(t *testing.T) { var tests = []struct { - name string - numPartitions int - numBrokers int - useRack bool + name string + numPartitions int + numBrokers int + useRack bool brokersWithMultipleLeaders []int32 - expectedMinISR int + expectedMinISR int }{ {"one broker", 1, 1, false, []int32{}, 1}, {"three brokers without rack info", 3, 3, false, []int32{}, 2}, {"fewer brokers than partitions", 3, 2, false, []int32{0}, 1}, - {"six brokers with rack info", 6, 6, true, []int32{}, 2}, + {"six brokers with rack info", 6, 6, true, []int32{}, 2}, } for _, tt := range tests { @@ -84,7 +87,7 @@ func TestRequestedAssignments(t *testing.T) { for brokerId, count := range leaderBrokers { if count > 1 { found := false - for _, expectedBrokerId := range tt.brokersWithMultipleLeaders { + for _, expectedBrokerId := range tt.brokersWithMultipleLeaders { if expectedBrokerId == brokerId { found = true break @@ -126,7 +129,7 @@ func TestRequestedAssignments(t *testing.T) { func createBrokers(t *testing.T, num int, rack bool) ([]*sarama.Broker, map[int32]*sarama.Broker) { brokers := make([]*sarama.Broker, 0) brokerMap := make(map[int32]*sarama.Broker) - for i := 0; i < num ; i++ { + for i := 0; i < num; i++ { broker := &sarama.Broker{} setBrokerID(t, broker, i) diff --git a/internal/util/util_test.go b/internal/util/util_test.go index df95dff..6bc78f9 100644 --- a/internal/util/util_test.go +++ b/internal/util/util_test.go @@ -16,7 +16,7 @@ import ( func TestIsDisconnection(t *testing.T) { cases := []struct { - err error + err error expected bool }{ {nil, false}, diff --git a/internal/workers/canary_manager.go b/internal/workers/canary_manager.go index 29155dc..df59fd6 100644 --- a/internal/workers/canary_manager.go +++ b/internal/workers/canary_manager.go @@ -13,6 +13,7 @@ import ( "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + "github.com/strimzi/strimzi-canary/internal/config" "github.com/strimzi/strimzi-canary/internal/services" )