Skip to content

Commit

Permalink
start writing test client
Browse files Browse the repository at this point in the history
Signed-off-by: Alec Holmes <[email protected]>
  • Loading branch information
alecholmez committed Aug 4, 2021
1 parent 6cfa5af commit bce9cd9
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 0 deletions.
3 changes: 3 additions & 0 deletions benchmarks/client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Benchmark Client

This test client provides simulation of various workloads when communicating with the go-control-plane management server.
47 changes: 47 additions & 0 deletions benchmarks/client/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"log"
"os"
"runtime"
"time"

"github.com/envoyproxy/go-control-plane/benchmarks/client/xds"
"github.com/urfave/cli/v2"
)

func main() {
// Statically set the max procs
runtime.GOMAXPROCS(runtime.NumCPU())

app := &cli.App{
Name: "xds-benchmark",
Usage: "xds benchmarking tool that simulates client workload",
Commands: []*cli.Command{
{
Name: "run",
Aliases: []string{"r"},
Usage: "run the benchmark with the provided duration",
Action: func(c *cli.Context) error {
arg := c.Args().First()
dur, err := time.ParseDuration(arg)
if err != nil {
return err
}

sess, err := xds.NewSession("localhost:50000")
if err != nil {
return err
}

return sess.Simulate(dur)
},
},
},
}

err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
48 changes: 48 additions & 0 deletions benchmarks/client/xds/opts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package xds

// Options are configuration settings for the discovery object
type Options struct {
NodeID string
Zone string
Cluster string
ResourceNames []string // List of Envoy resource names to subscribe to
ResourceType string // ex: type.googleapis.com/envoy.api.v2.ClusterLoadAssignment
}

// Option follows the functional opts pattern
type Option func(*Options)

// WithNode will inject the node id into the configuration object
func WithNode(id string) Option {
return func(o *Options) {
o.NodeID = id
}
}

// WithZone will specificy which zone to use in the xDS discovery request
func WithZone(zone string) Option {
return func(o *Options) {
o.Zone = zone
}
}

// WithCluster will specificy which cluster the request is announcing as
func WithCluster(cluster string) Option {
return func(o *Options) {
o.Cluster = cluster
}
}

// WithResourceNames will inject a list of resources the user wants to place watches on
func WithResourceNames(names []string) Option {
return func(o *Options) {
o.ResourceNames = names
}
}

// WithResourceType will inject the specific resource type that a user wants to stream
func WithResourceType(resource string) Option {
return func(o *Options) {
o.ResourceType = resource
}
}
45 changes: 45 additions & 0 deletions benchmarks/client/xds/xds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package xds

import (
"time"

"google.golang.org/grpc"
)

// Sess holds a grpc connection as well as config options to use during the simulation
type Sess struct {
Session *grpc.ClientConn
Opts Options
}

// NewSession will dial a new benchmarking session with the configured options
func NewSession(url string, opts ...Option) (*Sess, error) {
var options Options
for _, o := range opts {
o(&options)
}

conn, err := grpc.Dial(url, grpc.WithBlock(), grpc.WithInsecure())
if err != nil {
return nil, err
}

return &Sess{
Session: conn,
Opts: options,
}, nil
}

// Simulate will start an xDS stream which provides simulatest clients communicating with an xDS server
func (s *Sess) Simulate(target time.Duration) error {
// Create a loop that will continually do work until the elapsed time as passed
for timeout := time.After(target); ; {
select {
case <-timeout:
return nil
default:
// Do some work

}
}
}
1 change: 1 addition & 0 deletions benchmarks/client/xds/xds_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package xds
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/pkg/profile v1.6.0
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4
github.com/stretchr/testify v1.7.0
github.com/urfave/cli/v2 v2.3.0
go.opentelemetry.io/proto/otlp v0.7.0
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/grpc v1.36.0
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed h1:OZmjad4L3H8ncOIR8rnb5MREYqG8ixi5+WbeUsquF0c=
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -47,10 +49,16 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
go.opentelemetry.io/proto/otlp v0.7.0 h1:rwOQPCuKAKmwGKq2aVNnYIibI6wnV7EvzgfTCzcdGg8=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down

0 comments on commit bce9cd9

Please sign in to comment.