Skip to content

Commit 2b23474

Browse files
committed
Move to generic types
1 parent 522822d commit 2b23474

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1328
-877
lines changed

adsc/adsc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
structpb "github.com/golang/protobuf/ptypes/struct"
2525
"google.golang.org/grpc"
2626
"google.golang.org/protobuf/proto"
27+
"istio.io/istio/pkg/log"
2728
"istio.io/istio/pkg/util/sets"
28-
"istio.io/pkg/log"
2929
)
3030

3131
var (

adsc/load.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import (
88
)
99

1010
func Fetch(pilotAddress string, config *Config) (*Responses, error) {
11-
log := func(template string, args ...interface{}) {
12-
a := []interface{}{"%v: " + template, config.Workload}
13-
a = append(a, args...)
14-
scope.Infof(a...)
15-
}
11+
log := scope.WithLabels("workload", config.Workload).Infof
1612
watchAll := map[string]struct{}{"cds": {}, "eds": {}, "rds": {}, "lds": {}}
1713
log("Connecting: %v", config.IP)
1814
con, err := Dial(pilotAddress, config)
@@ -51,11 +47,7 @@ func Fetch(pilotAddress string, config *Config) (*Responses, error) {
5147

5248
func Connect(pilotAddress string, config *Config) {
5349
attempts := 0
54-
log := func(template string, args ...interface{}) {
55-
a := []interface{}{"%v: " + template, config.Workload}
56-
a = append(a, args...)
57-
scope.Infof(a...)
58-
}
50+
log := scope.WithLabels("workload", config.Workload).Infof
5951
// Follow envoy defaults https://github.com/envoyproxy/envoy/blob/v1.12.1/source/common/config/grpc_stream.h#L40-L43
6052
b := backoff.NewExponentialBackOff()
6153
b.MaxElapsedTime = 0

cmd/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/ghodss/yaml"
88
"github.com/spf13/cobra"
9-
"istio.io/pkg/log"
9+
"istio.io/istio/pkg/log"
1010

1111
"github.com/howardjohn/pilot-load/pkg/simulation"
1212
"github.com/howardjohn/pilot-load/pkg/simulation/model"

cmd/cmd.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/ghodss/yaml"
1010
"github.com/spf13/cobra"
11-
"istio.io/pkg/log"
11+
"istio.io/istio/pkg/log"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1313
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
1414

@@ -107,7 +107,7 @@ func setDefaultArgs(args model.Args) (model.Args, error) {
107107
return model.Args{}, err
108108
}
109109
if _, f := xdsMetadata[CLOUDRUN_ADDR]; !f && args.Auth.Type == security.AuthTypeGoogle {
110-
mwh, err := args.Client.Kubernetes.AdmissionregistrationV1().MutatingWebhookConfigurations().Get(context.Background(), "istiod-asm-managed", metav1.GetOptions{})
110+
mwh, err := args.Client.Kube().AdmissionregistrationV1().MutatingWebhookConfigurations().Get(context.Background(), "istiod-asm-managed", metav1.GetOptions{})
111111
if err != nil {
112112
return model.Args{}, fmt.Errorf("failed to default CLOUDRUN_ADDR: %v", err)
113113
}
@@ -130,8 +130,6 @@ var rootCmd = &cobra.Command{
130130
Short: "open XDS connections to pilot",
131131
SilenceUsage: true,
132132
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
133-
log.FindScope("dump").SetOutputLevel(log.WarnLevel)
134-
135133
return log.Configure(loggingOptions)
136134
},
137135
}
@@ -154,6 +152,7 @@ func init() {
154152
xdsLatencyCmd,
155153
reproduceCmd,
156154
dumpCmd,
155+
isolatedCmd,
157156
)
158157
}
159158

cmd/impersonate.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ func init() {
1616
impersonateCmd.PersistentFlags().DurationVar(&impersonateConfig.Delay, "delay", impersonateConfig.Delay, "delay between each connection")
1717
impersonateCmd.PersistentFlags().IntVar(&impersonateConfig.Replicas, "replicas", impersonateConfig.Replicas, "number of connections to make for each pod")
1818
impersonateCmd.PersistentFlags().StringVar(&impersonateConfig.Selector, "selector", impersonateConfig.Selector, "selector to use {sidecar,external,both}")
19-
impersonateCmd.PersistentFlags().BoolVar(&impersonateConfig.Watch, "watch", impersonateConfig.Watch, "watch for pod changes")
2019
}
2120

2221
var impersonateCmd = &cobra.Command{

cmd/isolated.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net"
7+
"net/http"
8+
"os"
9+
"runtime/pprof"
10+
11+
"github.com/spf13/cobra"
12+
"istio.io/istio/pilot/pkg/features"
13+
"istio.io/istio/pilot/pkg/xds"
14+
"istio.io/istio/pkg/log"
15+
"istio.io/istio/pkg/test"
16+
"k8s.io/apimachinery/pkg/watch"
17+
18+
"github.com/howardjohn/pilot-load/pkg/kube"
19+
"github.com/howardjohn/pilot-load/pkg/simulation"
20+
"github.com/howardjohn/pilot-load/pkg/simulation/isolated"
21+
"github.com/howardjohn/pilot-load/pkg/simulation/model"
22+
"github.com/howardjohn/pilot-load/pkg/simulation/monitoring"
23+
"github.com/howardjohn/pilot-load/pkg/simulation/security"
24+
)
25+
26+
func init() {
27+
isolatedCmd.PersistentFlags().StringVarP(&configFile, "config", "c", configFile, "config file")
28+
}
29+
30+
func WithProfiling(c *cobra.Command) *cobra.Command {
31+
var cpuProfile string
32+
var memProfile string
33+
c.PersistentFlags().StringVar(&cpuProfile, "cpuprofile", cpuProfile, "file to write cpu profile to")
34+
c.PersistentFlags().StringVar(&memProfile, "memprofile", memProfile, "file to write memory profile to")
35+
orig := c.RunE
36+
c.RunE = func(cmd *cobra.Command, args []string) error {
37+
if cpuProfile != "" {
38+
f, err := os.Create(cpuProfile)
39+
if err != nil {
40+
return err
41+
}
42+
if err := pprof.StartCPUProfile(f); err != nil {
43+
return err
44+
}
45+
defer pprof.StopCPUProfile()
46+
}
47+
if memProfile != "" {
48+
f, err := os.Create(memProfile)
49+
if err != nil {
50+
return err
51+
}
52+
defer func() {
53+
pprof.WriteHeapProfile(f)
54+
}()
55+
}
56+
return orig(cmd, args)
57+
}
58+
return c
59+
}
60+
61+
func executeSimulations(a model.Args, s model.Simulation) error {
62+
ctx, cancel := context.WithCancel(context.Background())
63+
go simulation.CaptureTermination(ctx, cancel)
64+
defer cancel()
65+
simulationContext := model.Context{Context: ctx, Args: a, Client: a.Client, Cancel: cancel}
66+
if err := s.Run(simulationContext); err != nil {
67+
log.Errorf("failed: %v, starting cleanup", err)
68+
cleanupErr := s.Cleanup(simulationContext)
69+
return fmt.Errorf("failed to run: %v; cleanup: %v", err, cleanupErr)
70+
}
71+
<-ctx.Done()
72+
return s.Cleanup(simulationContext)
73+
}
74+
75+
var isolatedCmd = WithProfiling(&cobra.Command{
76+
Use: "isolated",
77+
Short: "simulate a full cluster in a single binary",
78+
RunE: func(cmd *cobra.Command, _ []string) error {
79+
var ds *xds.FakeDiscoveryServer
80+
ready := make(chan struct{})
81+
done := make(chan struct{})
82+
defer func() {
83+
close(done)
84+
}()
85+
// Bump up QPS of requests so test starts faster
86+
features.RequestLimit = 200.0
87+
// Kube fake explodes too early
88+
watch.DefaultChanSize = 10_000
89+
go test.Wrap(func(t test.Failer) {
90+
ds = xds.NewFakeDiscoveryServer(t, xds.FakeOptions{
91+
ListenerBuilder: func() (net.Listener, error) {
92+
return net.Listen("tcp", "127.0.0.1:0")
93+
},
94+
})
95+
close(ready)
96+
<-done
97+
})
98+
<-ready
99+
ms := monitoring.StartMonitoring(8765)
100+
ds.Discovery.InitDebug(ms.Handler.(*http.ServeMux), false, func() map[string]string {
101+
return nil
102+
})
103+
104+
args := model.Args{
105+
PilotAddress: ds.Listener.Addr().String(),
106+
Client: kube.NewFakeClient(ds.KubeClient()),
107+
Auth: &security.AuthOptions{
108+
Type: security.AuthTypePlaintext,
109+
},
110+
}
111+
config, err := readConfigFile(configFile)
112+
if err != nil {
113+
return fmt.Errorf("failed to read config file: %v", err)
114+
}
115+
config = config.ApplyDefaults()
116+
117+
logConfig(config)
118+
logClusterConfig(config)
119+
log.Infof("Starting cluster, total size: %v pods", config.PodCount())
120+
121+
sim := isolated.NewCluster(isolated.IsolatedSpec{Config: config})
122+
if err := executeSimulations(args, sim); err != nil {
123+
return fmt.Errorf("error executing: %v", err)
124+
}
125+
126+
return nil
127+
},
128+
})

examples/big.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
nodeMetadata: {}
22
jitter:
3-
workloads: "30s"
3+
workloads: "110ms"
44
config: "0s"
55
namespaces:
66
- name: mesh
77
replicas: 1
88
applications:
99
- name: big
10-
replicas: 1
11-
instances: 1000
10+
replicas: 200
11+
instances: 10
1212
nodes:
1313
- name: node
1414
count: 10

0 commit comments

Comments
 (0)