GeezerVison is showing github.com — rls: Add the target label to RLS counter metrics (#11142) · grpc/grpc-java@a1d1932
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: rls/src/main/java/io/grpc/rls/CachingRlsLbClient.java +15-15Lines changed: 15 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 24 | 24 | import com.google.common.base.MoreObjects; | 25 | 25 | import com.google.common.base.MoreObjects.ToStringHelper; | 26 | 26 | import com.google.common.base.Ticker; | 27 | | -import com.google.common.collect.Lists; | 28 | 27 | import com.google.common.util.concurrent.Futures; | 29 | 28 | import com.google.common.util.concurrent.ListenableFuture; | 30 | 29 | import com.google.common.util.concurrent.MoreExecutors; | | 61 | 60 | import io.grpc.util.ForwardingLoadBalancerHelper; | 62 | 61 | import java.net.URI; | 63 | 62 | import java.net.URISyntaxException; | | 63 | +import java.util.Arrays; | | 64 | +import java.util.Collections; | 64 | 65 | import java.util.HashMap; | 65 | 66 | import java.util.List; | 66 | 67 | import java.util.Map; | @@ -127,16 +128,16 @@ final class CachingRlsLbClient { | 127 | 128 | = MetricInstrumentRegistry.getDefaultRegistry(); | 128 | 129 | DEFAULT_TARGET_PICKS_COUNTER = metricInstrumentRegistry.registerLongCounter( | 129 | 130 | "grpc.lb.rls.default_target_picks", "Number of LB picks sent to the default target", "pick", | 130 | | - Lists.newArrayList("grpc.target", "grpc.lb.rls.server_target", | 131 | | - "grpc.lb.rls.data_plane_target", "grpc.lb.pick_result"), Lists.newArrayList(), true); | | 131 | + Arrays.asList("grpc.target", "grpc.lb.rls.server_target", | | 132 | + "grpc.lb.rls.data_plane_target", "grpc.lb.pick_result"), Collections.emptyList(), true); | 132 | 133 | TARGET_PICKS_COUNTER = metricInstrumentRegistry.registerLongCounter("grpc.lb.rls.target_picks", | 133 | 134 | "Number of LB picks sent to each RLS target", "pick", | 134 | | - Lists.newArrayList("grpc.target", "grpc.lb.rls.server_target", | 135 | | - "grpc.lb.rls.data_plane_target", "grpc.lb.pick_result"), Lists.newArrayList(), true); | | 135 | + Arrays.asList("grpc.target", "grpc.lb.rls.server_target", | | 136 | + "grpc.lb.rls.data_plane_target", "grpc.lb.pick_result"), Collections.emptyList(), true); | 136 | 137 | FAILED_PICKS_COUNTER = metricInstrumentRegistry.registerLongCounter("grpc.lb.rls.failed_picks", | 137 | 138 | "Number of LB picks failed due to either a failed RLS request or the RLS channel being " | 138 | | - + "throttled", "pick", Lists.newArrayList("grpc.target", "grpc.lb.rls.server_target"), | 139 | | - Lists.newArrayList(), true); | | 139 | + + "throttled", "pick", Arrays.asList("grpc.target", "grpc.lb.rls.server_target"), | | 140 | + Collections.emptyList(), true); | 140 | 141 | } | 141 | 142 |
| 142 | 143 | private CachingRlsLbClient(Builder builder) { | @@ -968,11 +969,11 @@ public PickResult pickSubchannel(PickSubchannelArgs args) { | 968 | 969 | // Happy path | 969 | 970 | logger.log(ChannelLogLevel.DEBUG, "Returning PickResult"); | 970 | 971 | PickResult pickResult = picker.pickSubchannel(args); | 971 | | - // TODO: include the "grpc.target" label once target is available here. | 972 | 972 | if (pickResult.hasResult()) { | 973 | 973 | helper.getMetricRecorder().addLongCounter(TARGET_PICKS_COUNTER, 1, | 974 | | - Lists.newArrayList("", lookupService, childPolicyWrapper.getTarget(), | 975 | | - determineMetricsPickResult(pickResult)), Lists.newArrayList()); | | 974 | + Arrays.asList(helper.getChannelTarget(), lookupService, | | 975 | + childPolicyWrapper.getTarget(), determineMetricsPickResult(pickResult)), | | 976 | + Collections.emptyList()); | 976 | 977 | } | 977 | 978 | return pickResult; | 978 | 979 | } else if (response.hasError()) { | @@ -982,9 +983,8 @@ public PickResult pickSubchannel(PickSubchannelArgs args) { | 982 | 983 | return useFallback(args); | 983 | 984 | } | 984 | 985 | logger.log(ChannelLogLevel.DEBUG, "No RLS fallback, returning PickResult with an error"); | 985 | | - // TODO: include the "grpc.target" label once target is available here. | 986 | 986 | helper.getMetricRecorder().addLongCounter(FAILED_PICKS_COUNTER, 1, | 987 | | - Lists.newArrayList("", lookupService), Lists.newArrayList()); | | 987 | + Arrays.asList(helper.getChannelTarget(), lookupService), Collections.emptyList()); | 988 | 988 | return PickResult.withError( | 989 | 989 | convertRlsServerStatus(response.getStatus(), | 990 | 990 | lbPolicyConfig.getRouteLookupConfig().lookupService())); | @@ -1007,10 +1007,10 @@ private PickResult useFallback(PickSubchannelArgs args) { | 1007 | 1007 | } | 1008 | 1008 | PickResult pickResult = picker.pickSubchannel(args); | 1009 | 1009 | if (pickResult.hasResult()) { | 1010 | | - // TODO: include the grpc.target label once target is available here. | 1011 | 1010 | helper.getMetricRecorder().addLongCounter(DEFAULT_TARGET_PICKS_COUNTER, 1, | 1012 | | - Lists.newArrayList("", lookupService, fallbackChildPolicyWrapper.getTarget(), | 1013 | | - determineMetricsPickResult(pickResult)), Lists.newArrayList()); | | 1011 | + Arrays.asList(helper.getChannelTarget(), lookupService, | | 1012 | + fallbackChildPolicyWrapper.getTarget(), determineMetricsPickResult(pickResult)), | | 1013 | + Collections.emptyList()); | 1014 | 1014 | } | 1015 | 1015 | return pickResult; | 1016 | 1016 | } | |
Collapse file Copy file name to clipboardExpand all lines: rls/src/test/java/io/grpc/rls/CachingRlsLbClientTest.java +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -900,6 +900,11 @@ public ChannelLogger getChannelLogger() { | 900 | 900 | public MetricRecorder getMetricRecorder() { | 901 | 901 | return mockMetricRecorder; | 902 | 902 | } | | 903 | + | | 904 | + @Override | | 905 | + public String getChannelTarget() { | | 906 | + return "channelTarget"; | | 907 | + } | 903 | 908 | } | 904 | 909 |
| 905 | 910 | private static final class FakeThrottler implements Throttler { | |
Collapse file Copy file name to clipboardExpand all lines: rls/src/test/java/io/grpc/rls/RlsLoadBalancerTest.java +12-2Lines changed: 12 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -124,6 +124,7 @@ public void uncaughtException(Thread t, Throwable e) { | 124 | 124 | private final FakeRlsServerImpl fakeRlsServerImpl = new FakeRlsServerImpl(); | 125 | 125 | private final Deque<FakeSubchannel> subchannels = new LinkedList<>(); | 126 | 126 | private final FakeThrottler fakeThrottler = new FakeThrottler(); | | 127 | + private final String channelTarget = "channelTarget"; | 127 | 128 | @Mock | 128 | 129 | private Marshaller<Object> mockMarshaller; | 129 | 130 | @Captor | @@ -296,6 +297,7 @@ public void lb_working_withoutDefaultTarget_noRlsResponse() throws Exception { | 296 | 297 | PickResult res = picker.pickSubchannel(searchSubchannelArgs); // create subchannel | 297 | 298 | assertThat(res.getStatus().getCode()).isEqualTo(Code.UNAVAILABLE); | 298 | 299 | inOrder.verify(helper).getMetricRecorder(); | | 300 | + inOrder.verify(helper).getChannelTarget(); | 299 | 301 | inOrder.verifyNoMoreInteractions(); | 300 | 302 | verifyFailedPicksCounterAdd(1, 1); | 301 | 303 | verifyNoMoreInteractions(mockMetricRecorder); | @@ -319,6 +321,7 @@ public void lb_working_withDefaultTarget_noRlsResponse() throws Exception { | 319 | 321 | assertThat(fallbackSubchannel).isNotNull(); | 320 | 322 | assertThat(subchannelIsReady(fallbackSubchannel)).isTrue(); | 321 | 323 | inOrder.verify(helper).getMetricRecorder(); | | 324 | + inOrder.verify(helper).getChannelTarget(); | 322 | 325 | inOrder.verifyNoMoreInteractions(); | 323 | 326 | verifyLongCounterAdd("grpc.lb.rls.default_target_picks", 1, 1, "defaultTarget", "complete"); | 324 | 327 | verifyNoMoreInteractions(mockMetricRecorder); | @@ -393,6 +396,7 @@ public void lb_working_withoutDefaultTarget() throws Exception { | 393 | 396 | FakeSubchannel searchSubchannel = | 394 | 397 | (FakeSubchannel) markReadyAndGetPickResult(inOrder, searchSubchannelArgs).getSubchannel(); | 395 | 398 | inOrder.verify(helper).getMetricRecorder(); | | 399 | + inOrder.verify(helper).getChannelTarget(); | 396 | 400 | inOrder.verifyNoMoreInteractions(); | 397 | 401 | assertThat(subchannelIsReady(searchSubchannel)).isTrue(); | 398 | 402 | assertThat(subchannels.getLast()).isSameInstanceAs(searchSubchannel); | @@ -468,6 +472,7 @@ public void lb_nameResolutionFailed() throws Exception { | 468 | 472 | verifyLongCounterAdd("grpc.lb.rls.target_picks", 1, 1, "wilderness", "complete"); | 469 | 473 |
| 470 | 474 | inOrder.verify(helper).getMetricRecorder(); | | 475 | + inOrder.verify(helper).getChannelTarget(); | 471 | 476 | inOrder.verifyNoMoreInteractions(); | 472 | 477 |
| 473 | 478 | rlsLb.handleNameResolutionError(Status.UNAVAILABLE); | @@ -559,7 +564,7 @@ public boolean matches(LongCounterMetricInstrument longCounterInstrument) { | 559 | 564 | return longCounterInstrument.getName().equals(name); | 560 | 565 | } | 561 | 566 | }), eq(value), | 562 | | - eq(Lists.newArrayList("", "localhost:8972", dataPlaneTargetLabel, pickResult)), | | 567 | + eq(Lists.newArrayList(channelTarget, "localhost:8972", dataPlaneTargetLabel, pickResult)), | 563 | 568 | eq(Lists.newArrayList())); | 564 | 569 | } | 565 | 570 |
| @@ -573,7 +578,7 @@ public boolean matches(LongCounterMetricInstrument longCounterInstrument) { | 573 | 578 | return longCounterInstrument.getName().equals("grpc.lb.rls.failed_picks"); | 574 | 579 | } | 575 | 580 | }), eq(value), | 576 | | - eq(Lists.newArrayList("", "localhost:8972")), | | 581 | + eq(Lists.newArrayList(channelTarget, "localhost:8972")), | 577 | 582 | eq(Lists.newArrayList())); | 578 | 583 | } | 579 | 584 |
| @@ -675,6 +680,11 @@ public ChannelLogger getChannelLogger() { | 675 | 680 | public MetricRecorder getMetricRecorder() { | 676 | 681 | return mockMetricRecorder; | 677 | 682 | } | | 683 | + | | 684 | + @Override | | 685 | + public String getChannelTarget() { | | 686 | + return channelTarget; | | 687 | + } | 678 | 688 | } | 679 | 689 |
| 680 | 690 | private static final class FakeRlsServerImpl | |
|