Skip to content

Commit bce9cd9

Browse files
committed
start writing test client
Signed-off-by: Alec Holmes <[email protected]>
1 parent 6cfa5af commit bce9cd9

File tree

7 files changed

+153
-0
lines changed

7 files changed

+153
-0
lines changed

Diff for: benchmarks/client/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Benchmark Client
2+
3+
This test client provides simulation of various workloads when communicating with the go-control-plane management server.

Diff for: benchmarks/client/main.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
"runtime"
7+
"time"
8+
9+
"github.com/envoyproxy/go-control-plane/benchmarks/client/xds"
10+
"github.com/urfave/cli/v2"
11+
)
12+
13+
func main() {
14+
// Statically set the max procs
15+
runtime.GOMAXPROCS(runtime.NumCPU())
16+
17+
app := &cli.App{
18+
Name: "xds-benchmark",
19+
Usage: "xds benchmarking tool that simulates client workload",
20+
Commands: []*cli.Command{
21+
{
22+
Name: "run",
23+
Aliases: []string{"r"},
24+
Usage: "run the benchmark with the provided duration",
25+
Action: func(c *cli.Context) error {
26+
arg := c.Args().First()
27+
dur, err := time.ParseDuration(arg)
28+
if err != nil {
29+
return err
30+
}
31+
32+
sess, err := xds.NewSession("localhost:50000")
33+
if err != nil {
34+
return err
35+
}
36+
37+
return sess.Simulate(dur)
38+
},
39+
},
40+
},
41+
}
42+
43+
err := app.Run(os.Args)
44+
if err != nil {
45+
log.Fatal(err)
46+
}
47+
}

Diff for: benchmarks/client/xds/opts.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package xds
2+
3+
// Options are configuration settings for the discovery object
4+
type Options struct {
5+
NodeID string
6+
Zone string
7+
Cluster string
8+
ResourceNames []string // List of Envoy resource names to subscribe to
9+
ResourceType string // ex: type.googleapis.com/envoy.api.v2.ClusterLoadAssignment
10+
}
11+
12+
// Option follows the functional opts pattern
13+
type Option func(*Options)
14+
15+
// WithNode will inject the node id into the configuration object
16+
func WithNode(id string) Option {
17+
return func(o *Options) {
18+
o.NodeID = id
19+
}
20+
}
21+
22+
// WithZone will specificy which zone to use in the xDS discovery request
23+
func WithZone(zone string) Option {
24+
return func(o *Options) {
25+
o.Zone = zone
26+
}
27+
}
28+
29+
// WithCluster will specificy which cluster the request is announcing as
30+
func WithCluster(cluster string) Option {
31+
return func(o *Options) {
32+
o.Cluster = cluster
33+
}
34+
}
35+
36+
// WithResourceNames will inject a list of resources the user wants to place watches on
37+
func WithResourceNames(names []string) Option {
38+
return func(o *Options) {
39+
o.ResourceNames = names
40+
}
41+
}
42+
43+
// WithResourceType will inject the specific resource type that a user wants to stream
44+
func WithResourceType(resource string) Option {
45+
return func(o *Options) {
46+
o.ResourceType = resource
47+
}
48+
}

Diff for: benchmarks/client/xds/xds.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package xds
2+
3+
import (
4+
"time"
5+
6+
"google.golang.org/grpc"
7+
)
8+
9+
// Sess holds a grpc connection as well as config options to use during the simulation
10+
type Sess struct {
11+
Session *grpc.ClientConn
12+
Opts Options
13+
}
14+
15+
// NewSession will dial a new benchmarking session with the configured options
16+
func NewSession(url string, opts ...Option) (*Sess, error) {
17+
var options Options
18+
for _, o := range opts {
19+
o(&options)
20+
}
21+
22+
conn, err := grpc.Dial(url, grpc.WithBlock(), grpc.WithInsecure())
23+
if err != nil {
24+
return nil, err
25+
}
26+
27+
return &Sess{
28+
Session: conn,
29+
Opts: options,
30+
}, nil
31+
}
32+
33+
// Simulate will start an xDS stream which provides simulatest clients communicating with an xDS server
34+
func (s *Sess) Simulate(target time.Duration) error {
35+
// Create a loop that will continually do work until the elapsed time as passed
36+
for timeout := time.After(target); ; {
37+
select {
38+
case <-timeout:
39+
return nil
40+
default:
41+
// Do some work
42+
43+
}
44+
}
45+
}

Diff for: benchmarks/client/xds/xds_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package xds

Diff for: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/pkg/profile v1.6.0
1212
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4
1313
github.com/stretchr/testify v1.7.0
14+
github.com/urfave/cli/v2 v2.3.0
1415
go.opentelemetry.io/proto/otlp v0.7.0
1516
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
1617
google.golang.org/grpc v1.36.0

Diff for: go.sum

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
99
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
1010
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed h1:OZmjad4L3H8ncOIR8rnb5MREYqG8ixi5+WbeUsquF0c=
1111
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
12+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
13+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
1214
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
1315
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1416
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
@@ -47,10 +49,16 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
4749
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM=
4850
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
4951
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
52+
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
53+
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
54+
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
55+
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
5056
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
5157
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
5258
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
5359
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
60+
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
61+
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
5462
go.opentelemetry.io/proto/otlp v0.7.0 h1:rwOQPCuKAKmwGKq2aVNnYIibI6wnV7EvzgfTCzcdGg8=
5563
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
5664
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

0 commit comments

Comments
 (0)