Skip to content

Commit

Permalink
xds: include the target label to WRR metrics (#11141)
Browse files Browse the repository at this point in the history
  • Loading branch information
temawi committed May 1, 2024
1 parent a9fb272 commit 35a171b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
18 changes: 10 additions & 8 deletions xds/src/main/java/io/grpc/xds/WeightedRoundRobinLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,31 +430,33 @@ private void updateWeight() {
for (int i = 0; i < children.size(); i++) {
double newWeight = ((WeightedChildLbState) children.get(i)).getWeight(staleEndpoints,
notYetUsableEndpoints);
// TODO: add target and locality labels once available
// TODO: add locality label once available
helper.getMetricRecorder()
.recordDoubleHistogram(ENDPOINT_WEIGHTS_HISTOGRAM, newWeight, ImmutableList.of(""),
.recordDoubleHistogram(ENDPOINT_WEIGHTS_HISTOGRAM, newWeight,
ImmutableList.of(helper.getChannelTarget()),
ImmutableList.of(""));
newWeights[i] = newWeight > 0 ? (float) newWeight : 0.0f;
}
if (staleEndpoints.get() > 0) {
// TODO: add target and locality labels once available
// TODO: add locality label once available
helper.getMetricRecorder()
.addLongCounter(ENDPOINT_WEIGHT_STALE_COUNTER, staleEndpoints.get(),
ImmutableList.of(""),
ImmutableList.of(helper.getChannelTarget()),
ImmutableList.of(""));
}
if (notYetUsableEndpoints.get() > 0) {
// TODO: add target and locality labels once available
// TODO: add locality label once available
helper.getMetricRecorder()
.addLongCounter(ENDPOINT_WEIGHT_NOT_YET_USEABLE_COUNTER, notYetUsableEndpoints.get(),
ImmutableList.of(""), ImmutableList.of(""));
ImmutableList.of(helper.getChannelTarget()), ImmutableList.of(""));
}

this.scheduler = new StaticStrideScheduler(newWeights, sequence);
if (this.scheduler.usesRoundRobin()) {
// TODO: add target and locality labels once available
// TODO: locality label once available
helper.getMetricRecorder()
.addLongCounter(RR_FALLBACK_COUNTER, 1, ImmutableList.of(""), ImmutableList.of(""));
.addLongCounter(RR_FALLBACK_COUNTER, 1, ImmutableList.of(helper.getChannelTarget()),
ImmutableList.of(""));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public void uncaughtException(Thread t, Throwable e) {
}
});

private String channelTarget = "channel-target";

public WeightedRoundRobinLoadBalancerTest() {
testHelperInstance = new TestHelper();
helper = mock(Helper.class, delegatesTo(testHelperInstance));
Expand Down Expand Up @@ -1238,7 +1240,7 @@ private void verifyLongCounterRecord(String name, int times, long value) {
public boolean matches(LongCounterMetricInstrument longCounterInstrument) {
return longCounterInstrument.getName().equals(name);
}
}), eq(value), eq(Lists.newArrayList("")), eq(Lists.newArrayList("")));
}), eq(value), eq(Lists.newArrayList(channelTarget)), eq(Lists.newArrayList("")));
}

// Verifies that the MetricRecorder has been called to record a given double histogram value the
Expand All @@ -1250,7 +1252,7 @@ private void verifyDoubleHistogramRecord(String name, int times, double value) {
public boolean matches(DoubleHistogramMetricInstrument doubleHistogramInstrument) {
return doubleHistogramInstrument.getName().equals(name);
}
}), eq(value), eq(Lists.newArrayList("")), eq(Lists.newArrayList("")));
}), eq(value), eq(Lists.newArrayList(channelTarget)), eq(Lists.newArrayList("")));
}

private int getNumFilteredPendingTasks() {
Expand Down Expand Up @@ -1326,5 +1328,10 @@ public Map<Subchannel, SubchannelStateListener> getSubchannelStateListeners() {
public MetricRecorder getMetricRecorder() {
return mockMetricRecorder;
}

@Override
public String getChannelTarget() {
return channelTarget;
}
}
}

0 comments on commit 35a171b

Please sign in to comment.