Skip to content

Commit 43cd4e9

Browse files
committed
etcd_docker 3: Incorporate docker based etcd integration package into… (#4147)
PR 3 for #4144 High level approach is as described in #4144 . This PR incorporates the new test package into our unittests. Usage is via the `etcdintegration` package, which makes it transparent to the test code; it simply gets an etcd server started via different means. One piece of weirdness to call out here: the package currently relies on autosync being *disabled* on the client side. This is because the advertise client URL (aka what etcd tells clients to connect to) isn't correct for the open port on the host. That is we have: - etcd: listen on container port 0.0.0.0:2379, advertise 0.0.0.0:2379 - docker: expose etcd port 2379 to 0.0.0.0:0 on host machine (random free port) - client: connect to etcd via host machine. We could probably make this better. commit-id:263fed13
1 parent 240dcf4 commit 43cd4e9

29 files changed

Lines changed: 257 additions & 227 deletions

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ require (
7070
go.etcd.io/etcd/client/pkg/v3 v3.6.0-alpha.0
7171
go.etcd.io/etcd/client/v3 v3.6.0-alpha.0
7272
go.etcd.io/etcd/server/v3 v3.6.0-alpha.0
73-
go.etcd.io/etcd/tests/v3 v3.6.0-alpha.0
7473
go.opentelemetry.io/collector v0.45.0
7574
go.opentelemetry.io/otel v1.4.1
7675
go.opentelemetry.io/otel/bridge/opentracing v1.4.1
@@ -121,7 +120,6 @@ require (
121120
github.com/go-playground/locales v0.13.0 // indirect
122121
github.com/go-playground/universal-translator v0.17.0 // indirect
123122
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
124-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
125123
github.com/google/btree v1.0.1 // indirect
126124
github.com/gorilla/handlers v1.5.1 // indirect
127125
github.com/gorilla/websocket v1.4.2 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,8 +1592,6 @@ go.etcd.io/etcd/raft/v3 v3.6.0-alpha.0 h1:BQ6CnNP4pIpy5rusFlTBxAacDgPXhuiHFwoTsB
15921592
go.etcd.io/etcd/raft/v3 v3.6.0-alpha.0/go.mod h1:/kZdrBXlc5fUgYXfIEQ0B5sb7ejXPKbtF4jWzF1exiQ=
15931593
go.etcd.io/etcd/server/v3 v3.6.0-alpha.0 h1:BQUVqBqNFZZyrRbfydrRLzq9hYvCcRj97SsX1YwD7CA=
15941594
go.etcd.io/etcd/server/v3 v3.6.0-alpha.0/go.mod h1:3QM2rLq3B3hSXmVEvgVt3vEEbG/AumSs0Is7EgrlKzU=
1595-
go.etcd.io/etcd/tests/v3 v3.6.0-alpha.0 h1:3qrZ3p/E7CxdV1kKtAU75hHOcUoXcSTwC7ELKWyzMJo=
1596-
go.etcd.io/etcd/tests/v3 v3.6.0-alpha.0/go.mod h1:hFQkP/cTsZIXXvUv+BsGHZ3TK+76XZMi5GToYA94iac=
15971595
go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
15981596
go.mongodb.org/mongo-driver v1.1.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
15991597
go.mongodb.org/mongo-driver v1.1.2/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=

src/aggregator/integration/custom_aggregations_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2016 Uber Technologies, Inc.
44
//
@@ -68,7 +68,6 @@ func testCustomAggregations(t *testing.T, metadataFns [4]metadataFn) {
6868
if testing.Short() {
6969
t.SkipNow()
7070
}
71-
7271
aggTypesOpts := aggregation.NewTypesOptions().
7372
SetCounterTypeStringTransformFn(aggregation.SuffixTransform).
7473
SetTimerTypeStringTransformFn(aggregation.SuffixTransform).
@@ -179,7 +178,7 @@ func testCustomAggregations(t *testing.T, metadataFns [4]metadataFn) {
179178
// must be the longer than the lowest resolution across all policies.
180179
finalTime := end.Add(6 * time.Second)
181180
clock.SetNow(finalTime)
182-
time.Sleep(6 * time.Second)
181+
time.Sleep(waitForDataToFlush)
183182

184183
require.NoError(t, client.close())
185184

src/aggregator/integration/election.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import (
2626
"github.com/m3db/m3/src/cluster/services"
2727
"github.com/m3db/m3/src/cluster/services/leader"
2828

29+
integration "github.com/m3db/m3/src/integration/resources/docker/dockerexternal/etcdintegration"
2930
"github.com/stretchr/testify/require"
3031
clientv3 "go.etcd.io/etcd/client/v3"
31-
"go.etcd.io/etcd/tests/v3/framework/integration"
3232
)
3333

3434
var (
@@ -40,27 +40,38 @@ var (
4040
)
4141

4242
type testCluster struct {
43-
t *testing.T
44-
cluster *integration.Cluster
43+
t *testing.T
44+
cluster *integration.Cluster
45+
leaderService services.LeaderService
4546
}
4647

4748
func newTestCluster(t *testing.T) *testCluster {
4849
integration.BeforeTestExternal(t)
49-
return &testCluster{
50+
cluster := &testCluster{
5051
t: t,
5152
cluster: integration.NewCluster(t, &integration.ClusterConfig{
5253
Size: testClusterSize,
54+
// UseBridge: true,
5355
}),
5456
}
57+
return cluster
5558
}
5659

5760
func (tc *testCluster) LeaderService() services.LeaderService {
61+
if tc.leaderService != nil {
62+
return tc.leaderService
63+
}
64+
5865
svc, err := leader.NewService(tc.etcdClient(), tc.options())
5966
require.NoError(tc.t, err)
60-
return svc
67+
tc.leaderService = svc
68+
return tc.leaderService
6169
}
6270

6371
func (tc *testCluster) Close() {
72+
if tc.leaderService != nil {
73+
require.NoError(tc.t, tc.leaderService.Close())
74+
}
6475
tc.cluster.Terminate(tc.t)
6576
}
6677

src/aggregator/integration/metadata_change_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2016 Uber Technologies, Inc.
44
//
@@ -138,7 +138,7 @@ func testMetadataChange(t *testing.T, oldMetadataFn, newMetadataFn metadataFn) {
138138
// must be the longer than the lowest resolution across all policies.
139139
finalTime := end.Add(6 * time.Second)
140140
clock.SetNow(finalTime)
141-
time.Sleep(6 * time.Second)
141+
time.Sleep(waitForDataToFlush)
142142

143143
require.NoError(t, client.close())
144144

src/aggregator/integration/multi_client_one_type_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2016 Uber Technologies, Inc.
44
//
@@ -126,7 +126,7 @@ func testMultiClientOneType(t *testing.T, metadataFn metadataFn) {
126126
// must be the longer than the lowest resolution across all policies.
127127
finalTime := stop.Add(6 * time.Second)
128128
clock.SetNow(finalTime)
129-
time.Sleep(4 * time.Second)
129+
time.Sleep(waitForDataToFlush)
130130

131131
for i := 0; i < numClients; i++ {
132132
require.NoError(t, clients[i].close())

src/aggregator/integration/multi_server_forwarding_pipeline_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2018 Uber Technologies, Inc.
44
//

src/aggregator/integration/multi_server_resend_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build integration
2-
// +build integration
32

43
// Copyright (c) 2018 Uber Technologies, Inc.
54
//
@@ -142,6 +141,7 @@ func TestMultiServerResendAggregatedValues(t *testing.T) {
142141

143142
// Election cluster setup.
144143
electionCluster := newTestCluster(t)
144+
defer electionCluster.Close()
145145

146146
// Sharding function maps all metrics to shard 0 except for the rollup metric,
147147
// which gets mapped to the last shard.

src/aggregator/integration/one_client_multi_type_forwarded_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2018 Uber Technologies, Inc.
44
//
@@ -121,7 +121,7 @@ func TestOneClientMultiTypeForwardedMetrics(t *testing.T) {
121121
// Move time forward and wait for flushing to happen.
122122
finalTime := stop.Add(2 * time.Second)
123123
clock.SetNow(finalTime)
124-
time.Sleep(2 * time.Second)
124+
time.Sleep(waitForDataToFlush)
125125

126126
require.NoError(t, client.close())
127127

src/aggregator/integration/one_client_multi_type_timed_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build integration
1+
//go:build integration
22

33
// Copyright (c) 2018 Uber Technologies, Inc.
44
//
@@ -119,7 +119,7 @@ func TestOneClientMultiTypeTimedMetrics(t *testing.T) {
119119
// Move time forward and wait for flushing to happen.
120120
finalTime := stop.Add(time.Minute + 2*time.Second)
121121
clock.SetNow(finalTime)
122-
time.Sleep(2 * time.Second)
122+
time.Sleep(waitForDataToFlush)
123123

124124
require.NoError(t, client.close())
125125

0 commit comments

Comments
 (0)