Skip to content

Commit

Permalink
pr comment
Browse files Browse the repository at this point in the history
  • Loading branch information
yuval-k committed Nov 28, 2024
1 parent f3b15dd commit c86e86d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
29 changes: 1 addition & 28 deletions projects/gateway2/setup/ggv2setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,33 +250,6 @@ func TestScenarios(t *testing.T) {
}
}

func dumpCache(snapCache cache.SnapshotCache) iosnapshot.SnapshotResponseData {
cacheKeys := snapCache.GetStatusKeys()
cacheEntries := make(map[string]interface{}, len(cacheKeys))

for _, k := range cacheKeys {
xdsSnapshot, err := getXdsSnapshot(snapCache, k)
if err != nil {
cacheEntries[k] = err.Error()
} else {
cacheEntries[k] = xdsSnapshot
}
}
return iosnapshot.SnapshotResponseData{
Data: cacheEntries,
Error: nil,
}

}
func getXdsSnapshot(snapCache cache.SnapshotCache, k string) (cache cache.Snapshot, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic occurred while getting xds snapshot: %v", r)
}
}()
return snapCache.GetSnapshot(k)
}

func testScenario(t *testing.T, ctx context.Context, kdbg *krt.DebugHandler, snapCache cache.SnapshotCache, client istiokube.CLIClient, xdsPort int, f string) {
fext := filepath.Ext(f)
fpre := strings.TrimSuffix(f, fext)
Expand Down Expand Up @@ -330,7 +303,7 @@ func testScenario(t *testing.T, ctx context.Context, kdbg *krt.DebugHandler, sna
defer dumper.Close()
dump := dumper.Dump(t, ctx)
if len(dump.Listeners) == 0 {
xdsDump := dumpCache(snapCache).MarshalJSONString()
xdsDump := iosnapshot.GetXdsSnapshotDataFromCache(snapCache).MarshalJSONString()
j, _ := kdbg.MarshalJSON()
t.Logf("timed out waiting - krt state for test: %s %s", t.Name(), string(j))
t.Logf("timed out waiting - xds state for test: %s %s", t.Name(), xdsDump)
Expand Down
12 changes: 8 additions & 4 deletions projects/gloo/pkg/servers/iosnapshot/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,15 @@ func (h *historyImpl) GetProxySnapshot(_ context.Context) SnapshotResponseData {
// GetXdsSnapshot returns the entire cache of xDS snapshots
// NOTE: This contains sensitive data, as it is the exact inputs that used by Envoy
func (h *historyImpl) GetXdsSnapshot(_ context.Context) SnapshotResponseData {
cacheKeys := h.xdsCache.GetStatusKeys()
return GetXdsSnapshotDataFromCache(h.xdsCache)
}

func GetXdsSnapshotDataFromCache(xdsCache cache.SnapshotCache) SnapshotResponseData {
cacheKeys := xdsCache.GetStatusKeys()
cacheEntries := make(map[string]interface{}, len(cacheKeys))

for _, k := range cacheKeys {
xdsSnapshot, err := h.getXdsSnapshot(k)
xdsSnapshot, err := getXdsSnapshot(xdsCache, k)
if err != nil {
cacheEntries[k] = err.Error()
} else {
Expand All @@ -197,13 +201,13 @@ func (h *historyImpl) GetXdsSnapshot(_ context.Context) SnapshotResponseData {
return completeSnapshotResponse(cacheEntries)
}

func (h *historyImpl) getXdsSnapshot(k string) (cache cache.Snapshot, err error) {
func getXdsSnapshot(xdsCache cache.SnapshotCache, k string) (cache cache.Snapshot, err error) {
defer func() {
if r := recover(); r != nil {
err = eris.New(fmt.Sprintf("panic occurred while getting xds snapshot: %v", r))
}
}()
return h.xdsCache.GetSnapshot(k)
return xdsCache.GetSnapshot(k)
}

// getRedactedApiSnapshot gets an in-memory copy of the ApiSnapshot
Expand Down

0 comments on commit c86e86d

Please sign in to comment.