From 04c4d993a668a6ee123fc33e0349eeeb9cbec162 Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Mon, 30 Mar 2026 16:35:43 -0500 Subject: [PATCH] Make reason tags upper-case --- .../grpc/MetricServerInterceptor.java | 7 ++++--- .../grpc/MetricServerInterceptorTest.java | 14 +++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/MetricServerInterceptor.java b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/MetricServerInterceptor.java index cd11ba1f1..4980e6bcf 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/MetricServerInterceptor.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/MetricServerInterceptor.java @@ -27,6 +27,7 @@ import io.micrometer.core.instrument.Timer; import java.io.UncheckedIOException; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import javax.annotation.Nullable; @@ -47,9 +48,9 @@ public class MetricServerInterceptor implements ServerInterceptor { private static final String TAG_REASON = "reason"; @VisibleForTesting - static final String DEFAULT_SUCCESS_REASON = "success"; + static final String DEFAULT_SUCCESS_REASON = "SUCCESS"; @VisibleForTesting - static final String DEFAULT_ERROR_REASON = "n/a"; + static final String DEFAULT_ERROR_REASON = "N/A"; @VisibleForTesting static final String REQUEST_MESSAGE_COUNTER_NAME = MetricsUtil.name(MetricServerInterceptor.class, "requestMessage"); @@ -124,7 +125,7 @@ public class MetricServerInterceptor implements ServerInterceptor { } Tags responseTags = tags.and(Tag.of(TAG_STATUS_CODE, status.getCode().name())); if (reason != null) { - responseTags = responseTags.and(TAG_REASON, reason); + responseTags = responseTags.and(TAG_REASON, reason.toUpperCase(Locale.ROOT)); } meterRegistry.counter(RPC_COUNTER_NAME, responseTags).increment(); super.close(status, responseHeaders); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/MetricServerInterceptorTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/MetricServerInterceptorTest.java index 72b36f968..348c0ddd7 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/MetricServerInterceptorTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/MetricServerInterceptorTest.java @@ -198,15 +198,15 @@ public class MetricServerInterceptorTest { static Stream testUnaryOkResponseReason() { return Stream.of( - Arguments.argumentSet("Default reason", TagResponse.newBuilder().build(), "success"), - Arguments.argumentSet("No reason", TagResponse.newBuilder().setNoReason(true).build(), "success"), - Arguments.argumentSet("Explicitly set reason", TagResponse.newBuilder().setReason1(true).build(), "reason_1"), - Arguments.argumentSet("Nested reason", TagResponse.newBuilder().setNestedReason(TagResponse.NestedReason.newBuilder().setReason(true)).build(), "nested_reason")); + Arguments.argumentSet("Default reason", TagResponse.newBuilder().build(), "SUCCESS"), + Arguments.argumentSet("No reason", TagResponse.newBuilder().setNoReason(true).build(), "SUCCESS"), + Arguments.argumentSet("Explicitly set reason", TagResponse.newBuilder().setReason1(true).build(), "REASON_1"), + Arguments.argumentSet("Nested reason", TagResponse.newBuilder().setNestedReason(TagResponse.NestedReason.newBuilder().setReason(true)).build(), "NESTED_REASON")); } @ParameterizedTest @MethodSource - void testUnaryOkResponseReason(TagResponse response, String expectedReason) throws InterruptedException { + void testUnaryOkResponseReason(TagResponse response, String expectedReason) { final TagTestServiceGrpc.TagTestServiceBlockingStub tagTestServiceBlockingStub = TagTestServiceGrpc.newBlockingStub(channel); when(tagResponseSupplier.get()).thenReturn(response); @@ -229,13 +229,13 @@ public class MetricServerInterceptorTest { // We make no promises if proto fields that have reason tags are present on a message, but this tests for the sane // behavior that at least one of these tags makes it into the metric. assertThat(find(Counter.class, MetricServerInterceptor.RPC_COUNTER_NAME).getId().getTag("reason")) - .isIn("duplicate_reason", "reason_1"); + .isIn("DUPLICATE_REASON", "REASON_1"); } @CartesianTest public void testStatusErrorResponseReason( @CartesianTest.Enum(mode = CartesianTest.Enum.Mode.EXCLUDE, names = {"OK"}) Status.Code statusCode, - @CartesianTest.Values(strings = {"test", "", "null"}) String reasonParam) { + @CartesianTest.Values(strings = {"TEST", "", "null"}) String reasonParam) { final String reason, expectedReasonTag; if (reasonParam.equals("null")) {