未验证 提交 f8c887e2 编写于 作者: B Brandon Fergerson 提交者: GitHub

Include request method type in rest mapping annotations (#5085)

上级 4f1dab70
......@@ -147,7 +147,7 @@ public class RestMappingMethodInterceptorTest {
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0), "/getRequestURL");
assertHttpSpan(spans.get(0), "{GET}", "/getRequestURL");
}
@Test
......@@ -173,7 +173,7 @@ public class RestMappingMethodInterceptorTest {
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0), "/postRequestURL");
assertHttpSpan(spans.get(0), "{POST}", "/postRequestURL");
}
@Test
......@@ -199,7 +199,7 @@ public class RestMappingMethodInterceptorTest {
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0), "/putRequestURL");
assertHttpSpan(spans.get(0), "{PUT}", "/putRequestURL");
}
@Test
......@@ -226,7 +226,7 @@ public class RestMappingMethodInterceptorTest {
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0), "/deleteRequestURL");
assertHttpSpan(spans.get(0), "{DELETE}", "/deleteRequestURL");
}
@Test
......@@ -252,7 +252,7 @@ public class RestMappingMethodInterceptorTest {
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0), "/patchRequestURL");
assertHttpSpan(spans.get(0), "{PATCH}", "/patchRequestURL");
}
@Test
......@@ -278,7 +278,7 @@ public class RestMappingMethodInterceptorTest {
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0), "");
assertHttpSpan(spans.get(0), "", "");
}
@Test
......@@ -304,7 +304,7 @@ public class RestMappingMethodInterceptorTest {
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0), "/getRequestURL");
assertHttpSpan(spans.get(0), "{GET}", "/getRequestURL");
List<LogDataEntity> logDataEntities = SpanHelper.getLogs(spans.get(0));
assertThat(logDataEntities.size(), is(1));
SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class);
......@@ -335,7 +335,7 @@ public class RestMappingMethodInterceptorTest {
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0), "/getRequestURL");
assertHttpSpan(spans.get(0), "{GET}", "/getRequestURL");
SpanAssert.assertTag(spans.get(0), 2, "connection=[keep-alive]");
}
......@@ -345,8 +345,8 @@ public class RestMappingMethodInterceptorTest {
MatcherAssert.assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.444.555"));
}
private void assertHttpSpan(AbstractTracingSpan span, String suffix) {
assertThat(span.getOperationName(), is("/test" + suffix));
private void assertHttpSpan(AbstractTracingSpan span, String prefix, String suffix) {
assertThat(span.getOperationName(), is(prefix + "/test" + suffix));
SpanAssert.assertComponent(span, ComponentsDefine.SPRING_MVC_ANNOTATION);
SpanAssert.assertTag(span, 0, "http://localhost:8080/test" + suffix);
assertThat(span.isEntry(), is(true));
......
......@@ -80,6 +80,20 @@ public class RestMappingMethodInterceptor extends AbstractMethodInterceptor {
@Override
public String getAcceptedMethodTypes(Method method) {
return "";
return ParsePathUtil.recursiveParseMethodAnnotation(method, m -> {
if (AnnotationUtils.getAnnotation(m, GetMapping.class) != null) {
return "{GET}";
} else if (AnnotationUtils.getAnnotation(m, PostMapping.class) != null) {
return "{POST}";
} else if (AnnotationUtils.getAnnotation(m, PutMapping.class) != null) {
return "{PUT}";
} else if (AnnotationUtils.getAnnotation(m, DeleteMapping.class) != null) {
return "{DELETE}";
} else if (AnnotationUtils.getAnnotation(m, PatchMapping.class) != null) {
return "{PATCH}";
} else {
return null;
}
});
}
}
......@@ -141,9 +141,8 @@ public class KafkaProfileE2E extends SkyWalkingTestAdapter {
@Order(3)
void createProfileTask() throws Exception {
final ProfileTaskCreationRequest creationRequest = ProfileTaskCreationRequest.builder()
.serviceId(
"ZTJlLXByb2ZpbGUtc2VydmljZQ==.1")
.endpointName("/profile/{name}")
.serviceId("ZTJlLXByb2ZpbGUtc2VydmljZQ==.1")
.endpointName("{POST}/profile/{name}")
.duration(1)
.startTime(-1)
.minDurationThreshold(1500)
......
......@@ -141,7 +141,7 @@ public class ProfileE2E extends SkyWalkingTestAdapter {
void createProfileTask() throws Exception {
final ProfileTaskCreationRequest creationRequest = ProfileTaskCreationRequest.builder()
.serviceId("ZTJlLXByb2ZpbGUtc2VydmljZQ==.1")
.endpointName("/profile/{name}")
.endpointName("{POST}/profile/{name}")
.duration(1)
.startTime(-1)
.minDurationThreshold(1500)
......
......@@ -14,5 +14,5 @@
# limitations under the License.
endpoints:
- key: ZTJlLXByb2ZpbGUtc2VydmljZQ==.1_L3Byb2ZpbGUve25hbWV9
label: /profile/{name}
- key: ZTJlLXByb2ZpbGUtc2VydmljZQ==.1_e1BPU1R9L3Byb2ZpbGUve25hbWV9
label: '{POST}/profile/{name}'
......@@ -16,7 +16,7 @@
tasks:
- id: not null
serviceId: ZTJlLXByb2ZpbGUtc2VydmljZQ==.1
endpointName: /profile/{name}
endpointName: '{POST}/profile/{name}'
startTime: gt 0
duration: gt 0
minDurationThreshold: gt 0
......
......@@ -16,7 +16,7 @@
tasks:
- id: not null
serviceId: ZTJlLXByb2ZpbGUtc2VydmljZQ==.1
endpointName: /profile/{name}
endpointName: '{POST}/profile/{name}'
startTime: gt 0
duration: gt 0
minDurationThreshold: gt 0
......
......@@ -19,7 +19,7 @@ spans:
serviceCode: not null
startTime: gt 0
endTime: gt 0
endpointName: /profile/{name}
endpointName: '{POST}/profile/{name}'
tags:
- key: url
value: not null
......
......@@ -16,7 +16,7 @@
traces:
- key: not null
endpointNames:
- /profile/{name}
- '{POST}/profile/{name}'
duration: ge 0
start: gt 0
isError: false
......
......@@ -139,7 +139,7 @@ segmentItems:
- {key: es.indices, value: ''}
- {key: es.types, value: ''}
skipAnalysis: 'false'
- operationName: /case/elasticsearch
- operationName: '{GET}/case/elasticsearch'
operationId: 0
parentSpanId: -1
spanId: 0
......
......@@ -19,7 +19,7 @@ segmentItems:
segments:
- segmentId: not null
spans:
- operationName: /greet/{username}
- operationName: '{GET}/greet/{username}'
operationId: 0
parentSpanId: -1
spanId: 0
......@@ -63,7 +63,7 @@ segmentItems:
spanType: Local
peer: ''
refs:
- {parentEndpoint: '/greet/{username}', networkAddress: '', refType: CrossThread,
- {parentEndpoint: '{GET}/greet/{username}', networkAddress: '', refType: CrossThread,
parentSpanId: 0, parentTraceSegmentId: not null, parentServiceInstance: not
null, parentService: jdk-threading-scenario, traceId: not null}
skipAnalysis: 'false'
......@@ -96,7 +96,7 @@ segmentItems:
spanType: Local
peer: ''
refs:
- {parentEndpoint: '/greet/{username}', networkAddress: '', refType: CrossThread,
- {parentEndpoint: '{GET}/greet/{username}', networkAddress: '', refType: CrossThread,
parentSpanId: 0, parentTraceSegmentId: not null, parentServiceInstance: not
null, parentService: jdk-threading-scenario, traceId: not null}
skipAnalysis: 'false'
......@@ -70,7 +70,7 @@ segmentItems:
skipAnalysis: 'false'
- segmentId: not null
spans:
- operationName: /create/
- operationName: '{POST}/create/'
operationId: 0
parentSpanId: -1
spanId: 0
......@@ -91,7 +91,7 @@ segmentItems:
skipAnalysis: 'false'
- segmentId: not null
spans:
- operationName: /get/{id}
- operationName: '{GET}/get/{id}'
operationId: 0
parentSpanId: -1
spanId: 0
......@@ -112,7 +112,7 @@ segmentItems:
skipAnalysis: 'false'
- segmentId: not null
spans:
- operationName: /update/{id}
- operationName: '{PUT}/update/{id}'
operationId: 0
parentSpanId: -1
spanId: 0
......@@ -133,7 +133,7 @@ segmentItems:
skipAnalysis: 'false'
- segmentId: not null
spans:
- operationName: /delete/{id}
- operationName: '{DELETE}/delete/{id}'
operationId: 0
parentSpanId: -1
spanId: 0
......@@ -196,7 +196,7 @@ segmentItems:
skipAnalysis: 'false'
- segmentId: not null
spans:
- operationName: /impl/restmapping
- operationName: '{GET}/impl/restmapping'
operationId: 0
parentSpanId: -1
spanId: 0
......
......@@ -36,7 +36,7 @@ segmentItems:
- {key: db.instance, value: test}
- {key: db.statement, value: not null}
skipAnalysis: 'false'
- operationName: /testcase/{test}
- operationName: '{GET}/testcase/{test}'
operationId: 0
parentSpanId: -1
spanId: 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册