Skip to content
Snippets Groups Projects
Commit 136b4a42 authored by ale's avatar ale
Browse files

Merge branch 'etcd-mod' into 'master'

Update etcd client to 3.5.0-alpha

See merge request !34
parents 49524b2e 1acff763
Branches
No related tags found
1 merge request!34Update etcd client to 3.5.0-alpha
Showing with 361 additions and 135 deletions
......@@ -4,8 +4,8 @@ import (
"context"
"errors"
"github.com/golang/protobuf/proto"
"go.etcd.io/etcd/clientv3"
"google.golang.org/protobuf/proto"
"go.etcd.io/etcd/client/v3"
"git.autistici.org/ale/autoradio"
pb "git.autistici.org/ale/autoradio/proto"
......
......@@ -8,8 +8,8 @@ import (
"git.autistici.org/ale/autoradio"
"git.autistici.org/ale/autoradio/coordination/watcher"
pb "git.autistici.org/ale/autoradio/proto"
"github.com/golang/protobuf/proto"
"go.etcd.io/etcd/clientv3"
"google.golang.org/protobuf/proto"
"go.etcd.io/etcd/client/v3"
)
// WatchableConfig mimics the watcher.Watchable interface, but with
......
......@@ -16,7 +16,8 @@ import (
"git.autistici.org/ale/autoradio/client"
pb "git.autistici.org/ale/autoradio/proto"
"github.com/google/subcommands"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/client/v3"
"google.golang.org/grpc"
)
// Format for output of structured data.
......@@ -86,6 +87,7 @@ func getClient() *client.Client {
if auClient == nil {
cli, err := clientv3.New(clientv3.Config{
Endpoints: strings.Split(*etcdEndpoints, ","),
DialOptions: []grpc.DialOption{grpc.WithBlock()},
DialTimeout: 5 * time.Second,
})
if err != nil {
......
......@@ -17,8 +17,8 @@ import (
"git.autistici.org/ale/autoradio/node"
"git.autistici.org/ale/autoradio/node/icecast"
"git.autistici.org/ale/autoradio/util"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/clientv3/concurrency"
"go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/concurrency"
"golang.org/x/sync/errgroup"
)
......
......@@ -11,8 +11,8 @@ import (
"time"
"git.autistici.org/ale/autoradio/transcoder"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/clientv3/concurrency"
"go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/concurrency"
)
var (
......
......@@ -2,14 +2,15 @@ package election
import (
"context"
"errors"
"fmt"
"log"
"sync"
"time"
pb "git.autistici.org/ale/autoradio/proto"
"github.com/golang/protobuf/proto"
"go.etcd.io/etcd/clientv3/concurrency"
"go.etcd.io/etcd/client/v3/concurrency"
"google.golang.org/protobuf/proto"
)
// Op is a function that will be called when a node participating in
......@@ -103,7 +104,7 @@ func (e *Election) Run(ctx context.Context, op Op) error {
}
for {
err := e.runOnce(ctx, string(data), op)
if err == context.Canceled {
if errors.Is(err, context.Canceled) {
return err
} else if err != nil {
log.Printf("election: %v", err)
......
......@@ -8,8 +8,8 @@ import (
"strings"
"sync"
"github.com/golang/protobuf/proto"
"go.etcd.io/etcd/clientv3"
"google.golang.org/protobuf/proto"
"go.etcd.io/etcd/client/v3"
"git.autistici.org/ale/autoradio/coordination/watcher"
pb "git.autistici.org/ale/autoradio/proto"
......
......@@ -8,9 +8,9 @@ import (
"strings"
pb "git.autistici.org/ale/autoradio/proto"
"github.com/golang/protobuf/proto"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/clientv3/concurrency"
"google.golang.org/protobuf/proto"
"go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/concurrency"
)
// An EndpointRegistration specifies parameters for a presence
......
......@@ -7,7 +7,7 @@ import (
"sync"
"time"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/client/v3"
)
var watcherErrDelay = 200 * time.Millisecond
......
......@@ -4,16 +4,23 @@ go 1.14
require (
github.com/NYTimes/gziphandler v1.1.1
github.com/coreos/go-systemd/v22 v22.3.1 // indirect
github.com/elazarl/go-bindata-assetfs v1.0.1
github.com/golang/protobuf v1.5.2
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/subcommands v1.2.0
github.com/jmcvetta/randutil v0.0.0-20150817122601-2bb1b664bcff
github.com/lpar/gzipped v1.1.1-0.20190413023519-5d9a18ea7f47
github.com/miekg/dns v1.1.42
github.com/prometheus/client_golang v1.10.0
github.com/prometheus/common v0.23.0
go.etcd.io/etcd v0.5.0-alpha.5.0.20190401205724-a621d807f061
go.etcd.io/etcd/client/v3 v3.5.0-alpha.0
go.etcd.io/etcd/server/v3 v3.5.0-alpha.0
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/grpc v1.26.0
golang.org/x/sys v0.0.0-20210503080704-8803ae5d1324 // indirect
google.golang.org/genproto v0.0.0-20210429181445-86c259c2b4ab // indirect
google.golang.org/grpc v1.37.0
google.golang.org/protobuf v1.26.0
)
This diff is collapsed.
......@@ -17,7 +17,7 @@ import (
"sync"
"time"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/client/v3"
)
const (
......
......@@ -6,7 +6,7 @@ import (
"errors"
"time"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/client/v3"
)
var (
......
......@@ -17,7 +17,7 @@ import (
"git.autistici.org/ale/autoradio/node/lbv2"
pb "git.autistici.org/ale/autoradio/proto"
"git.autistici.org/ale/autoradio/util"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/client/v3"
)
type loadBalancer struct {
......
......@@ -13,7 +13,7 @@ import (
pb "git.autistici.org/ale/autoradio/proto"
"git.autistici.org/ale/autoradio/util"
"github.com/prometheus/client_golang/prometheus"
"go.etcd.io/etcd/clientv3/concurrency"
"go.etcd.io/etcd/client/v3/concurrency"
)
var statusUpdateInterval = 1 * time.Second
......
......@@ -3,6 +3,7 @@ package node
import (
"context"
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
......@@ -13,10 +14,11 @@ import (
"git.autistici.org/ale/autoradio"
pb "git.autistici.org/ale/autoradio/proto"
"github.com/golang/protobuf/proto"
"go.etcd.io/etcd/clientv3/concurrency"
"go.etcd.io/etcd/embed"
"go.etcd.io/etcd/etcdserver/api/v3client"
"go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/concurrency"
"go.etcd.io/etcd/server/v3/embed"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
)
type fakeIcecast struct{}
......@@ -29,19 +31,38 @@ func (f *fakeIcecast) Update(_ context.Context, mounts []*pb.Mount, isMaster boo
return nil
}
func TestNode(t *testing.T) {
func createTestEtcd(t testing.TB) (*clientv3.Client, func()) {
cfg := embed.NewConfig()
cfg.Dir = "default.etcd"
defer os.RemoveAll(cfg.Dir)
cfg.Dir, _ = ioutil.TempDir("", "")
e, err := embed.StartEtcd(cfg)
if err != nil {
t.Fatalf("StartEtcd: %v", err)
}
defer e.Close()
<-e.Server.ReadyNotify()
cli := v3client.New(e.Server)
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{"http://localhost:2379"},
DialOptions: []grpc.DialOption{grpc.WithBlock()},
})
if err != nil {
t.Fatalf("clientv3.New: %v", err)
}
return cli, func() {
cli.Close()
e.Close()
os.RemoveAll(cfg.Dir)
}
}
func TestNode(t *testing.T) {
cli, cleanup := createTestEtcd(t)
defer cleanup()
session, _ := concurrency.NewSession(cli, concurrency.WithTTL(2))
defer session.Close()
ctx, cancel := context.WithCancel(context.Background())
var nodes []*Node
......@@ -77,19 +98,11 @@ func TestNode(t *testing.T) {
}
func TestNode_StatusPage(t *testing.T) {
cfg := embed.NewConfig()
cfg.Dir = "default.etcd"
defer os.RemoveAll(cfg.Dir)
e, err := embed.StartEtcd(cfg)
if err != nil {
t.Fatalf("StartEtcd: %v", err)
}
defer e.Close()
<-e.Server.ReadyNotify()
cli := v3client.New(e.Server)
cli, cleanup := createTestEtcd(t)
defer cleanup()
session, _ := concurrency.NewSession(cli, concurrency.WithTTL(2))
defer session.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
......@@ -100,7 +113,7 @@ func TestNode_StatusPage(t *testing.T) {
SourcePassword: "pass",
}
mdata, _ := proto.Marshal(m)
_, err = cli.Put(ctx, autoradio.MountPrefix+"test.ogg", string(mdata))
_, err := cli.Put(ctx, autoradio.MountPrefix+"test.ogg", string(mdata))
if err != nil {
t.Fatalf("Put error: %v", err)
}
......@@ -119,6 +132,7 @@ func TestNode_StatusPage(t *testing.T) {
if err != nil {
t.Fatalf("NewNode: %v", err)
}
defer n.Wait()
httpSrv := httptest.NewServer(newHTTPHandler(n, 8080, "example.com"))
defer httpSrv.Close()
......@@ -145,4 +159,5 @@ func TestNode_StatusPage(t *testing.T) {
t.Fatalf("http.Get(/player/) error: HTTP: %s", resp.Status)
}
cancel()
}
......@@ -11,7 +11,7 @@ import (
"time"
"git.autistici.org/ale/autoradio/node/acme"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/client/v3"
"golang.org/x/sync/errgroup"
)
......
......@@ -9,14 +9,11 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"strconv"
"testing"
"time"
"go.etcd.io/etcd/clientv3/concurrency"
"go.etcd.io/etcd/embed"
"go.etcd.io/etcd/etcdserver/api/v3client"
"go.etcd.io/etcd/client/v3/concurrency"
"git.autistici.org/ale/autoradio/client"
pb "git.autistici.org/ale/autoradio/proto"
......@@ -47,18 +44,11 @@ func fakeDialer(real string) *http.Transport {
}
func TestServer(t *testing.T) {
cfg := embed.NewConfig()
cfg.Dir = "default.etcd"
defer os.RemoveAll(cfg.Dir)
e, err := embed.StartEtcd(cfg)
if err != nil {
t.Fatalf("StartEtcd: %v", err)
}
defer e.Close()
<-e.Server.ReadyNotify()
cli, cleanup := createTestEtcd(t)
defer cleanup()
cli := v3client.New(e.Server)
session, _ := concurrency.NewSession(cli, concurrency.WithTTL(2))
defer session.Close()
ctx, cancel := context.WithCancel(context.Background())
upstream, icecastPort := fakeAudioServer()
......
......@@ -13,7 +13,7 @@ import (
"git.autistici.org/ale/autoradio/coordination/presence"
pb "git.autistici.org/ale/autoradio/proto"
"git.autistici.org/ale/autoradio/util"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/client/v3"
"google.golang.org/grpc"
)
......@@ -52,6 +52,8 @@ func withoutNode(nodes []*pb.Status, name string) []*pb.Status {
}
type statusManager struct {
pb.UnimplementedGossipServiceServer
peers *presence.EndpointSet
conns *util.ConnCache
......
package autoradio
package proto
import (
"errors"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment