From da251fe958e2d917a3bdbc273a71c66e7aa9858b Mon Sep 17 00:00:00 2001 From: donghun-cho Date: Mon, 1 Jul 2024 18:12:52 +0900 Subject: [PATCH] [#noissue] Cleanup --- .../grpc/MetadataGrpcDataSenderTest.java | 39 ++++++++++--------- .../retry/HedgingServiceConfigBuilder.java | 1 - 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/MetadataGrpcDataSenderTest.java b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/MetadataGrpcDataSenderTest.java index b22ddd92234b..61dd4e4d260c 100644 --- a/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/MetadataGrpcDataSenderTest.java +++ b/agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/grpc/MetadataGrpcDataSenderTest.java @@ -38,7 +38,6 @@ import org.mapstruct.factory.Mappers; import java.sql.Timestamp; -import java.util.Arrays; import java.util.Collections; import java.util.concurrent.CompletableFuture; @@ -53,6 +52,8 @@ class MetadataGrpcDataSenderTest { private static final String UNKNOWN_METADATA = "status code UNKNOWN"; private static final String FAIL_METADATA = "success=false"; + private static final Context.Key GRPC_METADATA_CONTEXT_KEY = Context.key("test-grpc-metadata"); + private static final Metadata.Key TEST_ID_KEY = Metadata.Key.of("test-id", Metadata.ASCII_STRING_MARSHALLER); private static final Metadata.Key GRPC_PREVIOUS_RPC_ATTEMPTS_KEY = Metadata.Key.of("grpc-previous-rpc-attempts", Metadata.ASCII_STRING_MARSHALLER); @@ -97,7 +98,8 @@ public void resetCounter() { public static class MetadataGrpcService extends MetadataGrpc.MetadataImplBase { @Override public void requestApiMetaData(PApiMetaData request, StreamObserver responseObserver) { - System.out.println(request); + countAndPrint(request); + switch (request.getApiInfo()) { case DELAY_METADATA: try { @@ -127,29 +129,33 @@ public void requestApiMetaData(PApiMetaData request, StreamObserver res break; } } - } - public static class TestServerInterceptor implements ServerInterceptor { - @Override - public ServerCall.Listener interceptCall(ServerCall serverCall, Metadata metadata, ServerCallHandler serverCallHandler) { + private void countAndPrint(PApiMetaData request) { int totalAttempts = -1; - String callTestId = metadata.get(TEST_ID_KEY); - if (callTestId != null && callTestId.equals(Integer.toString(testId))) { - requestCounter++; + Metadata metadata = GRPC_METADATA_CONTEXT_KEY.get(Context.current()); + String requestTestId = metadata.get(TEST_ID_KEY); + String previousAttempts = metadata.get(GRPC_PREVIOUS_RPC_ATTEMPTS_KEY); - String previousAttempts = metadata.get(GRPC_PREVIOUS_RPC_ATTEMPTS_KEY); + if (requestTestId != null && requestTestId.equals(Integer.toString(testId))) { + requestCounter++; if (previousAttempts == null) { totalAttempts = 1; } else { totalAttempts = Integer.parseInt(previousAttempts) + 1; } - //Assertions.assertThat(requestCounter).isEqualTo(totalAttempts); } - System.out.println("---- server time: " + new Timestamp(System.currentTimeMillis())); - System.out.println("testId: " + callTestId); + System.out.println("testId: " + requestTestId); System.out.println("total attempts: " + totalAttempts); - return Contexts.interceptCall(Context.current(), serverCall, metadata, serverCallHandler); + System.out.println(request); + } + } + + public static class TestServerInterceptor implements ServerInterceptor { + @Override + public ServerCall.Listener interceptCall(ServerCall serverCall, Metadata metadata, ServerCallHandler serverCallHandler) { + Context newContext = Context.current().withValue(GRPC_METADATA_CONTEXT_KEY, metadata); + return Contexts.interceptCall(newContext, serverCall, metadata, serverCallHandler); } } @@ -294,11 +300,6 @@ public void start(Listener responseListener, Metadata headers) { private HedgingServiceConfigBuilder getTestServiceConfigBuilder() { HedgingServiceConfigBuilder serviceConfigBuilder = new HedgingServiceConfigBuilder(); serviceConfigBuilder.setHedgingDelayMillis(DEFAULT_TEST_HEDGING_DELAY_MILLIS); - serviceConfigBuilder.setNonFatalStatusCodes(Arrays.asList( - Status.Code.UNKNOWN.name(), - Status.Code.INTERNAL.name(), - Status.Code.UNAVAILABLE.name() - )); return serviceConfigBuilder; } diff --git a/grpc/src/main/java/com/navercorp/pinpoint/grpc/client/retry/HedgingServiceConfigBuilder.java b/grpc/src/main/java/com/navercorp/pinpoint/grpc/client/retry/HedgingServiceConfigBuilder.java index 449741e27638..596cc3158b06 100644 --- a/grpc/src/main/java/com/navercorp/pinpoint/grpc/client/retry/HedgingServiceConfigBuilder.java +++ b/grpc/src/main/java/com/navercorp/pinpoint/grpc/client/retry/HedgingServiceConfigBuilder.java @@ -30,7 +30,6 @@ public class HedgingServiceConfigBuilder implements ServiceConfigBuilder { public static final long DEFAULT_HEDGING_DELAY_MILLIS = 1000L; public static final List DEFAULT_STATUS_CODES = Arrays.asList( Status.Code.UNKNOWN.name(), - Status.Code.INTERNAL.name(), Status.Code.UNAVAILABLE.name() );