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: [refer dubbo 2.7.6] attachment type from map[string]stiring to map[string]interface{} #713

Merged
merged 18 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
20 changes: 11 additions & 9 deletions cluster/router/tag/tag_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ func (c *tagRouter) Priority() int64 {
}

func filterUsingStaticTag(invokers []protocol.Invoker, url *common.URL, invocation protocol.Invocation) []protocol.Invoker {
if tag, ok := invocation.Attachments()[constant.Tagkey]; ok {
result := make([]protocol.Invoker, 0, 8)
for _, v := range invokers {
if v.GetUrl().GetParam(constant.Tagkey, "") == tag {
result = append(result, v)
if tagObject := invocation.Attachment(constant.Tagkey); tagObject != nil {
if tag, ok := tagObject.(string); ok {
result := make([]protocol.Invoker, 0, 8)
for _, v := range invokers {
if v.GetUrl().GetParam(constant.Tagkey, "") == tag {
result = append(result, v)
}
}
if len(result) == 0 && !isForceUseTag(url, invocation) {
return invokers
}
return result
}
if len(result) == 0 && !isForceUseTag(url, invocation) {
return invokers
}
return result
}
return invokers
}
Expand Down
28 changes: 21 additions & 7 deletions filter/filter_impl/access_log_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,27 @@ func (ef *AccessLogFilter) logIntoChannel(accessLogData AccessLogData) {
func (ef *AccessLogFilter) buildAccessLogData(_ protocol.Invoker, invocation protocol.Invocation) map[string]string {
dataMap := make(map[string]string, 16)
attachments := invocation.Attachments()
dataMap[constant.INTERFACE_KEY] = attachments[constant.INTERFACE_KEY]
dataMap[constant.METHOD_KEY] = invocation.MethodName()
dataMap[constant.VERSION_KEY] = attachments[constant.VERSION_KEY]
dataMap[constant.GROUP_KEY] = attachments[constant.GROUP_KEY]
dataMap[constant.TIMESTAMP_KEY] = time.Now().Format(MessageDateLayout)
dataMap[constant.LOCAL_ADDR], _ = attachments[constant.LOCAL_ADDR]
dataMap[constant.REMOTE_ADDR], _ = attachments[constant.REMOTE_ADDR]
if attachments[constant.INTERFACE_KEY] != nil {
AlexStocks marked this conversation as resolved.
Show resolved Hide resolved
dataMap[constant.INTERFACE_KEY] = attachments[constant.INTERFACE_KEY].(string)
}
if attachments[constant.METHOD_KEY] != nil {
dataMap[constant.METHOD_KEY] = attachments[constant.METHOD_KEY].(string)
}
if attachments[constant.VERSION_KEY] != nil {
dataMap[constant.VERSION_KEY] = attachments[constant.VERSION_KEY].(string)
}
if attachments[constant.GROUP_KEY] != nil {
dataMap[constant.GROUP_KEY] = attachments[constant.GROUP_KEY].(string)
}
if attachments[constant.TIMESTAMP_KEY] != nil {
dataMap[constant.TIMESTAMP_KEY] = attachments[constant.TIMESTAMP_KEY].(string)
}
if attachments[constant.LOCAL_ADDR] != nil {
dataMap[constant.LOCAL_ADDR] = attachments[constant.LOCAL_ADDR].(string)
}
if attachments[constant.REMOTE_ADDR] != nil {
dataMap[constant.REMOTE_ADDR] = attachments[constant.REMOTE_ADDR].(string)
}

if len(invocation.Arguments()) > 0 {
builder := strings.Builder{}
Expand Down
4 changes: 2 additions & 2 deletions filter/filter_impl/access_log_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestAccessLogFilter_Invoke_Not_Config(t *testing.T) {
"service.filter=echo%2Ctoken%2Caccesslog&timestamp=1569153406&token=934804bf-b007-4174-94eb-96e3e1d60cc7&version=&warmup=100")
invoker := protocol.NewBaseInvoker(url)

attach := make(map[string]string, 10)
attach := make(map[string]interface{}, 10)
inv := invocation.NewRPCInvocation("MethodName", []interface{}{"OK", "Hello"}, attach)

accessLogFilter := GetAccessLogFilter()
Expand All @@ -64,7 +64,7 @@ func TestAccessLogFilterInvokeDefaultConfig(t *testing.T) {
"service.filter=echo%2Ctoken%2Caccesslog&timestamp=1569153406&token=934804bf-b007-4174-94eb-96e3e1d60cc7&version=&warmup=100")
invoker := protocol.NewBaseInvoker(url)

attach := make(map[string]string, 10)
attach := make(map[string]interface{}, 10)
attach[constant.VERSION_KEY] = "1.0"
attach[constant.GROUP_KEY] = "MyGroup"
inv := invocation.NewRPCInvocation("MethodName", []interface{}{"OK", "Hello"}, attach)
Expand Down
4 changes: 2 additions & 2 deletions filter/filter_impl/active_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

func TestActiveFilterInvoke(t *testing.T) {
invoc := invocation.NewRPCInvocation("test", []interface{}{"OK"}, make(map[string]string, 0))
invoc := invocation.NewRPCInvocation("test", []interface{}{"OK"}, make(map[string]interface{}, 0))
url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider")
filter := ActiveFilter{}
ctrl := gomock.NewController(t)
Expand All @@ -53,7 +53,7 @@ func TestActiveFilterInvoke(t *testing.T) {
func TestActiveFilterOnResponse(t *testing.T) {
c := protocol.CurrentTimeMillis()
elapsed := 100
invoc := invocation.NewRPCInvocation("test", []interface{}{"OK"}, map[string]string{
invoc := invocation.NewRPCInvocation("test", []interface{}{"OK"}, map[string]interface{}{
dubboInvokeStartTime: strconv.FormatInt(c-int64(elapsed), 10),
})
url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider")
Expand Down
6 changes: 3 additions & 3 deletions filter/filter_impl/auth/default_authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestDefaultAuthenticator_Authenticate(t *testing.T) {

var authenticator = &DefaultAuthenticator{}

invcation := invocation.NewRPCInvocation("test", parmas, map[string]string{
invcation := invocation.NewRPCInvocation("test", parmas, map[string]interface{}{
constant.REQUEST_SIGNATURE_KEY: signature,
constant.CONSUMER: "test",
constant.REQUEST_TIMESTAMP_KEY: requestTime,
Expand All @@ -61,7 +61,7 @@ func TestDefaultAuthenticator_Authenticate(t *testing.T) {
err := authenticator.Authenticate(invcation, &testurl)
assert.Nil(t, err)
// modify the params
invcation = invocation.NewRPCInvocation("test", parmas[:1], map[string]string{
invcation = invocation.NewRPCInvocation("test", parmas[:1], map[string]interface{}{
constant.REQUEST_SIGNATURE_KEY: signature,
constant.CONSUMER: "test",
constant.REQUEST_TIMESTAMP_KEY: requestTime,
Expand Down Expand Up @@ -119,7 +119,7 @@ func Test_getAccessKeyPairFailed(t *testing.T) {
func Test_getSignatureWithinParams(t *testing.T) {
testurl, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=gg&version=2.6.0")
testurl.SetParam(constant.PARAMTER_SIGNATURE_ENABLE_KEY, "true")
inv := invocation.NewRPCInvocation("test", []interface{}{"OK"}, map[string]string{
inv := invocation.NewRPCInvocation("test", []interface{}{"OK"}, map[string]interface{}{
"": "",
})
secret := "dubbo"
Expand Down
2 changes: 1 addition & 1 deletion filter/filter_impl/auth/provider_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestProviderAuthFilter_Invoke(t *testing.T) {
requestTime := strconv.Itoa(int(time.Now().Unix() * 1000))
signature, _ := getSignature(&url, inv, secret, requestTime)

inv = invocation.NewRPCInvocation("test", []interface{}{"OK"}, map[string]string{
inv = invocation.NewRPCInvocation("test", []interface{}{"OK"}, map[string]interface{}{
constant.REQUEST_SIGNATURE_KEY: signature,
constant.CONSUMER: "test",
constant.REQUEST_TIMESTAMP_KEY: requestTime,
Expand Down
6 changes: 3 additions & 3 deletions filter/filter_impl/execute_limit_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (

func TestExecuteLimitFilterInvokeIgnored(t *testing.T) {
methodName := "hello"
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]string, 0))
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]interface{}, 0))

invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
Expand All @@ -51,7 +51,7 @@ func TestExecuteLimitFilterInvokeIgnored(t *testing.T) {

func TestExecuteLimitFilterInvokeConfigureError(t *testing.T) {
methodName := "hello1"
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]string, 0))
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]interface{}, 0))

invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
Expand All @@ -68,7 +68,7 @@ func TestExecuteLimitFilterInvokeConfigureError(t *testing.T) {

func TestExecuteLimitFilterInvoke(t *testing.T) {
methodName := "hello1"
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]string, 0))
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]interface{}, 0))

invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
Expand Down
2 changes: 1 addition & 1 deletion filter/filter_impl/graceful_shutdown_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
)

func TestGenericFilterInvoke(t *testing.T) {
invoc := invocation.NewRPCInvocation("GetUser", []interface{}{"OK"}, make(map[string]string, 0))
invoc := invocation.NewRPCInvocation("GetUser", []interface{}{"OK"}, make(map[string]interface{}, 0))

invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}))
Expand Down
2 changes: 1 addition & 1 deletion filter/filter_impl/metrics_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestMetricsFilterInvoke(t *testing.T) {
"service.filter=echo%2Ctoken%2Caccesslog&timestamp=1569153406&token=934804bf-b007-4174-94eb-96e3e1d60cc7&version=&warmup=100")
invoker := protocol.NewBaseInvoker(url)

attach := make(map[string]string, 10)
attach := make(map[string]interface{}, 10)
inv := invocation.NewRPCInvocation("MethodName", []interface{}{"OK", "Hello"}, attach)

ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion filter/filter_impl/token_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (tf *TokenFilter) Invoke(ctx context.Context, invoker protocol.Invoker, inv
if len(invokerTkn) > 0 {
attachs := invocation.Attachments()
remoteTkn, exist := attachs[constant.TOKEN_KEY]
if exist && strings.EqualFold(invokerTkn, remoteTkn) {
if exist && remoteTkn != nil && strings.EqualFold(invokerTkn, remoteTkn.(string)) {
return invoker.Invoke(ctx, invocation)
}
return &protocol.RPCResult{Err: perrors.Errorf("Invalid token! Forbid invoke remote service %v method %s ",
Expand Down
8 changes: 4 additions & 4 deletions filter/filter_impl/token_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestTokenFilterInvoke(t *testing.T) {
url := common.NewURLWithOptions(
common.WithParams(url.Values{}),
common.WithParamsValue(constant.TOKEN_KEY, "ori_key"))
attch := make(map[string]string, 0)
attch := make(map[string]interface{}, 0)
attch[constant.TOKEN_KEY] = "ori_key"
result := filter.Invoke(context.Background(),
protocol.NewBaseInvoker(*url),
Expand All @@ -54,7 +54,7 @@ func TestTokenFilterInvokeEmptyToken(t *testing.T) {
filter := GetTokenFilter()

testUrl := common.URL{}
attch := make(map[string]string, 0)
attch := make(map[string]interface{}, 0)
attch[constant.TOKEN_KEY] = "ori_key"
result := filter.Invoke(context.Background(), protocol.NewBaseInvoker(testUrl), invocation.NewRPCInvocation("MethodName", []interface{}{"OK"}, attch))
assert.Nil(t, result.Error())
Expand All @@ -67,7 +67,7 @@ func TestTokenFilterInvokeEmptyAttach(t *testing.T) {
testUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
common.WithParamsValue(constant.TOKEN_KEY, "ori_key"))
attch := make(map[string]string, 0)
attch := make(map[string]interface{}, 0)
result := filter.Invoke(context.Background(), protocol.NewBaseInvoker(*testUrl), invocation.NewRPCInvocation("MethodName", []interface{}{"OK"}, attch))
assert.NotNil(t, result.Error())
}
Expand All @@ -78,7 +78,7 @@ func TestTokenFilterInvokeNotEqual(t *testing.T) {
testUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
common.WithParamsValue(constant.TOKEN_KEY, "ori_key"))
attch := make(map[string]string, 0)
attch := make(map[string]interface{}, 0)
attch[constant.TOKEN_KEY] = "err_key"
result := filter.Invoke(context.Background(),
protocol.NewBaseInvoker(*testUrl), invocation.NewRPCInvocation("MethodName", []interface{}{"OK"}, attch))
Expand Down
8 changes: 4 additions & 4 deletions filter/filter_impl/tps/tps_limiter_method_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (

func TestMethodServiceTpsLimiterImplIsAllowableOnlyServiceLevel(t *testing.T) {
methodName := "hello"
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]string, 0))
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]interface{}, 0))

ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand All @@ -63,7 +63,7 @@ func TestMethodServiceTpsLimiterImplIsAllowableOnlyServiceLevel(t *testing.T) {

func TestMethodServiceTpsLimiterImplIsAllowableNoConfig(t *testing.T) {
methodName := "hello1"
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]string, 0))
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]interface{}, 0))
// ctrl := gomock.NewController(t)
// defer ctrl.Finish()

Expand All @@ -80,7 +80,7 @@ func TestMethodServiceTpsLimiterImplIsAllowableNoConfig(t *testing.T) {
func TestMethodServiceTpsLimiterImplIsAllowableMethodLevelOverride(t *testing.T) {
methodName := "hello2"
methodConfigPrefix := "methods." + methodName + "."
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]string, 0))
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]interface{}, 0))
ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand Down 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]string, 0))
invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]interface{}, 0))
ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand Down
6 changes: 3 additions & 3 deletions filter/filter_impl/tps_limit_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestTpsLimitFilterInvokeWithNoTpsLimiter(t *testing.T) {
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
common.WithParamsValue(constant.TPS_LIMITER_KEY, ""))
attch := make(map[string]string, 0)
attch := make(map[string]interface{}, 0)

result := tpsFilter.Invoke(context.Background(),
protocol.NewBaseInvoker(*invokeUrl),
Expand All @@ -68,7 +68,7 @@ func TestGenericFilterInvokeWithDefaultTpsLimiter(t *testing.T) {
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
common.WithParamsValue(constant.TPS_LIMITER_KEY, constant.DEFAULT_KEY))
attch := make(map[string]string, 0)
attch := make(map[string]interface{}, 0)

result := tpsFilter.Invoke(context.Background(),
protocol.NewBaseInvoker(*invokeUrl),
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestGenericFilterInvokeWithDefaultTpsLimiterNotAllow(t *testing.T) {
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
common.WithParamsValue(constant.TPS_LIMITER_KEY, constant.DEFAULT_KEY))
attch := make(map[string]string, 0)
attch := make(map[string]interface{}, 0)

result := tpsFilter.Invoke(context.Background(),
protocol.NewBaseInvoker(*invokeUrl), invocation.NewRPCInvocation("MethodName", []interface{}{"OK"}, attch))
Expand Down
2 changes: 1 addition & 1 deletion filter/filter_impl/tracing_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestTracingFilterInvoke(t *testing.T) {
"service.filter=echo%2Ctoken%2Caccesslog&timestamp=1569153406&token=934804bf-b007-4174-94eb-96e3e1d60cc7&version=&warmup=100")
invoker := protocol.NewBaseInvoker(url)

attach := make(map[string]string, 10)
attach := make(map[string]interface{}, 10)
inv := invocation.NewRPCInvocation("MethodName", []interface{}{"OK", "Hello"}, attach)
ctx := context.Background()
tf := newTracingFilter()
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module github.com/apache/dubbo-go
require (
github.com/Workiva/go-datastructures v1.0.50
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5 // indirect
github.com/apache/dubbo-go-hessian2 v1.6.1
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/etcd v3.3.13+incompatible
github.com/coreos/go-semver v0.3.0 // indirect
Expand Down Expand Up @@ -58,4 +56,6 @@ require (
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a // indirect
)

replace github.com/apache/dubbo-go-hessian2 => /Users/cvictory/go/src/github.com/apache/dubbo-go-hessian2

go 1.13
Loading