From 91c4a345b7d3948eb12a8c5136a99165e997e2e5 Mon Sep 17 00:00:00 2001 From: ga-ram Date: Thu, 15 Jun 2023 15:18:11 +0900 Subject: [PATCH] [#10041] Add auto option to profiler.span.collected.uri --- agent/src/main/resources/pinpoint-root.config | 7 ++--- .../grpc/GrpcSpanMessageConverter.java | 19 ++++--------- .../GrpcSpanMessageConverterProvider.java | 27 ++++++++++++++++--- .../grpc/config/SpanAutoUriGetter.java | 15 +++++++++++ .../context/grpc/config/SpanRawUriGetter.java | 10 +++++++ .../grpc/config/SpanTemplateUriGetter.java | 10 +++++++ .../context/grpc/config/SpanUriGetter.java | 7 +++++ .../compress/GrpcSpanProcessorV2Test.java | 3 ++- 8 files changed, 77 insertions(+), 21 deletions(-) create mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanAutoUriGetter.java create mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanRawUriGetter.java create mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanTemplateUriGetter.java create mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanUriGetter.java diff --git a/agent/src/main/resources/pinpoint-root.config b/agent/src/main/resources/pinpoint-root.config index 21d798f07a9c..70f7d39807cd 100644 --- a/agent/src/main/resources/pinpoint-root.config +++ b/agent/src/main/resources/pinpoint-root.config @@ -408,9 +408,10 @@ pinpoint.banner.configs=pinpoint.profiler.profiles.active,\ ########################################################### # SPAN COLLECTED URL TYPE # ########################################################### -# Collected URI Type for profiler : TEMPLATE (default), RAW +# Collected URI Type for profiler : TEMPLATE, RAW, AUTO (default) # e.g.) # Collected URI for each type for a request `/randomResponseTime/50` mapped to `@RequestMapping("/randomResponseTime/**")` -# TEMPLATE (default) : `/randomResponseTime/**` +# TEMPLATE : `/randomResponseTime/**` # RAW : `/randomResponseTime/50` -profiler.span.collected.uri.type=TEMPLATE +# AUTO (default) : `/randomResponseTime/**` for supported frameworks, `/randomResponseTime/50` for unsupported frameworks +profiler.span.collected.uri.type=AUTO \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverter.java index 2813e4b5bcde..6d4b82394934 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverter.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverter.java @@ -47,6 +47,7 @@ import com.navercorp.pinpoint.profiler.context.SpanEvent; import com.navercorp.pinpoint.profiler.context.SpanType; import com.navercorp.pinpoint.profiler.context.compress.SpanProcessor; +import com.navercorp.pinpoint.profiler.context.grpc.config.SpanUriGetter; import com.navercorp.pinpoint.profiler.context.id.Shared; import com.navercorp.pinpoint.profiler.context.id.TraceRoot; import org.apache.logging.log4j.LogManager; @@ -80,19 +81,15 @@ public class GrpcSpanMessageConverter implements MessageConverter spanProcessor, - String spanCollectedUriType) { + SpanUriGetter spanUriGetter) { this.agentId = Objects.requireNonNull(agentId, "agentId"); this.applicationServiceType = applicationServiceType; this.spanProcessor = Objects.requireNonNull(spanProcessor, "spanProcessor"); - this.spanCollectedUriType = SpanUriType.valueOf(spanCollectedUriType); + this.spanUriGetter = Objects.requireNonNull(spanUriGetter); } @Override @@ -196,13 +193,7 @@ private PAcceptEvent newAcceptEvent(Span span) { } final Shared shared = span.getTraceRoot().getShared(); - final String rpc; - if (spanCollectedUriType == SpanUriType.RAW) { - rpc = shared.getRpcName(); - } else { - rpc = shared.getUriTemplate(); - } - + final String rpc = spanUriGetter.getCollectedUri(shared); if (StringUtils.isEmpty(rpc)) { hasEmptyValue = true; builder.setRpc(DEFAULT_RPC_NAME); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterProvider.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterProvider.java index b8dc365ded68..c460836c427d 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterProvider.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcSpanMessageConverterProvider.java @@ -26,6 +26,10 @@ import com.navercorp.pinpoint.grpc.trace.PSpanChunk; import com.navercorp.pinpoint.profiler.context.SpanType; import com.navercorp.pinpoint.profiler.context.compress.SpanProcessor; +import com.navercorp.pinpoint.profiler.context.grpc.config.SpanAutoUriGetter; +import com.navercorp.pinpoint.profiler.context.grpc.config.SpanRawUriGetter; +import com.navercorp.pinpoint.profiler.context.grpc.config.SpanTemplateUriGetter; +import com.navercorp.pinpoint.profiler.context.grpc.config.SpanUriGetter; import com.navercorp.pinpoint.profiler.context.module.AgentId; import com.navercorp.pinpoint.profiler.context.module.ApplicationServerType; @@ -42,7 +46,12 @@ public class GrpcSpanMessageConverterProvider implements Provider spanPostProcessor; - private final String spanCollectedUriType; + public enum SpanUriType { + TEMPLATE, RAW, AUTO + } + + private final SpanUriGetter spanUriGetter; + @Inject public GrpcSpanMessageConverterProvider(@AgentId String agentId, @ApplicationServerType ServiceType applicationServiceType, @@ -52,11 +61,23 @@ public GrpcSpanMessageConverterProvider(@AgentId String agentId, @ApplicationSer this.applicationServiceTypeCode = applicationServiceType.getCode(); this.spanPostProcessor = Objects.requireNonNull(spanPostProcessor, "spanPostProcessor"); Objects.requireNonNull(profilerConfig, "profilerConfig"); - this.spanCollectedUriType = profilerConfig.readString(SPAN_COLLECTED_URI_CONFIG, "TEMPLATE"); + SpanUriType spanCollectedUriType = SpanUriType.valueOf(profilerConfig.readString(SPAN_COLLECTED_URI_CONFIG, "AUTO")); + this.spanUriGetter = getSpanUriGetter(spanCollectedUriType); } @Override public MessageConverter get() { - return new GrpcSpanMessageConverter(agentId, applicationServiceTypeCode, spanPostProcessor, spanCollectedUriType); + return new GrpcSpanMessageConverter(agentId, applicationServiceTypeCode, spanPostProcessor, spanUriGetter); + } + + private SpanUriGetter getSpanUriGetter(SpanUriType spanCollectedUriType) { + switch (spanCollectedUriType) { + case RAW: + return new SpanRawUriGetter(); + case TEMPLATE: + return new SpanTemplateUriGetter(); + default: + return new SpanAutoUriGetter(); + } } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanAutoUriGetter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanAutoUriGetter.java new file mode 100644 index 000000000000..a7eae04c1e1b --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanAutoUriGetter.java @@ -0,0 +1,15 @@ +package com.navercorp.pinpoint.profiler.context.grpc.config; + +import com.navercorp.pinpoint.common.util.StringUtils; +import com.navercorp.pinpoint.profiler.context.id.Shared; + +public class SpanAutoUriGetter implements SpanUriGetter { + @Override + public String getCollectedUri(Shared shared) { + String uriTemplate = shared.getUriTemplate(); + if (StringUtils.isEmpty(uriTemplate)) { + return shared.getRpcName(); + } + return uriTemplate; + } +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanRawUriGetter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanRawUriGetter.java new file mode 100644 index 000000000000..f4577ea6fddb --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanRawUriGetter.java @@ -0,0 +1,10 @@ +package com.navercorp.pinpoint.profiler.context.grpc.config; + +import com.navercorp.pinpoint.profiler.context.id.Shared; + +public class SpanRawUriGetter implements SpanUriGetter { + @Override + public String getCollectedUri(Shared shared) { + return shared.getRpcName(); + } +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanTemplateUriGetter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanTemplateUriGetter.java new file mode 100644 index 000000000000..8f3c79553644 --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanTemplateUriGetter.java @@ -0,0 +1,10 @@ +package com.navercorp.pinpoint.profiler.context.grpc.config; + +import com.navercorp.pinpoint.profiler.context.id.Shared; + +public class SpanTemplateUriGetter implements SpanUriGetter { + @Override + public String getCollectedUri(Shared shared) { + return shared.getUriTemplate(); + } +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanUriGetter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanUriGetter.java new file mode 100644 index 000000000000..442eabfea34e --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/config/SpanUriGetter.java @@ -0,0 +1,7 @@ +package com.navercorp.pinpoint.profiler.context.grpc.config; + +import com.navercorp.pinpoint.profiler.context.id.Shared; + +public interface SpanUriGetter { + String getCollectedUri(Shared shared); +} diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/GrpcSpanProcessorV2Test.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/GrpcSpanProcessorV2Test.java index bf3338376211..923ef2ae13c6 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/GrpcSpanProcessorV2Test.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/compress/GrpcSpanProcessorV2Test.java @@ -23,6 +23,7 @@ import com.navercorp.pinpoint.profiler.context.Span; import com.navercorp.pinpoint.profiler.context.SpanEvent; import com.navercorp.pinpoint.profiler.context.grpc.GrpcSpanMessageConverter; +import com.navercorp.pinpoint.profiler.context.grpc.config.SpanAutoUriGetter; import com.navercorp.pinpoint.profiler.context.id.DefaultTraceId; import com.navercorp.pinpoint.profiler.context.id.TraceRoot; import org.junit.jupiter.api.Assertions; @@ -37,7 +38,7 @@ public class GrpcSpanProcessorV2Test { private SpanProcessor spanProcessorProtoV2 = new GrpcSpanProcessorV2(); - private GrpcSpanMessageConverter converter = new GrpcSpanMessageConverter("agentId", (short) 1, spanProcessorProtoV2, "TEMPLATE"); + private GrpcSpanMessageConverter converter = new GrpcSpanMessageConverter("agentId", (short) 1, spanProcessorProtoV2, new SpanAutoUriGetter()); @Test public void preProcess() {