Skip to content

Commit 7162d2d

Browse files
committed
xds: Pass grpc.xds.cluster label to tracer
This is in service to gRFC A89. Since the gRFC isn't finalized this purposefully doesn't really do anything yet. The grpc-opentelemetry change to use this optional label will be done after the gRFC is merged. grpc-opentelemetry currently has a hard-coded list (one entry) of labels that it looks for, and this label will need to be added. b/356167676
1 parent 176f3ee commit 7162d2d

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ private RequestLimitingSubchannelPicker(SubchannelPicker delegate,
385385
public PickResult pickSubchannel(PickSubchannelArgs args) {
386386
args.getCallOptions().getOption(ClusterImplLoadBalancerProvider.FILTER_METADATA_CONSUMER)
387387
.accept(filterMetadata);
388+
args.getPickDetailsConsumer().addOptionalLabel("grpc.xds.cluster", cluster);
388389
for (DropOverload dropOverload : dropPolicies) {
389390
int rand = random.nextInt(1_000_000);
390391
if (rand < dropOverload.dropsPerMillion()) {

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

+31-2
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public void nameResolutionError_afterChildPolicyInstantiated_propagateToDownstre
271271
}
272272

273273
@Test
274-
public void pick_addsLocalityLabel() {
274+
public void pick_addsOptionalLabels() {
275275
LoadBalancerProvider weightedTargetProvider = new WeightedTargetLoadBalancerProvider();
276276
WeightedTargetConfig weightedTargetConfig =
277277
buildWeightedTargetConfig(ImmutableMap.of(locality, 10));
@@ -298,6 +298,31 @@ public void pick_addsLocalityLabel() {
298298
// The value will be determined by the parent policy, so can be different than the value used in
299299
// makeAddress() for the test.
300300
verify(detailsConsumer).addOptionalLabel("grpc.lb.locality", locality.toString());
301+
verify(detailsConsumer).addOptionalLabel("grpc.xds.cluster", CLUSTER);
302+
}
303+
304+
@Test
305+
public void pick_noResult_addsClusterLabel() {
306+
LoadBalancerProvider weightedTargetProvider = new WeightedTargetLoadBalancerProvider();
307+
WeightedTargetConfig weightedTargetConfig =
308+
buildWeightedTargetConfig(ImmutableMap.of(locality, 10));
309+
ClusterImplConfig config = new ClusterImplConfig(CLUSTER, EDS_SERVICE_NAME, LRS_SERVER_INFO,
310+
null, Collections.<DropOverload>emptyList(),
311+
GracefulSwitchLoadBalancer.createLoadBalancingPolicyConfig(
312+
weightedTargetProvider, weightedTargetConfig),
313+
null, Collections.emptyMap());
314+
EquivalentAddressGroup endpoint = makeAddress("endpoint-addr", locality);
315+
deliverAddressesAndConfig(Collections.singletonList(endpoint), config);
316+
FakeLoadBalancer leafBalancer = Iterables.getOnlyElement(downstreamBalancers);
317+
leafBalancer.deliverSubchannelState(PickResult.withNoResult(), ConnectivityState.CONNECTING);
318+
assertThat(currentState).isEqualTo(ConnectivityState.CONNECTING);
319+
320+
PickDetailsConsumer detailsConsumer = mock(PickDetailsConsumer.class);
321+
pickSubchannelArgs = new PickSubchannelArgsImpl(
322+
TestMethodDescriptors.voidMethod(), new Metadata(), CallOptions.DEFAULT, detailsConsumer);
323+
PickResult result = currentPicker.pickSubchannel(pickSubchannelArgs);
324+
assertThat(result.getStatus().isOk()).isTrue();
325+
verify(detailsConsumer).addOptionalLabel("grpc.xds.cluster", CLUSTER);
301326
}
302327

303328
@Test
@@ -1061,10 +1086,14 @@ public void shutdown() {
10611086
}
10621087

10631088
void deliverSubchannelState(final Subchannel subchannel, ConnectivityState state) {
1089+
deliverSubchannelState(PickResult.withSubchannel(subchannel), state);
1090+
}
1091+
1092+
void deliverSubchannelState(final PickResult result, ConnectivityState state) {
10641093
SubchannelPicker picker = new SubchannelPicker() {
10651094
@Override
10661095
public PickResult pickSubchannel(PickSubchannelArgs args) {
1067-
return PickResult.withSubchannel(subchannel);
1096+
return result;
10681097
}
10691098
};
10701099
helper.updateBalancingState(state, picker);

0 commit comments

Comments
 (0)