Skip to content

Commit

Permalink
Merge branch 'main' into rolds/test_failure_collect_metrics_dump
Browse files Browse the repository at this point in the history
  • Loading branch information
nfuden authored Nov 26, 2024
2 parents 49d65dd + 2635711 commit 34ee46c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 18 deletions.
7 changes: 7 additions & 0 deletions changelog/v1.18.0-rc3/docs-cleanchangelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
changelog:
- type: NON_USER_FACING
resolvesIssue: true
description: >-
Clean docgen
skipCI-kube-tests:true
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ require (
github.com/saiskee/gettercheck v0.0.0-20210820204958-38443d06ebe0
github.com/sergi/go-diff v1.2.0
github.com/solo-io/go-list-licenses v0.1.4
github.com/solo-io/go-utils v0.27.2
github.com/solo-io/go-utils v0.27.3
github.com/solo-io/k8s-utils v0.8.1
github.com/solo-io/protoc-gen-ext v0.0.25
github.com/solo-io/protoc-gen-openapi v0.2.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2695,8 +2695,8 @@ github.com/solo-io/cue v0.4.7/go.mod h1:P1tN9y6nBPAMoEK5aJxI8kn0VUcjVcRc+8esieRz
github.com/solo-io/go-list-licenses v0.1.4 h1:u4xh1OUORT4iSWuAp3Q4NsfHcDaeUV8QRDH8ACQqbxw=
github.com/solo-io/go-list-licenses v0.1.4/go.mod h1:x6LSp/NrYgVXwNum7ZOiaAYTpg6B3F6TrWYfcdHVroA=
github.com/solo-io/go-utils v0.20.2/go.mod h1:6e8K1spnMWwlnJRSNp/J84GEyJbrcK4Gm7i+ehzCi8c=
github.com/solo-io/go-utils v0.27.2 h1:4ixkKeOYsBVAL72mNUYfAUfqi5+ws3p6ztlKrG3A3Bg=
github.com/solo-io/go-utils v0.27.2/go.mod h1:cwbQIYO1/BeU4aPB0Yy8WzzS77dfVTZyCVqbA4YsRSY=
github.com/solo-io/go-utils v0.27.3 h1:1LxErw8pisPAuH1Vk6FKRgnvkwgm7mHrpjZow0hvfnA=
github.com/solo-io/go-utils v0.27.3/go.mod h1:cwbQIYO1/BeU4aPB0Yy8WzzS77dfVTZyCVqbA4YsRSY=
github.com/solo-io/k8s-utils v0.8.1 h1:Xqqze6RLWsHCYetbaiXDEnuhFRXyqw0azyogggK43H8=
github.com/solo-io/k8s-utils v0.8.1/go.mod h1:fOIFkh4+F45MmrUZEFx0pW75EvFYOR7v5/BIIQiSIwA=
github.com/solo-io/protoc-gen-ext v0.0.25 h1:UqNW/A4UqCO5aUFg7LYdV82tK0R2mqu7RFftYtT/Fu8=
Expand Down
56 changes: 41 additions & 15 deletions projects/gateway2/setup/ggv2setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sort"
"strings"
"sync"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -73,22 +74,30 @@ func getAssetsDir(t *testing.T) string {

// testingWriter is a WriteSyncer that writes logs to testing.T.
type testingWriter struct {
t *testing.T
t atomic.Value
}

func (w *testingWriter) Write(p []byte) (n int, err error) {
w.t.Log(string(p)) // Write the log to testing.T
w.t.Load().(*testing.T).Log(string(p)) // Write the log to testing.T
return len(p), nil
}

func (w *testingWriter) Sync() error {
return nil
}

// NewTestLogger creates a zap.Logger that writes to testing.T.
func NewTestLogger(t *testing.T) *zap.Logger {
writer := &testingWriter{t: t}
func (w *testingWriter) set(t *testing.T) {
w.t.Store(t)
}

var (
writer = &testingWriter{}
logger = NewTestLogger()
)

// NewTestLogger creates a zap.Logger which can be used to write to *testing.T
// on each test, set the *testing.T on the writer.
func NewTestLogger() *zap.Logger {
core := zapcore.NewCore(
zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()),
zapcore.AddSync(writer),
Expand All @@ -100,7 +109,13 @@ func NewTestLogger(t *testing.T) *zap.Logger {
return zap.New(core, zap.AddCaller())
}

func init() {
log.SetLogger(zapr.NewLogger(logger))

}

func TestScenarios(t *testing.T) {
writer.set(t)
os.Setenv("POD_NAMESPACE", "gwtest")
testEnv := &envtest.Environment{
CRDDirectoryPaths: []string{
Expand All @@ -118,11 +133,6 @@ func TestScenarios(t *testing.T) {

ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
logger := NewTestLogger(t)
t.Cleanup(func() { logger.Sync() })
// t.Cleanup(func() { _ = logger.Sync() })
log.SetLogger(zapr.NewLogger(logger))

ctx = contextutils.WithExistingLogger(ctx, logger.Sugar())

cfg, err := testEnv.Start()
Expand Down Expand Up @@ -212,9 +222,20 @@ func TestScenarios(t *testing.T) {
}
for _, f := range files {
// run tests with the yaml files (but not -out.yaml files)/s
parentT := t
if strings.HasSuffix(f.Name(), ".yaml") && !strings.HasSuffix(f.Name(), "-out.yaml") {
fullpath := filepath.Join("testdata", f.Name())
t.Run(strings.TrimSuffix(f.Name(), ".yaml"), func(t *testing.T) {
writer.set(t)
t.Cleanup(func() {
writer.set(parentT)
})
t.Cleanup(func() {
if t.Failed() {
j, _ := setupOpts.KrtDebugger.MarshalJSON()
t.Logf("krt state for failed test: %s %s", t.Name(), string(j))
}
})
//sadly tests can't run yet in parallel, as ggv2 will add all the k8s services as clusters. this means
// that we get test pollution.
// once we change it to only include the ones in the proxy, we can re-enable this
Expand All @@ -224,8 +245,6 @@ func TestScenarios(t *testing.T) {
})
}
}

t.Log("DONE")
}

func testScenario(t *testing.T, ctx context.Context, client istiokube.CLIClient, xdsPort int, f string) {
Expand Down Expand Up @@ -363,6 +382,7 @@ func (x *xdsDump) Compare(t *testing.T, other xdsDump) {
otherc := clusterset[c.Name]
if otherc == nil {
t.Errorf("cluster %v not found", c.Name)
continue
}
if !proto.Equal(c, otherc) {
t.Errorf("cluster %v not equal", c.Name)
Expand All @@ -376,6 +396,7 @@ func (x *xdsDump) Compare(t *testing.T, other xdsDump) {
otherc := listenerset[c.Name]
if otherc == nil {
t.Errorf("listener %v not found", c.Name)
continue
}
if !proto.Equal(c, otherc) {
t.Errorf("listener %v not equal", c.Name)
Expand All @@ -389,6 +410,7 @@ func (x *xdsDump) Compare(t *testing.T, other xdsDump) {
otherc := routeset[c.Name]
if otherc == nil {
t.Errorf("route %v not found", c.Name)
continue
}
if !proto.Equal(c, otherc) {
t.Errorf("route %v not equal: %v vs %v", c.Name, c, otherc)
Expand Down Expand Up @@ -590,14 +612,15 @@ func (x *xdsFetcher) getclusters(t *testing.T, ctx context.Context) []*envoyclus

epcli, err := cds.StreamClusters(ctx)
if err != nil {
t.Fatalf("failed to get eds client: %v", err)
t.Fatalf("failed to get cds client: %v", err)
}
defer epcli.CloseSend()
epcli.Send(x.dr)
dresp, err := epcli.Recv()
if err != nil {
t.Fatalf("failed to get response from xds server: %v", err)
}
t.Logf("got cds response. nonce, version: %s %s", dresp.GetNonce(), dresp.GetVersionInfo())
var clusters []*envoycluster.Cluster
for _, anyCluster := range dresp.GetResources() {

Expand Down Expand Up @@ -644,14 +667,15 @@ func (x *xdsFetcher) getlisteners(t *testing.T, ctx context.Context) []*envoylis

epcli, err := ds.StreamListeners(ctx)
if err != nil {
t.Fatalf("failed to get eds client: %v", err)
t.Fatalf("failed to get lds client: %v", err)
}
defer epcli.CloseSend()
epcli.Send(x.dr)
dresp, err := epcli.Recv()
if err != nil {
t.Fatalf("failed to get response from xds server: %v", err)
}
t.Logf("got lds response. nonce, version: %s %s", dresp.GetNonce(), dresp.GetVersionInfo())
var resources []*envoylistener.Listener
for _, anyResource := range dresp.GetResources() {

Expand Down Expand Up @@ -682,6 +706,7 @@ func (x *xdsFetcher) getendpoints(t *testing.T, ctx context.Context, clusterServ
if err != nil {
t.Fatalf("failed to get response from xds server: %v", err)
}
t.Logf("got eds response. nonce, version: %s %s", dresp.GetNonce(), dresp.GetVersionInfo())
var clas []*envoyendpoint.ClusterLoadAssignment
for _, anyCluster := range dresp.GetResources() {

Expand All @@ -705,7 +730,7 @@ func (x *xdsFetcher) getroutes(t *testing.T, ctx context.Context, rosourceNames

epcli, err := eds.StreamRoutes(ctx)
if err != nil {
t.Fatalf("failed to get eds client: %v", err)
t.Fatalf("failed to get rds client: %v", err)
}
defer epcli.CloseSend()
dr := proto.Clone(x.dr).(*discovery_v3.DiscoveryRequest)
Expand All @@ -715,6 +740,7 @@ func (x *xdsFetcher) getroutes(t *testing.T, ctx context.Context, rosourceNames
if err != nil {
t.Fatalf("failed to get response from xds server: %v", err)
}
t.Logf("got rds response. nonce, version: %s %s", dresp.GetNonce(), dresp.GetVersionInfo())
var clas []*envoy_config_route_v3.RouteConfiguration
for _, anyCluster := range dresp.GetResources() {

Expand Down

0 comments on commit 34ee46c

Please sign in to comment.