Skip to content

Commit 0c2ef7c

Browse files
committed
Added Outlier Detection Balancer
1 parent 29d9970 commit 0c2ef7c

File tree

7 files changed

+2969
-1
lines changed

7 files changed

+2969
-1
lines changed

internal/grpcrand/grpcrand.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ func Intn(n int) int {
5252
return r.Intn(n)
5353
}
5454

55+
// Int31n implements rand.Int31n on the grpcrand global source.
56+
func Int31n(n int32) int32 {
57+
mu.Lock()
58+
defer mu.Unlock()
59+
return r.Int31n(n)
60+
}
61+
5562
// Float64 implements rand.Float64 on the grpcrand global source.
5663
func Float64() float64 {
5764
mu.Lock()
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
*
3+
* Copyright 2022 gRPC authors.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package xds_test
20+
21+
import (
22+
"context"
23+
"fmt"
24+
"testing"
25+
26+
"google.golang.org/grpc"
27+
"google.golang.org/grpc/credentials/insecure"
28+
"google.golang.org/grpc/internal"
29+
"google.golang.org/grpc/internal/envconfig"
30+
"google.golang.org/grpc/internal/testutils/xds/e2e"
31+
32+
testgrpc "google.golang.org/grpc/test/grpc_testing"
33+
testpb "google.golang.org/grpc/test/grpc_testing"
34+
)
35+
36+
func (s) TestOutlierDetection(t *testing.T) {
37+
oldOD := envconfig.XDSOutlierDetection
38+
envconfig.XDSOutlierDetection = true
39+
internal.RegisterOutlierDetectionBalancerForTesting()
40+
defer func() {
41+
envconfig.XDSOutlierDetection = oldOD
42+
internal.UnregisterOutlierDetectionBalancerForTesting()
43+
}()
44+
45+
managementServer, nodeID, _, resolver, cleanup1 := e2e.SetupManagementServer(t)
46+
defer cleanup1()
47+
48+
port, cleanup2 := startTestService(t, nil)
49+
defer cleanup2()
50+
51+
const serviceName = "my-service-client-side-xds"
52+
resources := e2e.DefaultClientResources(e2e.ResourceParams{
53+
DialTarget: serviceName,
54+
NodeID: nodeID,
55+
Host: "localhost",
56+
Port: port,
57+
SecLevel: e2e.SecurityLevelNone,
58+
})
59+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
60+
defer cancel()
61+
if err := managementServer.Update(ctx, resources); err != nil {
62+
t.Fatal(err)
63+
}
64+
65+
// Create a ClientConn and make a successful RPC.
66+
cc, err := grpc.Dial(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolver))
67+
if err != nil {
68+
t.Fatalf("failed to dial local test server: %v", err)
69+
}
70+
defer cc.Close()
71+
72+
client := testgrpc.NewTestServiceClient(cc)
73+
if _, err := client.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); err != nil {
74+
t.Fatalf("rpc EmptyCall() failed: %v", err)
75+
}
76+
}

0 commit comments

Comments
 (0)