-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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 #1573: Support customized origin parser in Apache Dubbo 2.7.x adapter #1617
Changes from 3 commits
cbf3d22
0bbf5fa
95b755f
ce8cd6e
8235587
549d35a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
*/ | ||
package com.alibaba.csp.sentinel.adapter.dubbo; | ||
|
||
import com.alibaba.csp.sentinel.adapter.dubbo.config.DubboConfig; | ||
import com.alibaba.csp.sentinel.adapter.dubbo.config.DubboAdapterGlobalConfig; | ||
import com.alibaba.csp.sentinel.util.StringUtil; | ||
import org.apache.dubbo.rpc.Invocation; | ||
import org.apache.dubbo.rpc.Invoker; | ||
|
@@ -34,11 +34,11 @@ public static String getApplication(Invocation invocation, String defaultValue) | |
return invocation.getAttachment(SENTINEL_DUBBO_APPLICATION_KEY, defaultValue); | ||
} | ||
|
||
public static String getResourceName(Invoker<?> invoker, Invocation invocation){ | ||
return getResourceName(invoker, invocation, false); | ||
public static String getMethodResourceName(Invoker<?> invoker, Invocation invocation){ | ||
return getMethodResourceName(invoker, invocation, false); | ||
} | ||
|
||
public static String getResourceName(Invoker<?> invoker, Invocation invocation, Boolean useGroupAndVersion) { | ||
public static String getMethodResourceName(Invoker<?> invoker, Invocation invocation, Boolean useGroupAndVersion) { | ||
StringBuilder buf = new StringBuilder(64); | ||
String interfaceResource = useGroupAndVersion ? invoker.getUrl().getColonSeparatedKey() : invoker.getInterface().getName(); | ||
buf.append(interfaceResource) | ||
|
@@ -57,20 +57,20 @@ public static String getResourceName(Invoker<?> invoker, Invocation invocation, | |
return buf.toString(); | ||
} | ||
|
||
public static String getResourceName(Invoker<?> invoker, Invocation invocation, String prefix) { | ||
public static String getMethodResourceName(Invoker<?> invoker, Invocation invocation, String prefix) { | ||
if (StringUtil.isNotBlank(prefix)) { | ||
return new StringBuilder(64) | ||
.append(prefix) | ||
.append(getResourceName(invoker, invocation, DubboConfig.getDubboInterfaceGroupAndVersionEnabled())) | ||
.append(getMethodResourceName(invoker, invocation, DubboAdapterGlobalConfig.getDubboInterfaceGroupAndVersionEnabled())) | ||
.toString(); | ||
} else { | ||
return getResourceName(invoker, invocation, DubboConfig.getDubboInterfaceGroupAndVersionEnabled()); | ||
return getMethodResourceName(invoker, invocation, DubboAdapterGlobalConfig.getDubboInterfaceGroupAndVersionEnabled()); | ||
} | ||
} | ||
Comment on lines
-60
to
69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, this piece is really my incomplete consideration, thank you for correcting, and it has been fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So modest, very nice work! 👍 |
||
|
||
|
||
public static String getInterfaceName(Invoker invoker) { | ||
return DubboConfig.getDubboInterfaceGroupAndVersionEnabled() ? invoker.getUrl().getColonSeparatedKey() | ||
return DubboAdapterGlobalConfig.getDubboInterfaceGroupAndVersionEnabled() ? invoker.getUrl().getColonSeparatedKey() | ||
: invoker.getInterface().getName(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.csp.sentinel.adapter.dubbo.config; | ||
|
||
import com.alibaba.csp.sentinel.adapter.dubbo.fallback.DefaultDubboFallback; | ||
import com.alibaba.csp.sentinel.adapter.dubbo.fallback.DubboFallback; | ||
import com.alibaba.csp.sentinel.adapter.dubbo.origin.DefaultDubboOriginParser; | ||
import com.alibaba.csp.sentinel.adapter.dubbo.origin.DubboOriginParser; | ||
import com.alibaba.csp.sentinel.config.SentinelConfig; | ||
import com.alibaba.csp.sentinel.util.AssertUtil; | ||
import com.alibaba.csp.sentinel.util.StringUtil; | ||
|
||
/** | ||
* <p> | ||
* Responsible for dubbo service provider, consumer attribute configuration | ||
* </p> | ||
* | ||
* @author lianglin | ||
* @since 1.7.0 | ||
*/ | ||
public final class DubboAdapterGlobalConfig { | ||
|
||
private static final String TRUE_STR = "true"; | ||
|
||
public static final String DUBBO_RES_NAME_WITH_PREFIX_KEY = "csp.sentinel.dubbo.resource.use.prefix"; | ||
public static final String DUBBO_PROVIDER_RES_NAME_PREFIX_KEY = "csp.sentinel.dubbo.resource.provider.prefix"; | ||
public static final String DUBBO_CONSUMER_RES_NAME_PREFIX_KEY = "csp.sentinel.dubbo.resource.consumer.prefix"; | ||
|
||
private static final String DEFAULT_DUBBO_PROVIDER_PREFIX = "dubbo:provider:"; | ||
private static final String DEFAULT_DUBBO_CONSUMER_PREFIX = "dubbo:consumer:"; | ||
|
||
public static final String DUBBO_INTERFACE_GROUP_VERSION_ENABLED = "csp.sentinel.dubbo.interface.group.version.enabled"; | ||
public static final String TRACE_BIZ_EXCEPTION_ENABLED = "csp.sentinel.dubbo.trace.biz.exception.enabled"; | ||
|
||
private static volatile DubboFallback consumerFallback = new DefaultDubboFallback(); | ||
private static volatile DubboFallback providerFallback = new DefaultDubboFallback(); | ||
private static volatile DubboOriginParser originParser = new DefaultDubboOriginParser(); | ||
|
||
|
||
public static boolean isUsePrefix() { | ||
return TRUE_STR.equalsIgnoreCase(SentinelConfig.getConfig(DUBBO_RES_NAME_WITH_PREFIX_KEY)); | ||
} | ||
|
||
public static String getDubboProviderResNamePrefixKey() { | ||
if (isUsePrefix()) { | ||
String config = SentinelConfig.getConfig(DUBBO_PROVIDER_RES_NAME_PREFIX_KEY); | ||
return StringUtil.isNotBlank(config) ? config : DEFAULT_DUBBO_PROVIDER_PREFIX; | ||
} | ||
return null; | ||
} | ||
|
||
public static String getDubboConsumerResNamePrefixKey() { | ||
if (isUsePrefix()) { | ||
String config = SentinelConfig.getConfig(DUBBO_CONSUMER_RES_NAME_PREFIX_KEY); | ||
return StringUtil.isNotBlank(config) ? config : DEFAULT_DUBBO_CONSUMER_PREFIX; | ||
} | ||
return null; | ||
} | ||
|
||
public static Boolean getDubboInterfaceGroupAndVersionEnabled() { | ||
return TRUE_STR.equalsIgnoreCase(SentinelConfig.getConfig(DUBBO_INTERFACE_GROUP_VERSION_ENABLED)); | ||
} | ||
|
||
public static Boolean getDubboBizExceptionTraceEnabled() { | ||
String traceBizExceptionEnabled = SentinelConfig.getConfig(TRACE_BIZ_EXCEPTION_ENABLED); | ||
if (StringUtil.isNotBlank(traceBizExceptionEnabled)) { | ||
return TRUE_STR.equalsIgnoreCase(traceBizExceptionEnabled); | ||
} | ||
return true; | ||
} | ||
|
||
|
||
|
||
public static DubboFallback getConsumerFallback() { | ||
return consumerFallback; | ||
} | ||
|
||
public static void setConsumerFallback(DubboFallback consumerFallback) { | ||
AssertUtil.notNull(consumerFallback, "consumerFallback cannot be null"); | ||
DubboAdapterGlobalConfig.consumerFallback = consumerFallback; | ||
} | ||
|
||
public static DubboFallback getProviderFallback() { | ||
return providerFallback; | ||
} | ||
|
||
public static void setProviderFallback(DubboFallback providerFallback) { | ||
AssertUtil.notNull(providerFallback, "providerFallback cannot be null"); | ||
DubboAdapterGlobalConfig.providerFallback = providerFallback; | ||
} | ||
|
||
/** | ||
* Get the origin parser of Dubbo adapter. | ||
* | ||
* @return the origin parser | ||
* @since 1.8.0 | ||
*/ | ||
public static DubboOriginParser getOriginParser() { | ||
return originParser; | ||
} | ||
|
||
/** | ||
* Set the origin parser of Dubbo adapter. | ||
* | ||
* @param originParser the origin parser | ||
* @since 1.8.0 | ||
*/ | ||
public static void setOriginParser(DubboOriginParser originParser) { | ||
AssertUtil.notNull(originParser, "originParser cannot be null"); | ||
DubboAdapterGlobalConfig.originParser = originParser; | ||
} | ||
|
||
private DubboAdapterGlobalConfig() {} | ||
|
||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
originParse
seems a typo, addingSince 1.8.0
can help user who use old verison.Maybe the document can refer to #1572
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this piece is really my incomplete consideration, thank you for correcting, and it has been fixed