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

fix: support xds adsz empty metadata #1813

Merged
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
18 changes: 16 additions & 2 deletions remoting/xds/mapping/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,23 @@ type ADSZClient struct {
func (a *ADSZResponse) GetMap() map[string]string {
result := make(map[string]string)
for _, c := range a.Clients {
if c.Metadata["LABELS"] == nil {
continue
}
labelsMap, ok := c.Metadata["LABELS"].(map[string]interface{})
if !ok {
continue
}
dubbogoMetadata := labelsMap["DUBBO_GO"]
if dubbogoMetadata == nil {
continue
}
dubbogoMetadataStr, ok := dubbogoMetadata.(string)
if !ok {
continue
}
resultMap := make(map[string]string)
// todo assert failed panic
_ = json.Unmarshal([]byte(c.Metadata["LABELS"].(map[string]interface{})["DUBBO_GO"].(string)), &resultMap)
_ = json.Unmarshal([]byte(dubbogoMetadataStr), &resultMap)
for k, v := range resultMap {
result[k] = v
}
Expand Down
30 changes: 23 additions & 7 deletions remoting/xds/mapping/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package mapping

import (
"encoding/json"
"fmt"
"testing"
)

Expand All @@ -28,19 +27,20 @@ import (
)

const (
debugAdszDataFoo = `{"totalClients":2,"clients":[{"connectionId":"dubbo-go-app-0.0.1-77b8cd56f9-4hpmb.default-4","connectedAt":"2022-03-23T13:32:49.884373692Z","address":"172.17.80.28:57150","metadata":{"LABELS":{"DUBBO_GO":"{\"providers:api.Greeter::\":\"dubbo-go-app.default.svc.cluster.local:20000\",\"providers:grpc.reflection.v1alpha.ServerReflection::\":\"dubbo-go-app.default.svc.cluster.local:20000\"}","topology.istio.io/cluster":"Kubernetes","topology.kubernetes.io/region":"cn-hangzhou","topology.kubernetes.io/zone":"cn-hangzhou-b"},"CLUSTER_ID":"Kubernetes"},"watches":{"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment":["outbound|443||istiod.istio-system.svc.cluster.local","outbound|443||metrics-server.kube-system.svc.cluster.local","outbound|80||heapster.kube-system.svc.cluster.local","outbound|443||storage-crd-validate-service.kube-system.svc.cluster.local","outbound|20000||laurence-svc.default.svc.cluster.local","outbound|11280||storage-monitor-service.kube-system.svc.cluster.local","outbound|15010||istiod.istio-system.svc.cluster.local","outbound|443||kubernetes.default.svc.cluster.local","outbound|9153||kube-dns.kube-system.svc.cluster.local","outbound|53||kube-dns.kube-system.svc.cluster.local","","outbound|15012||istiod.istio-system.svc.cluster.local","outbound|8848||nacos.default.svc.cluster.local","outbound|15014||istiod.istio-system.svc.cluster.local","outbound|20000||dubbo-go-app.default.svc.cluster.local"]}},{"connectionId":"dubbo-go-app-0.0.2-f465d67f7-k5ckq.default-2","connectedAt":"2022-03-23T13:32:15.790703481Z","address":"172.17.80.29:35406","metadata":{"LABELS":{"DUBBO_GO":"{\"providers:api.Greeter::\":\"dubbo-go-app.default.svc.cluster.local:20000\",\"providers:grpc.reflection.v1alpha.ServerReflection::\":\"dubbo-go-app.default.svc.cluster.local:20000\"}","topology.istio.io/cluster":"Kubernetes","topology.kubernetes.io/region":"cn-hangzhou","topology.kubernetes.io/zone":"cn-hangzhou-b"},"CLUSTER_ID":"Kubernetes"},"watches":{"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment":["outbound|15014||istiod.istio-system.svc.cluster.local","outbound|15010||istiod.istio-system.svc.cluster.local","outbound|53||kube-dns.kube-system.svc.cluster.local","outbound|11280||storage-monitor-service.kube-system.svc.cluster.local","outbound|8848||nacos.default.svc.cluster.local","outbound|20000||dubbo-go-app.default.svc.cluster.local","outbound|9153||kube-dns.kube-system.svc.cluster.local","","outbound|443||storage-crd-validate-service.kube-system.svc.cluster.local","outbound|443||metrics-server.kube-system.svc.cluster.local","outbound|15012||istiod.istio-system.svc.cluster.local","outbound|443||istiod.istio-system.svc.cluster.local","outbound|80||heapster.kube-system.svc.cluster.local","outbound|20000||laurence-svc.default.svc.cluster.local","outbound|443||kubernetes.default.svc.cluster.local"]}}]}`
key1 = "providers:api.Greeter::"
val1 = "dubbo-go-app.default.svc.cluster.local:20000"
key2 = "providers:grpc.reflection.v1alpha.ServerReflection::"
val2 = "dubbo-go-app.default.svc.cluster.local:20000"
debugAdszDataFoo = `{"totalClients":2,"clients":[{"connectionId":"dubbo-go-app-0.0.1-77b8cd56f9-4hpmb.default-4","connectedAt":"2022-03-23T13:32:49.884373692Z","address":"172.17.80.28:57150","metadata":{"LABELS":{"DUBBO_GO":"{\"providers:api.Greeter::\":\"dubbo-go-app.default.svc.cluster.local:20000\",\"providers:grpc.reflection.v1alpha.ServerReflection::\":\"dubbo-go-app.default.svc.cluster.local:20000\"}","topology.istio.io/cluster":"Kubernetes","topology.kubernetes.io/region":"cn-hangzhou","topology.kubernetes.io/zone":"cn-hangzhou-b"},"CLUSTER_ID":"Kubernetes"},"watches":{"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment":["outbound|443||istiod.istio-system.svc.cluster.local","outbound|443||metrics-server.kube-system.svc.cluster.local","outbound|80||heapster.kube-system.svc.cluster.local","outbound|443||storage-crd-validate-service.kube-system.svc.cluster.local","outbound|20000||laurence-svc.default.svc.cluster.local","outbound|11280||storage-monitor-service.kube-system.svc.cluster.local","outbound|15010||istiod.istio-system.svc.cluster.local","outbound|443||kubernetes.default.svc.cluster.local","outbound|9153||kube-dns.kube-system.svc.cluster.local","outbound|53||kube-dns.kube-system.svc.cluster.local","","outbound|15012||istiod.istio-system.svc.cluster.local","outbound|8848||nacos.default.svc.cluster.local","outbound|15014||istiod.istio-system.svc.cluster.local","outbound|20000||dubbo-go-app.default.svc.cluster.local"]}},{"connectionId":"dubbo-go-app-0.0.2-f465d67f7-k5ckq.default-2","connectedAt":"2022-03-23T13:32:15.790703481Z","address":"172.17.80.29:35406","metadata":{"LABELS":{"DUBBO_GO":"{\"providers:api.Greeter::\":\"dubbo-go-app.default.svc.cluster.local:20000\",\"providers:grpc.reflection.v1alpha.ServerReflection::\":\"dubbo-go-app.default.svc.cluster.local:20000\"}","topology.istio.io/cluster":"Kubernetes","topology.kubernetes.io/region":"cn-hangzhou","topology.kubernetes.io/zone":"cn-hangzhou-b"},"CLUSTER_ID":"Kubernetes"},"watches":{"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment":["outbound|15014||istiod.istio-system.svc.cluster.local","outbound|15010||istiod.istio-system.svc.cluster.local","outbound|53||kube-dns.kube-system.svc.cluster.local","outbound|11280||storage-monitor-service.kube-system.svc.cluster.local","outbound|8848||nacos.default.svc.cluster.local","outbound|20000||dubbo-go-app.default.svc.cluster.local","outbound|9153||kube-dns.kube-system.svc.cluster.local","","outbound|443||storage-crd-validate-service.kube-system.svc.cluster.local","outbound|443||metrics-server.kube-system.svc.cluster.local","outbound|15012||istiod.istio-system.svc.cluster.local","outbound|443||istiod.istio-system.svc.cluster.local","outbound|80||heapster.kube-system.svc.cluster.local","outbound|20000||laurence-svc.default.svc.cluster.local","outbound|443||kubernetes.default.svc.cluster.local"]}}]}`
debugAdszInvalidDataFoo = `"totalClients":2,"clients":[{"connectionId":"dubbo-go-app-0.0.1-77b8cd56f9-4hpmb.default-4","connectedAt":"2022-03-23T13:32:49.884373692Z","address":"172.17.80.28:57150","metadata":{"LABELS":{"DUBBO_GO":"{\"providers:api.Greeter::\":\"dubbo-go-app.default.svc.cluster.local:20000\",\"providers:grpc.reflection.v1alpha.ServerReflection::\":\"dubbo-go-app.default.svc.cluster.local:20000\"}","topology.istio.io/cluster":"Kubernetes","topology.kubernetes.io/region":"cn-hangzhou","topology.kubernetes.io/zone":"cn-hangzhou-b"},"CLUSTER_ID":"Kubernetes"},"watches":{"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment":["outbound|443||istiod.istio-system.svc.cluster.local","outbound|443||metrics-server.kube-system.svc.cluster.local","outbound|80||heapster.kube-system.svc.cluster.local","outbound|443||storage-crd-validate-service.kube-system.svc.cluster.local","outbound|20000||laurence-svc.default.svc.cluster.local","outbound|11280||storage-monitor-service.kube-system.svc.cluster.local","outbound|15010||istiod.istio-system.svc.cluster.local","outbound|443||kubernetes.default.svc.cluster.local","outbound|9153||kube-dns.kube-system.svc.cluster.local","outbound|53||kube-dns.kube-system.svc.cluster.local","","outbound|15012||istiod.istio-system.svc.cluster.local","outbound|8848||nacos.default.svc.cluster.local","outbound|15014||istiod.istio-system.svc.cluster.local","outbound|20000||dubbo-go-app.default.svc.cluster.local"]}},{"connectionId":"dubbo-go-app-0.0.2-f465d67f7-k5ckq.default-2","connectedAt":"2022-03-23T13:32:15.790703481Z","address":"172.17.80.29:35406","metadata":{"LABELS":{"DUBBO_GO":"{\"providers:api.Greeter::\":\"dubbo-go-app.default.svc.cluster.local:20000\",\"providers:grpc.reflection.v1alpha.ServerReflection::\":\"dubbo-go-app.default.svc.cluster.local:20000\"}","topology.istio.io/cluster":"Kubernetes","topology.kubernetes.io/region":"cn-hangzhou","topology.kubernetes.io/zone":"cn-hangzhou-b"},"CLUSTER_ID":"Kubernetes"},"watches":{"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment":["outbound|15014||istiod.istio-system.svc.cluster.local","outbound|15010||istiod.istio-system.svc.cluster.local","outbound|53||kube-dns.kube-system.svc.cluster.local","outbound|11280||storage-monitor-service.kube-system.svc.cluster.local","outbound|8848||nacos.default.svc.cluster.local","outbound|20000||dubbo-go-app.default.svc.cluster.local","outbound|9153||kube-dns.kube-system.svc.cluster.local","","outbound|443||storage-crd-validate-service.kube-system.svc.cluster.local","outbound|443||metrics-server.kube-system.svc.cluster.local","outbound|15012||istiod.istio-system.svc.cluster.local","outbound|443||istiod.istio-system.svc.cluster.local","outbound|80||heapster.kube-system.svc.cluster.local","outbound|20000||laurence-svc.default.svc.cluster.local","outbound|443||kubernetes.default.svc.cluster.local"]}}]}`
debugAdszEmptyDubbogoDataFoo = `{"totalClients":2,"clients":[{"connectionId":"dubbo-go-app-0.0.1-77b8cd56f9-4hpmb.default-4","connectedAt":"2022-03-23T13:32:49.884373692Z","address":"172.17.80.28:57150","metadata":{"LABELS":{"topology.istio.io/cluster":"Kubernetes","topology.kubernetes.io/region":"cn-hangzhou","topology.kubernetes.io/zone":"cn-hangzhou-b"},"CLUSTER_ID":"Kubernetes"},"watches":{"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment":["outbound|443||istiod.istio-system.svc.cluster.local","outbound|443||metrics-server.kube-system.svc.cluster.local","outbound|80||heapster.kube-system.svc.cluster.local","outbound|443||storage-crd-validate-service.kube-system.svc.cluster.local","outbound|20000||laurence-svc.default.svc.cluster.local","outbound|11280||storage-monitor-service.kube-system.svc.cluster.local","outbound|15010||istiod.istio-system.svc.cluster.local","outbound|443||kubernetes.default.svc.cluster.local","outbound|9153||kube-dns.kube-system.svc.cluster.local","outbound|53||kube-dns.kube-system.svc.cluster.local","","outbound|15012||istiod.istio-system.svc.cluster.local","outbound|8848||nacos.default.svc.cluster.local","outbound|15014||istiod.istio-system.svc.cluster.local","outbound|20000||dubbo-go-app.default.svc.cluster.local"]}},{"connectionId":"dubbo-go-app-0.0.2-f465d67f7-k5ckq.default-2","connectedAt":"2022-03-23T13:32:15.790703481Z","address":"172.17.80.29:35406","metadata":{"LABELS":{"topology.istio.io/cluster":"Kubernetes","topology.kubernetes.io/region":"cn-hangzhou","topology.kubernetes.io/zone":"cn-hangzhou-b"},"CLUSTER_ID":"Kubernetes"},"watches":{"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment":["outbound|15014||istiod.istio-system.svc.cluster.local","outbound|15010||istiod.istio-system.svc.cluster.local","outbound|53||kube-dns.kube-system.svc.cluster.local","outbound|11280||storage-monitor-service.kube-system.svc.cluster.local","outbound|8848||nacos.default.svc.cluster.local","outbound|20000||dubbo-go-app.default.svc.cluster.local","outbound|9153||kube-dns.kube-system.svc.cluster.local","","outbound|443||storage-crd-validate-service.kube-system.svc.cluster.local","outbound|443||metrics-server.kube-system.svc.cluster.local","outbound|15012||istiod.istio-system.svc.cluster.local","outbound|443||istiod.istio-system.svc.cluster.local","outbound|80||heapster.kube-system.svc.cluster.local","outbound|20000||laurence-svc.default.svc.cluster.local","outbound|443||kubernetes.default.svc.cluster.local"]}}]}`
key1 = "providers:api.Greeter::"
val1 = "dubbo-go-app.default.svc.cluster.local:20000"
key2 = "providers:grpc.reflection.v1alpha.ServerReflection::"
val2 = "dubbo-go-app.default.svc.cluster.local:20000"
)

func TestADSZResponseGetMap(t *testing.T) {
adszRsp := &ADSZResponse{}
assert.Nil(t, json.Unmarshal([]byte(debugAdszDataFoo), adszRsp))

adszMap := adszRsp.GetMap()
fmt.Println(adszMap)
assert.True(t, len(adszMap) == 2)
v1, ok1 := adszMap[key1]
assert.True(t, ok1)
Expand All @@ -50,3 +50,19 @@ func TestADSZResponseGetMap(t *testing.T) {
assert.True(t, ok2)
assert.Equal(t, val2, v2)
}

func TestInvalidADSZResponseGetMap(t *testing.T) {
adszRsp := &ADSZResponse{}
json.Unmarshal([]byte(debugAdszInvalidDataFoo), adszRsp)

adszMap := adszRsp.GetMap()
assert.True(t, len(adszMap) == 0)
}

func TestEmptyDubbogoMapADSZResponseGetMap(t *testing.T) {
adszRsp := &ADSZResponse{}
assert.Nil(t, json.Unmarshal([]byte(debugAdszEmptyDubbogoDataFoo), adszRsp))

adszMap := adszRsp.GetMap()
assert.True(t, len(adszMap) == 0)
}