Skip to content

Commit

Permalink
Merge b10af07 into 7d73b91
Browse files Browse the repository at this point in the history
  • Loading branch information
bwester committed Feb 24, 2022
2 parents 7d73b91 + b10af07 commit 1ed7491
Show file tree
Hide file tree
Showing 26 changed files with 884 additions and 291 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ services:
matrix:
include:
# Default: go test ./...
- go: 1.9.7
- go: 1.10.5
- go: 1.11.2
- go: 1.16.14
- go: 1.17.7

# Runs tests for admin UI
- go: 1.11.2
- go: 1.17.7
env: TEST=UI

install:
- go get golang.org/x/tools/cmd/cover && go get github.com/mattn/goveralls
- go install golang.org/x/tools/cmd/cover@latest && go install github.com/mattn/goveralls@latest

script:
- test/script.sh && goveralls -service=travis-ci -package github.com/square/quotaservice
Expand Down
12 changes: 9 additions & 3 deletions config/zkhelpers/zkhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ package zkhelpers

import (
"fmt"
"github.com/samuel/go-zookeeper/zk"
"strings"

"github.com/go-zookeeper/zk"
)

const (
DefaultRoot = ""
DefaultRoot = "/"
internalZookeeperNode = "/zookeeper"
internalZookeeperNodePrefix = "/zookeeper/"
)
Expand Down Expand Up @@ -42,7 +43,12 @@ func ListSubtree(zkConn *zk.Conn, pathRoot string) ([]string, error) {
}

for _, child := range children {
childPath := fmt.Sprintf("%v/%v", node, child)
var childPath string
if node == "/" {
childPath = "/" + child
} else {
childPath = fmt.Sprintf("%v/%v", node, child)
}
queue = append(queue, childPath)
tree = append(tree, childPath)
}
Expand Down
2 changes: 1 addition & 1 deletion config/zookeeper_persister.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"sync"
"time"

"github.com/go-zookeeper/zk"
"github.com/golang/protobuf/proto"
"github.com/samuel/go-zookeeper/zk"
"github.com/square/quotaservice/logging"
pb "github.com/square/quotaservice/protos/config"
)
Expand Down
5 changes: 3 additions & 2 deletions config/zookeeper_persister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (
"io"
"os"

"github.com/samuel/go-zookeeper/zk"
"github.com/go-zookeeper/zk"
"github.com/square/quotaservice/config/zkhelpers"
pb "github.com/square/quotaservice/protos/config"
"github.com/square/quotaservice/test/helpers"
"github.com/square/quotaservice/test/zktestserver"
)

var servers []string

