Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rm printing resources in cache logs #601

Merged
merged 3 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/cache/v3/linear.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ func (cache *LinearCache) respondDelta(request *DeltaRequest, value chan DeltaRe
// Only send a response if there were changes
if len(resp.Resources) > 0 || len(resp.RemovedResources) > 0 {
if cache.log != nil {
cache.log.Debugf("[linear cache] node: %s, sending delta response with resources: %v removed resources %v wildcard: %t",
request.GetNode().GetId(), resp.Resources, resp.RemovedResources, state.IsWildcard())
cache.log.Debugf("[linear cache] node: %s, sending delta response for typeURL %s with resources: %v removed resources: %v with wildcard: %t",
request.GetNode().GetId(), request.TypeUrl, GetResourceNames(resp.Resources), resp.RemovedResources, state.IsWildcard())
}
value <- resp
return resp
Expand Down
9 changes: 9 additions & 0 deletions pkg/cache/v3/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ func GetResourceName(res types.Resource) string {
}
}

// GetResourceName returns the resource names for a list of valid xDS response types.
func GetResourceNames(resources []types.Resource) []string {
out := make([]string, len(resources))
for i, r := range resources {
out[i] = GetResourceName(r)
}
return out
}

// MarshalResource converts the Resource to MarshaledResource.
func MarshalResource(resource types.Resource) (types.MarshaledResource, error) {
return proto.MarshalOptions{Deterministic: true}.Marshal(resource)
Expand Down
26 changes: 26 additions & 0 deletions pkg/cache/v3/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,32 @@ func TestGetResourceName(t *testing.T) {
}
}

func TestGetResourceNames(t *testing.T) {
tests := []struct {
name string
input []types.Resource
want []string
}{
{
name: "empty",
input: []types.Resource{},
want: []string{},
},
{
name: "many",
input: []types.Resource{testRuntime, testListener, testVirtualHost},
want: []string{runtimeName, listenerName, virtualHostName},
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
got := cache.GetResourceNames(test.input)
assert.ElementsMatch(t, test.want, got)
})
}
}

func TestGetResourceReferences(t *testing.T) {
cases := []struct {
in types.Resource
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/v3/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ func (cache *snapshotCache) respondDelta(ctx context.Context, snapshot ResourceS
// otherwise, envoy won't complete initialization
if len(resp.Resources) > 0 || len(resp.RemovedResources) > 0 || (state.IsWildcard() && state.IsFirst()) {
if cache.log != nil {
cache.log.Debugf("node: %s, sending delta response with resources: %v removed resources %v wildcard: %t",
request.GetNode().GetId(), resp.Resources, resp.RemovedResources, state.IsWildcard())
cache.log.Debugf("node: %s, sending delta response for typeURL %s with resources: %v removed resources: %v with wildcard: %t",
request.GetNode().GetId(), request.TypeUrl, GetResourceNames(resp.Resources), resp.RemovedResources, state.IsWildcard())
}
select {
case value <- resp:
Expand Down