Skip to content

Commit

Permalink
Baseline dump mode
Browse files Browse the repository at this point in the history
  • Loading branch information
howardjohn committed Aug 17, 2022
1 parent 002bb15 commit 1199aae
Show file tree
Hide file tree
Showing 11 changed files with 430 additions and 13 deletions.
2 changes: 1 addition & 1 deletion adsc/adsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
"github.com/envoyproxy/go-control-plane/pkg/resource/v3"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
structpb "github.com/golang/protobuf/ptypes/struct"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"

"istio.io/pkg/log"
)
Expand Down
1 change: 1 addition & 0 deletions adsc/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
udpa "github.com/cncf/udpa/go/udpa/type/v1"

_ "istio.io/api/envoy/config/filter/http/alpn/v2alpha1"
_ "istio.io/api/envoy/config/filter/network/metadata_exchange"
_ "istio.io/istio/pkg/config/xds"
)

Expand Down
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func init() {
startupCmd,
xdsLatencyCmd,
reproduceCmd,
dumpCmd,
)
}

Expand Down
37 changes: 37 additions & 0 deletions cmd/dump.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cmd

import (
"fmt"

"github.com/howardjohn/pilot-load/pkg/simulation"
"github.com/howardjohn/pilot-load/pkg/simulation/model"
"github.com/spf13/cobra"
)

var dumpConfig = model.DumpConfig{}

func init() {
dumpCmd.PersistentFlags().StringVar(&dumpConfig.Pod, "pod", dumpConfig.Pod, "pod to dump from")
dumpCmd.PersistentFlags().StringVar(&dumpConfig.Namespace, "namespace", dumpConfig.Namespace, "namespace to dump from")
dumpCmd.PersistentFlags().StringVar(&dumpConfig.OutputDir, "out", dumpConfig.OutputDir, "output directory")
}

var dumpCmd = &cobra.Command{
Use: "dump",
Short: "dump XDS for a pod to file, rewritten to be runnable with only files",
RunE: func(cmd *cobra.Command, _ []string) error {
args, err := GetArgs()
if err != nil {
return err
}
if dumpConfig.Pod == "" {
return fmt.Errorf("--pod required")
}
if dumpConfig.Namespace == "" {
return fmt.Errorf("--namespace required")
}
args.DumpConfig = dumpConfig
logConfig(args.DumpConfig)
return simulation.Dump(args)
},
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/google/go-cmp v0.5.8
github.com/lthibault/jitterbug v2.0.0+incompatible
github.com/spf13/cobra v1.5.0
golang.org/x/exp v0.0.0-20220407100705-7b9b53b0aca4
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
google.golang.org/api v0.93.0
google.golang.org/grpc v1.48.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220407100705-7b9b53b0aca4 h1:K3x+yU+fbot38x5bQbU2QqUAVyYLEktdNH2GxZLnM3U=
golang.org/x/exp v0.0.0-20220407100705-7b9b53b0aca4/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
25 changes: 13 additions & 12 deletions pkg/simulation/determinism.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import (
"fmt"
"sync"

"github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
"github.com/howardjohn/pilot-load/adsc"
"github.com/howardjohn/pilot-load/pkg/simulation/model"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"
"istio.io/pkg/log"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
klabels "k8s.io/apimachinery/pkg/labels"
corev1 "k8s.io/client-go/informers/core/v1"

"github.com/howardjohn/pilot-load/adsc"
"github.com/howardjohn/pilot-load/pkg/simulation/model"
"istio.io/pkg/log"
)

type DeterministicSimulation struct{}
Expand Down Expand Up @@ -93,11 +94,11 @@ func (d DeterministicSimulation) checkPod(ctx model.Context, pod *v1.Pod, addres
wg.Add(1)
go func() {
res, err := adsc.Fetch(addr, &adsc.Config{
Namespace: pod.Namespace,
Workload: pod.Name,
Meta: meta,
IP: ip,
Context: ctx,
Namespace: pod.Namespace,
Workload: pod.Name,
Meta: meta,
IP: ip,
Context: ctx,
StoreResponses: true,
})
if err != nil {
Expand Down Expand Up @@ -155,16 +156,16 @@ func compare(base, comp map[string]proto.Message) string {
if diff := cmp.Diff(got, want, protocmp.Transform()); diff != "" {
return fmt.Sprintf("proto diff: %v", diff)
}
gots := marshaler.Text(got)
wants := marshaler.Text(want)
gots := marshaler.Format(got)
wants := marshaler.Format(want)
if gots != wants {
return fmt.Sprintf("text diff:\n%v\n%v\n", gots, wants)
}
}
return ""
}

var marshaler = proto.TextMarshaler{ExpandAny: true}
var marshaler = prototext.MarshalOptions{}

func (d DeterministicSimulation) Cleanup(ctx model.Context) error {
return nil
Expand Down
Loading

0 comments on commit 1199aae

Please sign in to comment.