Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
run goimports -w -local github.com/strimzi/strimzi-canary/ ./
Browse files Browse the repository at this point in the history
  • Loading branch information
melchiormoulin committed Jul 5, 2022
1 parent bf624c4 commit 32e3576
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 28 deletions.
14 changes: 8 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions internal/config/canary_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions internal/config/dynamic_config_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}),
}
Expand All @@ -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)
Expand All @@ -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
}
Expand All @@ -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)
})
Expand All @@ -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
}
1 change: 1 addition & 0 deletions internal/security/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"

"github.com/Shopify/sarama"

"github.com/strimzi/strimzi-canary/internal/config"
)

Expand Down
2 changes: 2 additions & 0 deletions internal/security/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,6 +14,7 @@ import (
"testing"

"github.com/Shopify/sarama"

"github.com/strimzi/strimzi-canary/internal/config"
)

Expand Down
1 change: 1 addition & 0 deletions internal/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"

"github.com/golang/glog"

"github.com/strimzi/strimzi-canary/internal/config"
)

Expand Down
1 change: 1 addition & 0 deletions internal/security/security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/servers/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/strimzi/strimzi-canary/internal/services"
)

Expand Down
1 change: 1 addition & 0 deletions internal/services/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/services/canary_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/services/connection_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
6 changes: 4 additions & 2 deletions internal/services/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 3 additions & 1 deletion internal/services/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
1 change: 1 addition & 0 deletions internal/services/status_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/golang/glog"

"github.com/strimzi/strimzi-canary/internal/config"
"github.com/strimzi/strimzi-canary/internal/util"
)
Expand Down
3 changes: 2 additions & 1 deletion internal/services/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -347,7 +348,7 @@ func (ts *TopicService) requestedAssignments(currentPartitions int, brokers []*s
} else {
index := 0

for ;; {
for {
again := false

for _, rackName := range rackNames {
Expand Down
23 changes: 13 additions & 10 deletions internal/services/topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func TestIsDisconnection(t *testing.T) {
cases := []struct {
err error
err error
expected bool
}{
{nil, false},
Expand Down
1 change: 1 addition & 0 deletions internal/workers/canary_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit 32e3576

Please sign in to comment.