Skip to content

Commit 96959f5

Browse files
committed
fix: suggested changes
1 parent 5171fdb commit 96959f5

3 files changed

Lines changed: 16 additions & 34 deletions

File tree

xds/src/main/java/io/grpc/xds/CompositeFilter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.google.protobuf.InvalidProtocolBufferException;
2424
import com.google.protobuf.Message;
2525
import io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig;
26-
import io.grpc.xds.ThreadSafeRandom;
2726
import io.envoyproxy.envoy.extensions.common.matching.v3.ExtensionWithMatcher;
2827
import io.envoyproxy.envoy.extensions.common.matching.v3.ExtensionWithMatcherPerRoute;
2928
import io.envoyproxy.envoy.extensions.filters.http.composite.v3.Composite;
@@ -42,6 +41,7 @@
4241
import io.grpc.ServerInterceptor;
4342
import io.grpc.Status;
4443
import io.grpc.internal.GrpcUtil;
44+
import io.grpc.xds.ThreadSafeRandom;
4545
import io.grpc.xds.internal.UnifiedMatcher;
4646
import java.net.InetSocketAddress;
4747
import java.net.SocketAddress;
@@ -199,7 +199,9 @@ private boolean isSupported() {
199199
}
200200

201201
private static FilterDelegate createFilterDelegate(
202-
com.github.xds.core.v3.TypedExtensionConfig config, FilterConfigParseContext context, int depth) {
202+
com.github.xds.core.v3.TypedExtensionConfig config,
203+
FilterConfigParseContext context,
204+
int depth) {
203205
try {
204206
Any actionAny = config.getTypedConfig();
205207
if (actionAny.is(ExecuteFilterAction.class)) {
@@ -286,6 +288,7 @@ static final class FilterDelegate {
286288

287289

288290
FilterDelegate(List<DelegateEntry> delegates, @Nullable FractionalPercent samplePercent) {
291+
289292
this.delegates = Collections.unmodifiableList(delegates);
290293
this.threshold = calculateThreshold(samplePercent);
291294
}

xds/src/main/java/io/grpc/xds/internal/MatcherParser.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public static Matchers.StringMatcher parseStringMatcher(
100100
}
101101
}
102102

103+
103104
/** Translate StringMatcher xDS proto to internal StringMatcher. */
104105
public static Matchers.StringMatcher parseStringMatcher(
105106
com.github.xds.type.matcher.v3.StringMatcher proto) {
@@ -144,28 +145,4 @@ public static Matchers.FractionMatcher parseFractionMatcher(
144145
}
145146
return Matchers.FractionMatcher.create(proto.getNumerator(), denominator);
146147
}
147-
148-
/** Translate StringMatcher xDS proto to internal StringMatcher. */
149-
public static Matchers.StringMatcher parseStringMatcher(
150-
com.github.xds.type.matcher.v3.StringMatcher proto) {
151-
switch (proto.getMatchPatternCase()) {
152-
case EXACT:
153-
return Matchers.StringMatcher.forExact(proto.getExact(), proto.getIgnoreCase());
154-
case PREFIX:
155-
return Matchers.StringMatcher.forPrefix(proto.getPrefix(), proto.getIgnoreCase());
156-
case SUFFIX:
157-
return Matchers.StringMatcher.forSuffix(proto.getSuffix(), proto.getIgnoreCase());
158-
case SAFE_REGEX:
159-
return Matchers.StringMatcher.forSafeRegEx(
160-
Pattern.compile(proto.getSafeRegex().getRegex()));
161-
case CONTAINS:
162-
return Matchers.StringMatcher.forContains(proto.getContains());
163-
case CUSTOM:
164-
throw new IllegalArgumentException("custom string matcher is not supported");
165-
case MATCHPATTERN_NOT_SET:
166-
default:
167-
throw new IllegalArgumentException(
168-
"Unknown StringMatcher match pattern: " + proto.getMatchPatternCase());
169-
}
170-
}
171148
}

xds/src/test/java/io/grpc/xds/CompositeFilterTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
import com.github.xds.type.matcher.v3.StringMatcher;
2828
import com.google.protobuf.Any;
2929
import io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig;
30-
import io.grpc.xds.Filter.FilterConfigParseContext;
31-
import io.grpc.xds.client.Bootstrapper.BootstrapInfo;
32-
import io.grpc.xds.client.Bootstrapper.ServerInfo;
33-
import io.envoyproxy.envoy.config.core.v3.Node;
34-
import java.util.Collections;
3530
import io.envoyproxy.envoy.extensions.common.matching.v3.ExtensionWithMatcher;
3631
import io.envoyproxy.envoy.extensions.common.matching.v3.ExtensionWithMatcherPerRoute;
3732
import io.envoyproxy.envoy.extensions.filters.http.composite.v3.Composite;
@@ -49,6 +44,8 @@
4944
import io.grpc.ServerInterceptor;
5045
import io.grpc.Status;
5146
import io.grpc.xds.Filter.FilterConfig;
47+
import io.grpc.xds.client.Bootstrapper.BootstrapInfo;
48+
import io.grpc.xds.client.Bootstrapper.ServerInfo;
5249
import io.grpc.xds.internal.UnifiedMatcher;
5350
import java.net.InetSocketAddress;
5451
import java.net.SocketAddress;
@@ -93,7 +90,10 @@ public void setUp() {
9390

9491
when(fakeProvider.typeUrls()).thenReturn(new String[]{FAKE_TYPE_URL});
9592
ConfigOrError<? extends FilterConfig> configRes = ConfigOrError.fromConfig(fakeConfig);
96-
when(fakeProvider.parseFilterConfig(any(Any.class), any(Filter.FilterConfigParseContext.class), org.mockito.ArgumentMatchers.anyInt()))
93+
when(fakeProvider.parseFilterConfig(
94+
any(Any.class),
95+
any(Filter.FilterConfigParseContext.class),
96+
org.mockito.ArgumentMatchers.anyInt()))
9797
.thenReturn((ConfigOrError) configRes);
9898
when(fakeProvider.newInstance(any(String.class))).thenReturn(fakeFilter);
9999
when(fakeFilter.buildClientInterceptor(any(), any(), any())).thenReturn(fakeClientInterceptor);
@@ -1028,7 +1028,8 @@ public void parseFilterConfigExceedsRecursionLimit() {
10281028
final Any configAny = Any.pack(configProto);
10291029

10301030
// Mock fakeProvider to call provider.parseFilterConfig recursively
1031-
when(fakeProvider.parseFilterConfig(any(), any(Filter.FilterConfigParseContext.class), org.mockito.ArgumentMatchers.anyInt()))
1031+
when(fakeProvider.parseFilterConfig(
1032+
any(), any(Filter.FilterConfigParseContext.class), org.mockito.ArgumentMatchers.anyInt()))
10321033
.thenAnswer(new org.mockito.stubbing.Answer<ConfigOrError>() {
10331034
@Override
10341035
public ConfigOrError answer(
@@ -1233,7 +1234,8 @@ public void parseFilterConfigInvalidMessageType() {
12331234
@Test
12341235
public void parseFilterConfigOverrideInvalidMessageType() {
12351236
ConfigOrError<CompositeFilter.CompositeFilterConfig> result = provider
1236-
.parseFilterConfigOverride(com.google.protobuf.Empty.getDefaultInstance(), getFilterContext(), 0);
1237+
.parseFilterConfigOverride(
1238+
com.google.protobuf.Empty.getDefaultInstance(), getFilterContext(), 0);
12371239

12381240
assertThat(result.errorDetail).contains("Invalid message type");
12391241
}

0 commit comments

Comments
 (0)