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

Ftr: registry ip:port set from enviroment variable #1036

Merged
merged 8 commits into from
Feb 23, 2021
Next Next commit
fix ctx linter error
  • Loading branch information
AlexStocks committed Jan 4, 2021
commit b6022bbd868305854f51e07312d8d5c3eacdea03
2 changes: 1 addition & 1 deletion common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
42 changes: 33 additions & 9 deletions common/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)
}
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion config_center/apollo/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion filter/filter_impl/tps/tps_limiter_method_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions remoting/getty/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down