Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#10041] Add auto option to profiler.span.collected.uri #10044

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions agent/src/main/resources/pinpoint-root.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,19 +81,15 @@ public class GrpcSpanMessageConverter implements MessageConverter<SpanType, Gene

private final PAnnotation.Builder pAnnotationBuilder = PAnnotation.newBuilder();

public enum SpanUriType {
TEMPLATE, RAW
}

private final SpanUriType spanCollectedUriType;
private final SpanUriGetter spanUriGetter;

public GrpcSpanMessageConverter(String agentId, short applicationServiceType,
SpanProcessor<PSpan.Builder, PSpanChunk.Builder> 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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -42,7 +46,12 @@ public class GrpcSpanMessageConverterProvider implements Provider<MessageConvert

private final SpanProcessor<PSpan.Builder, PSpanChunk.Builder> spanPostProcessor;

private final String spanCollectedUriType;
public enum SpanUriType {
TEMPLATE, RAW, AUTO
}

private final SpanUriGetter spanUriGetter;


@Inject
public GrpcSpanMessageConverterProvider(@AgentId String agentId, @ApplicationServerType ServiceType applicationServiceType,
Expand All @@ -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<SpanType, GeneratedMessageV3> 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +38,7 @@ public class GrpcSpanProcessorV2Test {

private SpanProcessor<PSpan.Builder, PSpanChunk.Builder> 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() {
Expand Down