Skip to content

Commit

Permalink
Update resource classification in SentinelWebFluxFilter and improve r…
Browse files Browse the repository at this point in the history
…eactor EntryConfig

Signed-off-by: Eric Zhao <[email protected]>
  • Loading branch information
sczyh30 committed Nov 11, 2019
1 parent 9c268bd commit 2750414
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public EntryConfig(String resourceName, EntryType entryType, ContextConfig conte
this(resourceName, entryType, 1, new Object[0], contextConfig);
}

public EntryConfig(String resourceName, int resourceType, EntryType entryType, ContextConfig contextConfig) {
this(resourceName, resourceType, entryType, 1, new Object[0], contextConfig);
}

public EntryConfig(String resourceName, EntryType entryType, int acquireCount, Object[] args) {
this(resourceName, entryType, acquireCount, args, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Optional;

import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.ResourceTypeConstants;
import com.alibaba.csp.sentinel.adapter.reactor.ContextConfig;
import com.alibaba.csp.sentinel.adapter.reactor.EntryConfig;
import com.alibaba.csp.sentinel.adapter.reactor.SentinelReactorTransformer;
Expand Down Expand Up @@ -45,15 +46,17 @@ public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
if (StringUtil.isEmpty(finalPath)) {
return chain.filter(exchange);
}
return chain.filter(exchange).transform(buildSentinelTransformer(exchange, finalPath));
return chain.filter(exchange)
.transform(buildSentinelTransformer(exchange, finalPath));
}

private SentinelReactorTransformer<Void> buildSentinelTransformer(ServerWebExchange exchange, String finalPath) {
String origin = Optional.ofNullable(WebFluxCallbackManager.getRequestOriginParser())
.map(f -> f.apply(exchange))
.orElse(EMPTY_ORIGIN);

return new SentinelReactorTransformer<>(new EntryConfig(finalPath, EntryType.IN, new ContextConfig(finalPath, origin)));
return new SentinelReactorTransformer<>(new EntryConfig(finalPath, ResourceTypeConstants.COMMON_WEB,
EntryType.IN, new ContextConfig(finalPath, origin)));
}

private static final String EMPTY_ORIGIN = "";
Expand Down

0 comments on commit 2750414

Please sign in to comment.