diff --git a/sentinel-adapter/sentinel-reactor-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/reactor/EntryConfig.java b/sentinel-adapter/sentinel-reactor-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/reactor/EntryConfig.java index be677d53..1bece3b5 100644 --- a/sentinel-adapter/sentinel-reactor-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/reactor/EntryConfig.java +++ b/sentinel-adapter/sentinel-reactor-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/reactor/EntryConfig.java @@ -18,6 +18,7 @@ package com.alibaba.csp.sentinel.adapter.reactor; import java.util.Arrays; import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.ResourceTypeConstants; import com.alibaba.csp.sentinel.util.AssertUtil; /** @@ -28,6 +29,8 @@ public class EntryConfig { private final String resourceName; private final EntryType entryType; + private final int resourceType; + private final int acquireCount; private final Object[] args; private final ContextConfig contextConfig; @@ -50,11 +53,21 @@ public class EntryConfig { public EntryConfig(String resourceName, EntryType entryType, int acquireCount, Object[] args, ContextConfig contextConfig) { + this(resourceName, ResourceTypeConstants.COMMON, entryType, acquireCount, args, contextConfig); + } + + public EntryConfig(String resourceName, int resourceType, EntryType entryType, int acquireCount, Object[] args) { + this(resourceName, resourceType, entryType, acquireCount, args, null); + } + + public EntryConfig(String resourceName, int resourceType, EntryType entryType, int acquireCount, Object[] args, + ContextConfig contextConfig) { AssertUtil.assertNotBlank(resourceName, "resourceName cannot be blank"); AssertUtil.notNull(entryType, "entryType cannot be null"); AssertUtil.isTrue(acquireCount > 0, "acquireCount should be positive"); this.resourceName = resourceName; this.entryType = entryType; + this.resourceType = resourceType; this.acquireCount = acquireCount; this.args = args; // Constructed ContextConfig should be valid here. Null is allowed here. @@ -81,11 +94,19 @@ public class EntryConfig { return contextConfig; } + /** + * @since 1.7.0 + */ + public int getResourceType() { + return resourceType; + } + @Override public String toString() { return "EntryConfig{" + "resourceName='" + resourceName + '\'' + ", entryType=" + entryType + + ", resourceType=" + resourceType + ", acquireCount=" + acquireCount + ", args=" + Arrays.toString(args) + ", contextConfig=" + contextConfig + diff --git a/sentinel-adapter/sentinel-reactor-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/reactor/SentinelReactorSubscriber.java b/sentinel-adapter/sentinel-reactor-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/reactor/SentinelReactorSubscriber.java index fa5d9353..00a44188 100644 --- a/sentinel-adapter/sentinel-reactor-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/reactor/SentinelReactorSubscriber.java +++ b/sentinel-adapter/sentinel-reactor-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/reactor/SentinelReactorSubscriber.java @@ -89,8 +89,8 @@ public class SentinelReactorSubscriber extends InheritableBaseSubscriber { ContextUtil.enter(sentinelContextConfig.getContextName(), sentinelContextConfig.getOrigin()); } try { - AsyncEntry entry = SphU.asyncEntry(entryConfig.getResourceName(), entryConfig.getEntryType(), - entryConfig.getAcquireCount(), entryConfig.getArgs()); + AsyncEntry entry = SphU.asyncEntry(entryConfig.getResourceName(), entryConfig.getResourceType(), + entryConfig.getEntryType(), entryConfig.getAcquireCount(), entryConfig.getArgs()); this.currentEntry = entry; actual.onSubscribe(this); } catch (BlockException ex) { diff --git a/sentinel-adapter/sentinel-spring-cloud-gateway-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/sc/SentinelGatewayFilter.java b/sentinel-adapter/sentinel-spring-cloud-gateway-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/sc/SentinelGatewayFilter.java index aeca8e98..3dfbaa5a 100644 --- a/sentinel-adapter/sentinel-spring-cloud-gateway-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/sc/SentinelGatewayFilter.java +++ b/sentinel-adapter/sentinel-spring-cloud-gateway-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/sc/SentinelGatewayFilter.java @@ -20,6 +20,7 @@ import java.util.Set; import java.util.stream.Collectors; import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.ResourceTypeConstants; import com.alibaba.csp.sentinel.adapter.gateway.common.SentinelGatewayConstants; import com.alibaba.csp.sentinel.adapter.gateway.common.param.GatewayParamParser; import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager; @@ -70,8 +71,8 @@ public class SentinelGatewayFilter implements GatewayFilter, GlobalFilter, Order .map(f -> f.apply(exchange)) .orElse(""); asyncResult = asyncResult.transform( - new SentinelReactorTransformer<>(new EntryConfig(routeId, EntryType.IN, - 1, params, new ContextConfig(contextName(routeId), origin))) + new SentinelReactorTransformer<>(new EntryConfig(routeId, ResourceTypeConstants.COMMON_API_GATEWAY, + EntryType.IN, 1, params, new ContextConfig(contextName(routeId), origin))) ); } @@ -80,7 +81,8 @@ public class SentinelGatewayFilter implements GatewayFilter, GlobalFilter, Order Object[] params = paramParser.parseParameterFor(apiName, exchange, r -> r.getResourceMode() == SentinelGatewayConstants.RESOURCE_MODE_CUSTOM_API_NAME); asyncResult = asyncResult.transform( - new SentinelReactorTransformer<>(new EntryConfig(apiName, EntryType.IN, 1, params)) + new SentinelReactorTransformer<>(new EntryConfig(apiName, ResourceTypeConstants.COMMON_API_GATEWAY, + EntryType.IN, 1, params)) ); }