You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by la...@apache.org on 2022/04/07 06:48:19 UTC

[dubbo-go] branch 3.0 updated: fix: support xds adsz empty metadata

This is an automated email from the ASF dual-hosted git repository.

laurence pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 5ecec59d7 fix: support xds adsz empty metadata
     new 70d9ddad2 Merge pull request #1813 from LaurenceLiZhixin/supportAdszEmptyMetadata
5ecec59d7 is described below

commit 5ecec59d7639c199339219cb03f3c6f74106a6a0
Author: LaurenceLiZhixin <38...@qq.com>
AuthorDate: Thu Apr 7 13:25:19 2022 +0800

    fix: support xds adsz empty metadata
---
 remoting/xds/mapping/debug.go      | 18 ++++++++++++++++--
 remoting/xds/mapping/debug_test.go | 30 +++++++++++++++++++++++-------
 2 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/remoting/xds/mapping/debug.go b/remoting/xds/mapping/debug.go
index 5606a25b8..64f57c0c0 100644
--- a/remoting/xds/mapping/debug.go
+++ b/remoting/xds/mapping/debug.go
@@ -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
 		}
diff --git a/remoting/xds/mapping/debug_test.go b/remoting/xds/mapping/debug_test.go
index 32120159b..a5b57afc6 100644
--- a/remoting/xds/mapping/debug_test.go
+++ b/remoting/xds/mapping/debug_test.go
@@ -19,7 +19,6 @@ package mapping
 
 import (
 	"encoding/json"
-	"fmt"
 	"testing"
 )
 
@@ -28,11 +27,13 @@ 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-han [...]
-	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/reg [...]
+	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/regi [...]
+	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.is [...]
+	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) {
@@ -40,7 +41,6 @@ func TestADSZResponseGetMap(t *testing.T) {
 	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)
@@ -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)
+}