From 35a171bc1d544241dd983deee9f407ebddddbc4a Mon Sep 17 00:00:00 2001 From: Terry Wilson Date: Wed, 1 May 2024 15:20:38 -0700 Subject: [PATCH] xds: include the target label to WRR metrics (#11141) --- .../xds/WeightedRoundRobinLoadBalancer.java | 18 ++++++++++-------- .../WeightedRoundRobinLoadBalancerTest.java | 11 +++++++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/xds/src/main/java/io/grpc/xds/WeightedRoundRobinLoadBalancer.java b/xds/src/main/java/io/grpc/xds/WeightedRoundRobinLoadBalancer.java index 1f9d6908126..cdbb0e3be08 100644 --- a/xds/src/main/java/io/grpc/xds/WeightedRoundRobinLoadBalancer.java +++ b/xds/src/main/java/io/grpc/xds/WeightedRoundRobinLoadBalancer.java @@ -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("")); } } diff --git a/xds/src/test/java/io/grpc/xds/WeightedRoundRobinLoadBalancerTest.java b/xds/src/test/java/io/grpc/xds/WeightedRoundRobinLoadBalancerTest.java index e43de19b517..6ef69c5ebdb 100644 --- a/xds/src/test/java/io/grpc/xds/WeightedRoundRobinLoadBalancerTest.java +++ b/xds/src/test/java/io/grpc/xds/WeightedRoundRobinLoadBalancerTest.java @@ -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)); @@ -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 @@ -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() { @@ -1326,5 +1328,10 @@ public Map getSubchannelStateListeners() { public MetricRecorder getMetricRecorder() { return mockMetricRecorder; } + + @Override + public String getChannelTarget() { + return channelTarget; + } } }