Skip to content

Commit

Permalink
Add switch for open all groups
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhiguo committed Oct 21, 2024
1 parent 9146632 commit d6f3840
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ public class ServiceConfig {
@Setter
private Map<String, String> invokeGroups;

/**
* If the target service is not configured with a group, should all groups be allowed to call it
*/
@Getter
@Setter
private boolean openAllGroups = true;

private final PathMatcherTrie<PrefixPath> systemPathTrie = new PathMatcherTrie<>(() -> {
List<PrefixPath> result = new ArrayList<>();
if (systemPaths != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.jd.live.agent.core.Constants;
import com.jd.live.agent.core.extension.annotation.Extension;
import com.jd.live.agent.core.inject.annotation.Injectable;
import com.jd.live.agent.governance.config.ServiceConfig;
import com.jd.live.agent.governance.invoke.OutboundInvocation;
import com.jd.live.agent.governance.invoke.RouteTarget;
import com.jd.live.agent.governance.invoke.filter.RouteFilter;
Expand All @@ -38,11 +39,12 @@ public class GroupFilter implements RouteFilter {
@Override
public <T extends OutboundRequest> void filter(OutboundInvocation<T> invocation, RouteFilterChain chain) {
ServiceMetadata serviceMetadata = invocation.getServiceMetadata();
ServiceConfig serviceConfig = serviceMetadata.getServiceConfig();
String targetGroup = serviceMetadata.getServiceGroup();
if (targetGroup != null && !targetGroup.isEmpty()) {
RouteTarget target = invocation.getRouteTarget();
target.filter(endpoint -> endpoint.getLabel(Constants.LABEL_SERVICE_GROUP).equals(targetGroup));
} else {
} else if (serviceConfig != null && !serviceConfig.isOpenAllGroups()) {
RouteTarget target = invocation.getRouteTarget();
target.filter(endpoint -> endpoint.getLabel(Constants.LABEL_SERVICE_GROUP).equals(PolicyId.DEFAULT_GROUP)
|| endpoint.getLabel(Constants.LABEL_SERVICE_GROUP) == null
Expand Down

0 comments on commit d6f3840

Please sign in to comment.