Skip to content

Commit 10fc3ae

Browse files
committed
opentelemetry, rls, xds: Refine delay attributes and add comprehensive nested priority/RLS delay tests (Proposal A121)
1 parent 9a0d168 commit 10fc3ae

5 files changed

Lines changed: 90 additions & 2 deletions

File tree

opentelemetry/src/main/java/io/grpc/opentelemetry/GrpcOpenTelemetry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ && isMetricEnabled("grpc.client.attempt.delay.duration", enableMetrics, disableD
364364
* Checks whether experimental client attempt and call delay observability is globally enabled.
365365
*
366366
* <p>Guarded strictly by the {@code GRPC_EXPERIMENTAL_ENABLE_DELAY_OBSERVABILITY} environment
367-
* variable or JVM system property (defaults to {@code false}). When disabled, delay spans and
367+
* variable (defaults to {@code false}). When disabled, delay spans and
368368
* duration histograms are suppressed to avoid runtime overhead.
369369
*/
370370
static boolean isDelayObservabilityEnabled() {

opentelemetry/src/main/java/io/grpc/opentelemetry/OpenTelemetryMetricsModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import io.grpc.internal.StatsTraceContext.ServerCallMethodListener;
5151
import io.grpc.opentelemetry.GrpcOpenTelemetry.TargetFilter;
5252
import io.opentelemetry.api.baggage.Baggage;
53+
import io.opentelemetry.api.common.Attributes;
5354
import io.opentelemetry.api.common.AttributesBuilder;
5455
import io.opentelemetry.context.Context;
5556
import java.util.ArrayList;
@@ -251,7 +252,7 @@ public void recordAttemptDelayEnd() {
251252
activeDelayStopwatch = null;
252253
activeDelayType = null;
253254
if (module.resource.clientAttemptDelayCounter() != null) {
254-
AttributesBuilder builder = io.opentelemetry.api.common.Attributes.builder()
255+
AttributesBuilder builder = Attributes.builder()
255256
.put(METHOD_KEY, fullMethodName)
256257
.put(TARGET_KEY, target)
257258
.put("grpc.delay_type", delayType);

opentelemetry/src/test/java/io/grpc/opentelemetry/OpenTelemetryTracingModuleTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@
4242
import io.grpc.ClientInterceptor;
4343
import io.grpc.ClientInterceptors;
4444
import io.grpc.ClientStreamTracer;
45+
import io.grpc.ConnectivityState;
4546
import io.grpc.KnownLength;
47+
import io.grpc.LoadBalancer;
48+
import io.grpc.LoadBalancerProvider;
49+
import io.grpc.LoadBalancerRegistry;
4650
import io.grpc.ManagedChannel;
51+
import io.grpc.ManagedChannelBuilder;
4752
import io.grpc.Metadata;
4853
import io.grpc.MethodDescriptor;
4954
import io.grpc.NoopServerCall;

rls/src/test/java/io/grpc/rls/CachingRlsLbClientTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.mockito.ArgumentMatchers.any;
2828
import static org.mockito.ArgumentMatchers.argThat;
2929
import static org.mockito.ArgumentMatchers.eq;
30+
import static org.mockito.Mockito.atLeastOnce;
3031
import static org.mockito.Mockito.inOrder;
3132
import static org.mockito.Mockito.mock;
3233
import static org.mockito.Mockito.times;
@@ -625,6 +626,52 @@ public void rls_pendingLookup_returnsDelayAttributes() throws Exception {
625626
assertThat(pickResult.getDelayReason()).contains("Route Lookup Service query pending");
626627
}
627628

629+
@Test
630+
public void rls_childPolicyDelayed_returnsDelayAttributes() throws Exception {
631+
setUpRlsLbClient();
632+
RlsProtoData.RouteLookupRequestKey routeLookupRequestKey =
633+
RlsProtoData.RouteLookupRequestKey.create(
634+
ImmutableMap.of(
635+
"server", "bigtable.googleapis.com", "service-key", "service1",
636+
"method-key", "create"));
637+
rlsServerImpl.setLookupTable(
638+
ImmutableMap.of(
639+
routeLookupRequestKey,
640+
RouteLookupResponse.create(
641+
ImmutableList.of("target1"), "header")));
642+
643+
CachedRouteLookupResponse resp = getInSyncContext(routeLookupRequestKey);
644+
assertThat(resp.hasData()).isFalse();
645+
fakeClock.forwardTime(SERVER_LATENCY_MILLIS, TimeUnit.MILLISECONDS);
646+
647+
resp = getInSyncContext(routeLookupRequestKey);
648+
assertThat(resp.hasData()).isTrue();
649+
650+
LbPolicyConfiguration.ChildPolicyWrapper wrapper = resp.getChildPolicyWrapper();
651+
wrapper.getHelper().updateBalancingState(ConnectivityState.CONNECTING, new SubchannelPicker() {
652+
@Override
653+
public PickResult pickSubchannel(LoadBalancer.PickSubchannelArgs args) {
654+
return PickResult.withNoResult("connecting", "TCP handshake in progress");
655+
}
656+
});
657+
658+
ArgumentCaptor<SubchannelPicker> pickerCaptor =
659+
ArgumentCaptor.forClass(SubchannelPicker.class);
660+
verify(helper, atLeastOnce())
661+
.updateBalancingState(any(), pickerCaptor.capture());
662+
PickResult pickResult = pickerCaptor.getValue().pickSubchannel(
663+
new PickSubchannelArgsImpl(
664+
TestMethodDescriptors.voidMethod().toBuilder()
665+
.setFullMethodName("service1/create").build(),
666+
new Metadata(),
667+
CallOptions.DEFAULT,
668+
new PickDetailsConsumer() {}));
669+
assertThat(pickResult.hasResult()).isFalse();
670+
assertThat(pickResult.getDelayType()).isEqualTo("connecting");
671+
assertThat(pickResult.getDelayReason()).isEqualTo(
672+
"RLS child (target1) delayed: TCP handshake in progress");
673+
}
674+
628675
@Test
629676
public void timeout_not_changing_picked_subchannel() throws Exception {
630677
setUpRlsLbClient();

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,41 @@ public PickResult pickSubchannel(PickSubchannelArgs args) {
10601060
.isEqualTo("waiting on priority group p0 (child_reason)");
10611061
}
10621062

1063+
@Test
1064+
public void priorityPicker_nestedPriorities_composesTokens() throws Exception {
1065+
PriorityChildConfig priorityChildConfig0 =
1066+
new PriorityChildConfig(newChildConfig(fooLbProvider, new Object()), true);
1067+
PriorityLbConfig priorityLbConfig =
1068+
new PriorityLbConfig(ImmutableMap.of("p0", priorityChildConfig0), ImmutableList.of("p0"));
1069+
1070+
priorityLb.acceptResolvedAddresses(
1071+
ResolvedAddresses.newBuilder()
1072+
.setAddresses(ImmutableList.<EquivalentAddressGroup>of())
1073+
.setLoadBalancingPolicyConfig(priorityLbConfig)
1074+
.build());
1075+
1076+
Helper helper0 = Iterables.getOnlyElement(fooHelpers); // priority p0
1077+
1078+
SubchannelPicker nestedChildPicker = new SubchannelPicker() {
1079+
@Override
1080+
public PickResult pickSubchannel(PickSubchannelArgs args) {
1081+
return PickResult.withNoResult("p1:connecting",
1082+
"waiting on priority group p1 (child_reason)");
1083+
}
1084+
};
1085+
helper0.updateBalancingState(CONNECTING, nestedChildPicker);
1086+
1087+
verify(helper, atLeastOnce())
1088+
.updateBalancingState(eq(CONNECTING), pickerCaptor.capture());
1089+
1090+
SubchannelPicker priorityPicker = pickerCaptor.getValue();
1091+
PickResult result = priorityPicker.pickSubchannel(mock(PickSubchannelArgs.class));
1092+
1093+
assertThat(result.getDelayType()).isEqualTo("p0:p1:connecting");
1094+
assertThat(result.getDelayReason()).isEqualTo(
1095+
"waiting on priority group p0 (waiting on priority group p1 (child_reason))");
1096+
}
1097+
10631098
private void assertLatestConnectivityState(ConnectivityState expectedState) {
10641099
verify(helper, atLeastOnce())
10651100
.updateBalancingState(connectivityStateCaptor.capture(), pickerCaptor.capture());

0 commit comments

Comments
 (0)