From b6022bbd868305854f51e07312d8d5c3eacdea03 Mon Sep 17 00:00:00 2001 From: AlexStocks Date: Mon, 4 Jan 2021 15:06:32 +0800 Subject: [PATCH 1/2] fix ctx linter error --- common/constant/key.go | 2 +- common/url.go | 8 ++-- common/url_test.go | 42 +++++++++++++++---- config_center/apollo/listener.go | 2 +- .../tps/tps_limiter_method_service_test.go | 2 +- remoting/getty/listener_test.go | 6 +-- 6 files changed, 44 insertions(+), 18 deletions(-) diff --git a/common/constant/key.go b/common/constant/key.go index 12e3096e5a..50aea81371 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -200,7 +200,7 @@ const ( ) const ( - TRACING_REMOTE_SPAN_CTX = "tracing.remote.span.ctx" + TRACING_REMOTE_SPAN_CTX = DubboCtxKey("tracing.remote.span.ctx") ) // Use for router module diff --git a/common/url.go b/common/url.go index 87cacfd7fb..ac49465346 100644 --- a/common/url.go +++ b/common/url.go @@ -90,9 +90,7 @@ type baseUrl struct { Location string // ip+port Ip string Port string - //url.Values is not safe map, add to avoid concurrent map read and map write error - paramsLock sync.RWMutex - params url.Values + PrimitiveURL string } @@ -116,6 +114,10 @@ type URL struct { noCopy noCopy baseUrl + //url.Values is not safe map, add to avoid concurrent map read and map write error + paramsLock sync.RWMutex + params url.Values + Path string // like /com.ikurento.dubbo.UserProvider Username string Password string diff --git a/common/url_test.go b/common/url_test.go index 4008f6a3d3..c645f1a046 100644 --- a/common/url_test.go +++ b/common/url_test.go @@ -161,7 +161,10 @@ func TestURLEqual(t *testing.T) { func TestURLGetParam(t *testing.T) { params := url.Values{} params.Set("key", "value") - u := URL{baseUrl: baseUrl{params: params}} + + u := URL{} + u.SetParams(params) + v := u.GetParam("key", "default") assert.Equal(t, "value", v) @@ -172,8 +175,11 @@ func TestURLGetParam(t *testing.T) { func TestURLGetParamInt(t *testing.T) { params := url.Values{} - params.Set("key", "") - u := URL{baseUrl: baseUrl{params: params}} + params.Set("key", "value") + + u := URL{} + u.SetParams(params) + v := u.GetParamInt("key", 1) assert.Equal(t, int64(1), v) @@ -185,7 +191,10 @@ func TestURLGetParamInt(t *testing.T) { func TestURLGetParamIntValue(t *testing.T) { params := url.Values{} params.Set("key", "0") - u := URL{baseUrl: baseUrl{params: params}} + + u := URL{} + u.SetParams(params) + v := u.GetParamInt("key", 1) assert.Equal(t, int64(0), v) @@ -197,7 +206,10 @@ func TestURLGetParamIntValue(t *testing.T) { func TestURLGetParamBool(t *testing.T) { params := url.Values{} params.Set("force", "true") - u := URL{baseUrl: baseUrl{params: params}} + + u := URL{} + u.SetParams(params) + v := u.GetParamBool("force", false) assert.Equal(t, true, v) @@ -210,7 +222,10 @@ func TestURLGetParamAndDecoded(t *testing.T) { rule := "host = 2.2.2.2,1.1.1.1,3.3.3.3 & host !=1.1.1.1 => host = 1.2.3.4" params := url.Values{} params.Set("rule", base64.URLEncoding.EncodeToString([]byte(rule))) - u := URL{baseUrl: baseUrl{params: params}} + + u := URL{} + u.SetParams(params) + v, _ := u.GetParamAndDecoded("rule") assert.Equal(t, rule, v) } @@ -247,7 +262,10 @@ func TestURLToMap(t *testing.T) { func TestURLGetMethodParamInt(t *testing.T) { params := url.Values{} params.Set("methods.GetValue.timeout", "3") - u := URL{baseUrl: baseUrl{params: params}} + + u := URL{} + u.SetParams(params) + v := u.GetMethodParamInt("GetValue", "timeout", 1) assert.Equal(t, int64(3), v) @@ -259,7 +277,10 @@ func TestURLGetMethodParamInt(t *testing.T) { func TestURLGetMethodParam(t *testing.T) { params := url.Values{} params.Set("methods.GetValue.timeout", "3s") - u := URL{baseUrl: baseUrl{params: params}} + + u := URL{} + u.SetParams(params) + v := u.GetMethodParam("GetValue", "timeout", "1s") assert.Equal(t, "3s", v) @@ -271,7 +292,10 @@ func TestURLGetMethodParam(t *testing.T) { func TestURLGetMethodParamBool(t *testing.T) { params := url.Values{} params.Set("methods.GetValue.async", "true") - u := URL{baseUrl: baseUrl{params: params}} + + u := URL{} + u.SetParams(params) + v := u.GetMethodParamBool("GetValue", "async", false) assert.Equal(t, true, v) diff --git a/config_center/apollo/listener.go b/config_center/apollo/listener.go index ace5ed0268..44d325582f 100644 --- a/config_center/apollo/listener.go +++ b/config_center/apollo/listener.go @@ -36,7 +36,7 @@ type apolloListener struct { // nolint func newApolloListener() *apolloListener { return &apolloListener{ - listeners: make(map[config_center.ConfigurationListener]struct{}, 0), + listeners: make(map[config_center.ConfigurationListener]struct{}), } } diff --git a/filter/filter_impl/tps/tps_limiter_method_service_test.go b/filter/filter_impl/tps/tps_limiter_method_service_test.go index a70287eabd..4ff0a232e4 100644 --- a/filter/filter_impl/tps/tps_limiter_method_service_test.go +++ b/filter/filter_impl/tps/tps_limiter_method_service_test.go @@ -113,7 +113,7 @@ func TestMethodServiceTpsLimiterImplIsAllowableMethodLevelOverride(t *testing.T) func TestMethodServiceTpsLimiterImplIsAllowableBothMethodAndService(t *testing.T) { methodName := "hello3" methodConfigPrefix := "methods." + methodName + "." - invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]interface{}, 0)) + invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]interface{})) ctrl := gomock.NewController(t) defer ctrl.Finish() diff --git a/remoting/getty/listener_test.go b/remoting/getty/listener_test.go index 956ecf9849..2700ed8cd8 100644 --- a/remoting/getty/listener_test.go +++ b/remoting/getty/listener_test.go @@ -23,14 +23,14 @@ import ( ) import ( + "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go/mocktracer" "github.com/stretchr/testify/assert" ) import ( "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/protocol/invocation" - "github.com/opentracing/opentracing-go" - "github.com/opentracing/opentracing-go/mocktracer" ) // test rebuild the ctx @@ -63,7 +63,7 @@ func TestRebuildCtx(t *testing.T) { // Once we decided to transfer more context's key-value, we should change this. // now we only support rebuild the tracing context func rebuildCtx(inv *invocation.RPCInvocation) context.Context { - ctx := context.WithValue(context.Background(), "attachment", inv.Attachments()) + ctx := context.WithValue(context.Background(), constant.DubboCtxKey("attachment"), inv.Attachments()) // actually, if user do not use any opentracing framework, the err will not be nil. spanCtx, err := opentracing.GlobalTracer().Extract(opentracing.TextMap, From 93d25b50f6834cb3131f473f06e0b44bc0cce4c2 Mon Sep 17 00:00:00 2001 From: LaurenceLiZhixin <382673304@qq.com> Date: Tue, 2 Feb 2021 15:42:27 +0800 Subject: [PATCH 2/2] ftr: add read registry ip and port from env --- registry/base_registry.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/registry/base_registry.go b/registry/base_registry.go index e97cc1a4ed..df8c8a3250 100644 --- a/registry/base_registry.go +++ b/registry/base_registry.go @@ -136,6 +136,13 @@ func (r *BaseRegistry) Register(conf *common.URL) error { ok bool err error ) + // if developer define registry port and ip, use it first. + if ipToRegistry := os.Getenv("DUBBO_IP_TO_REGISTRY"); ipToRegistry != "" { + conf.Ip = ipToRegistry + } + if portToRegistry := os.Getenv("DUBBO_PORT_TO_REGISTRY"); portToRegistry != "" { + conf.Port = portToRegistry + } role, _ := strconv.Atoi(r.URL.GetParam(constant.ROLE_KEY, "")) // Check if the service has been registered r.cltLock.Lock()