func TestMain(m *testing.M) {
t, err := zk.StartTestCluster(1, nil, nil)
t, err := zktestserver.StartTestCluster(1, nil, nil)
helpers.PanicError(err)

defer func() { _ = t.Stop() }()
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/square/quotaservice

go 1.13
go 1.16

require (
cloud.google.com/go v0.0.0-20170309001835-7bcba8ac93ae
Expand All @@ -12,6 +12,7 @@ require (
github.com/alecthomas/units v0.0.0-20150109002421-6b4e7dc5e314 // indirect
github.com/go-redis/redis v6.15.2+incompatible
github.com/go-sql-driver/mysql v1.4.1
github.com/go-zookeeper/zk v1.0.2
github.com/golang/protobuf v1.2.0
github.com/googleapis/gax-go v0.0.0-20170305230405-8c5154c0fe5b // indirect
github.com/kr/pretty v0.1.0 // indirect
Expand All @@ -23,7 +24,6 @@ require (
github.com/opentracing/opentracing-go v1.0.2
github.com/ory/dockertest/v3 v3.6.0
github.com/pkg/errors v0.8.1
github.com/samuel/go-zookeeper v0.0.0-20161028232340-1d7be4effb13
github.com/sergi/go-diff v1.0.0 // indirect
github.com/stretchr/testify v1.4.0
golang.org/x/net v0.0.0-20191003171128-d98b1b443823
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKoh
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDAhzyXg+Bs+0Sb4=
github.com/go-redis/redis v6.15.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-zookeeper/zk v1.0.2 h1:4mx0EYENAdX/B/rbunjlt5+4RTA/a9SMHBRuSKdGxPM=
github.com/go-zookeeper/zk v1.0.2/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
Expand All @@ -43,7 +44,6 @@ github.com/googleapis/gax-go v0.0.0-20170305230405-8c5154c0fe5b h1:v7wZg6KtYZHQ7
github.com/googleapis/gax-go v0.0.0-20170305230405-8c5154c0fe5b/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down Expand Up @@ -82,8 +82,6 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/samuel/go-zookeeper v0.0.0-20161028232340-1d7be4effb13 h1:4AQBn5RJY4WH8t8TLEMZUsWeXHAUcoao42TCAfpEJJE=
github.com/samuel/go-zookeeper v0.0.0-20161028232340-1d7be4effb13/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
Expand All @@ -96,7 +94,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20191003171128-d98b1b443823 h1:Ypyv6BNJh07T1pUSrehkLemqPKXhus2MkfktJ91kRh4=
Expand Down Expand Up @@ -133,7 +130,6 @@ gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions test/zktestserver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
zktestserver
============

Contains testing code copied out of github.com/samuel/go-zookeeper/zk due to
the functionality being removed from upstream in later versions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package zk
package zktestserver

import (
"fmt"
Expand All @@ -7,13 +7,10 @@ import (
"math/rand"
"os"
"path/filepath"
"strings"
"time"
)

func init() {
rand.Seed(time.Now().UnixNano())
}
"github.com/go-zookeeper/zk"
)

type TestServer struct {
Port int
Expand Down Expand Up @@ -99,28 +96,6 @@ func StartTestCluster(size int, stdout, stderr io.Writer) (*TestCluster, error)
return cluster, nil
}

func (tc *TestCluster) Connect(idx int) (*Conn, error) {
zk, _, err := Connect([]string{fmt.Sprintf("127.0.0.1:%d", tc.Servers[idx].Port)}, time.Second*15)
return zk, err
}

func (tc *TestCluster) ConnectAll() (*Conn, <-chan Event, error) {
return tc.ConnectAllTimeout(time.Second * 15)
}

func (tc *TestCluster) ConnectAllTimeout(sessionTimeout time.Duration) (*Conn, <-chan Event, error) {
return tc.ConnectWithOptions(sessionTimeout)
}

func (tc *TestCluster) ConnectWithOptions(sessionTimeout time.Duration, options ...connOption) (*Conn, <-chan Event, error) {
hosts := make([]string, len(tc.Servers))
for i, srv := range tc.Servers {
hosts[i] = fmt.Sprintf("127.0.0.1:%d", srv.Port)
}
zk, ch, err := Connect(hosts, sessionTimeout, options...)
return zk, ch, err
}

func (tc *TestCluster) Stop() error {
for _, srv := range tc.Servers {
srv.Srv.Stop()
Expand All @@ -138,7 +113,7 @@ func (tc *TestCluster) waitForStart(maxRetry int, interval time.Duration) error
}

for i := 0; i < maxRetry; i++ {
_, ok := FLWSrvr(serverAddrs, time.Second)
_, ok := zk.FLWSrvr(serverAddrs, time.Second)
if ok {
return nil
}
Expand All @@ -158,7 +133,7 @@ func (tc *TestCluster) waitForStop(maxRetry int, interval time.Duration) error {
var success bool
for i := 0; i < maxRetry && !success; i++ {
success = true
for _, ok := range FLWRuok(serverAddrs, time.Second) {
for _, ok := range zk.FLWRuok(serverAddrs, time.Second) {
if ok {
success = false
}
Expand All @@ -172,45 +147,3 @@ func (tc *TestCluster) waitForStop(maxRetry int, interval time.Duration) error {
}
return nil
}

func (tc *TestCluster) StartServer(server string) {
for _, s := range tc.Servers {
if strings.HasSuffix(server, fmt.Sprintf(":%d", s.Port)) {
s.Srv.Start()
return
}
}
panic(fmt.Sprintf("Unknown server: %s", server))
}

func (tc *TestCluster) StopServer(server string) {
for _, s := range tc.Servers {
if strings.HasSuffix(server, fmt.Sprintf(":%d", s.Port)) {
s.Srv.Stop()
return
}
}
panic(fmt.Sprintf("Unknown server: %s", server))
}

func (tc *TestCluster) StartAllServers() error {
for _, s := range tc.Servers {
if err := s.Srv.Start(); err != nil {
return fmt.Errorf(
"Failed to start server listening on port `%d` : %+v", s.Port, err)
}
}

return nil
}

func (tc *TestCluster) StopAllServers() error {
for _, s := range tc.Servers {
if err := s.Srv.Stop(); err != nil {
return fmt.Errorf(
"Failed to stop server listening on port `%d` : %+v", s.Port, err)
}
}

return nil
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package zk
package zktestserver

import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"

"github.com/go-zookeeper/zk"
)

type ErrMissingServerConfigField string
Expand Down Expand Up @@ -59,7 +61,7 @@ func (sc ServerConfig) Marshall(w io.Writer) error {
}
fmt.Fprintf(w, "syncLimit=%d\n", sc.SyncLimit)
if sc.ClientPort <= 0 {
sc.ClientPort = DefaultPort
sc.ClientPort = zk.DefaultPort
}
fmt.Fprintf(w, "clientPort=%d\n", sc.ClientPort)
if sc.AutoPurgePurgeInterval > 0 {
Expand Down
8 changes: 8 additions & 0 deletions vendor/github.com/go-zookeeper/zk/.codecov.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/github.com/go-zookeeper/zk/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions vendor/github.com/go-zookeeper/zk/CONTRIBUTION.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions vendor/github.com/go-zookeeper/zk/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1ed7491

Please sign in to comment.