1717 */
1818package org .apache .hadoop .hbase .ipc ;
1919
20- import static org .apache .hadoop .hbase .ipc .TestProtobufRpcServiceImpl .SERVICE ;
21- import static org .apache .hadoop .hbase .ipc .TestProtobufRpcServiceImpl .newBlockingStub ;
22- import static org .apache .hadoop .hbase .ipc .TestProtobufRpcServiceImpl .newStub ;
2320import static org .apache .hadoop .hbase .client .trace .hamcrest .AttributesMatchers .containsEntry ;
2421import static org .apache .hadoop .hbase .client .trace .hamcrest .SpanDataMatchers .hasAttributes ;
2522import static org .apache .hadoop .hbase .client .trace .hamcrest .SpanDataMatchers .hasDuration ;
2623import static org .apache .hadoop .hbase .client .trace .hamcrest .SpanDataMatchers .hasKind ;
2724import static org .apache .hadoop .hbase .client .trace .hamcrest .SpanDataMatchers .hasName ;
2825import static org .apache .hadoop .hbase .client .trace .hamcrest .SpanDataMatchers .hasStatusWithCode ;
2926import static org .apache .hadoop .hbase .client .trace .hamcrest .SpanDataMatchers .hasTraceId ;
27+ import static org .apache .hadoop .hbase .ipc .TestProtobufRpcServiceImpl .SERVICE ;
28+ import static org .apache .hadoop .hbase .ipc .TestProtobufRpcServiceImpl .newBlockingStub ;
29+ import static org .apache .hadoop .hbase .ipc .TestProtobufRpcServiceImpl .newStub ;
3030import static org .hamcrest .MatcherAssert .assertThat ;
3131import static org .hamcrest .Matchers .allOf ;
3232import static org .hamcrest .Matchers .everyItem ;
4343import static org .mockito .Mockito .spy ;
4444import static org .mockito .Mockito .verify ;
4545import static org .mockito .internal .verification .VerificationModeFactory .times ;
46-
4746import io .opentelemetry .api .common .AttributeKey ;
4847import io .opentelemetry .api .trace .SpanKind ;
4948import io .opentelemetry .api .trace .StatusCode ;
6867import org .apache .hadoop .hbase .util .Bytes ;
6968import org .apache .hadoop .io .compress .GzipCodec ;
7069import org .apache .hadoop .util .StringUtils ;
71- import org .apache .hbase .thirdparty .com .google .protobuf .Descriptors ;
7270import org .hamcrest .Matcher ;
7371import org .junit .Rule ;
7472import org .junit .Test ;
7573import org .slf4j .Logger ;
7674import org .slf4j .LoggerFactory ;
77-
7875import org .apache .hbase .thirdparty .com .google .common .collect .ImmutableList ;
7976import org .apache .hbase .thirdparty .com .google .common .collect .Lists ;
8077import org .apache .hbase .thirdparty .com .google .protobuf .ServiceException ;
81-
8278import org .apache .hadoop .hbase .shaded .ipc .protobuf .generated .TestProtos .EchoRequestProto ;
8379import org .apache .hadoop .hbase .shaded .ipc .protobuf .generated .TestProtos .EchoResponseProto ;
8480import org .apache .hadoop .hbase .shaded .ipc .protobuf .generated .TestProtos .EmptyRequestProto ;
@@ -465,49 +461,51 @@ private SpanData waitSpan(Matcher<SpanData> matcher) {
465461 .orElseThrow (AssertionError ::new );
466462 }
467463
468- private static String buildIpcSpanName (Descriptors .MethodDescriptor md ) {
469- final String packageAndService = md .getService ().getFullName ();
470- final String method = md .getName ();
471- return packageAndService + "/" + method ;
464+ private static String buildIpcSpanName (final String packageAndService , final String methodName ) {
465+ return packageAndService + "/" + methodName ;
472466 }
473467
474- private static Matcher <SpanData > buildIpcClientSpanMatcher (Descriptors .MethodDescriptor md ) {
468+ private static Matcher <SpanData > buildIpcClientSpanMatcher (
469+ final String packageAndService ,
470+ final String methodName
471+ ) {
475472 return allOf (
476- hasName (buildIpcSpanName (md )),
473+ hasName (buildIpcSpanName (packageAndService , methodName )),
477474 hasKind (SpanKind .CLIENT )
478475 );
479476 }
480477
481- private static Matcher <SpanData > buildIpcServerSpanMatcher (Descriptors .MethodDescriptor md ) {
478+ private static Matcher <SpanData > buildIpcServerSpanMatcher (
479+ final String packageAndService ,
480+ final String methodName
481+ ) {
482482 return allOf (
483- hasName (buildIpcSpanName (md )),
483+ hasName (buildIpcSpanName (packageAndService , methodName )),
484484 hasKind (SpanKind .SERVER )
485485 );
486486 }
487487
488488 private static Matcher <SpanData > buildIpcClientSpanAttributesMatcher (
489- Descriptors .MethodDescriptor md ,
490- InetSocketAddress isa
489+ final String packageAndService ,
490+ final String methodName ,
491+ final InetSocketAddress isa
491492 ) {
492- final String packageAndService = md .getService ().getFullName ();
493- final String method = md .getName ();
494493 return hasAttributes (allOf (
495494 containsEntry ("rpc.system" , "HBASE_RPC" ),
496495 containsEntry ("rpc.service" , packageAndService ),
497- containsEntry ("rpc.method" , method ),
496+ containsEntry ("rpc.method" , methodName ),
498497 containsEntry ("net.peer.name" , isa .getHostName ()),
499498 containsEntry (AttributeKey .longKey ("net.peer.port" ), (long ) isa .getPort ())));
500499 }
501500
502501 private static Matcher <SpanData > buildIpcServerSpanAttributesMatcher (
503- Descriptors .MethodDescriptor md
502+ final String packageAndService ,
503+ final String methodName
504504 ) {
505- final String packageAndService = md .getService ().getFullName ();
506- final String method = md .getName ();
507505 return hasAttributes (allOf (
508506 containsEntry ("rpc.system" , "HBASE_RPC" ),
509507 containsEntry ("rpc.service" , packageAndService ),
510- containsEntry ("rpc.method" , method )));
508+ containsEntry ("rpc.method" , methodName )));
511509 }
512510
513511 private void assertRemoteSpan () {
@@ -528,12 +526,14 @@ public void testTracingSuccessIpc() throws IOException, ServiceException {
528526 stub .pause (null , PauseRequestProto .newBuilder ().setMs (100 ).build ());
529527 // use the ISA from the running server so that we can get the port selected.
530528 final InetSocketAddress isa = rpcServer .getListenerAddress ();
531- final Descriptors .MethodDescriptor pauseMd =
532- SERVICE .getDescriptorForType ().findMethodByName ("pause" );
533- final SpanData pauseClientSpan = waitSpan (buildIpcClientSpanMatcher (pauseMd ));
534- assertThat (pauseClientSpan , buildIpcClientSpanAttributesMatcher (pauseMd , isa ));
535- final SpanData pauseServerSpan = waitSpan (buildIpcServerSpanMatcher (pauseMd ));
536- assertThat (pauseServerSpan , buildIpcServerSpanAttributesMatcher (pauseMd ));
529+ final SpanData pauseClientSpan = waitSpan (buildIpcClientSpanMatcher (
530+ "hbase.test.pb.TestProtobufRpcProto" , "pause" ));
531+ assertThat (pauseClientSpan , buildIpcClientSpanAttributesMatcher (
532+ "hbase.test.pb.TestProtobufRpcProto" , "pause" , isa ));
533+ final SpanData pauseServerSpan = waitSpan (buildIpcServerSpanMatcher (
534+ "hbase.test.pb.TestProtobufRpcProto" , "pause" ));
535+ assertThat (pauseServerSpan , buildIpcServerSpanAttributesMatcher (
536+ "hbase.test.pb.TestProtobufRpcProto" , "pause" ));
537537 assertRemoteSpan ();
538538 assertFalse ("no spans provided" , traceRule .getSpans ().isEmpty ());
539539 assertThat (traceRule .getSpans (), everyItem (allOf (
@@ -556,12 +556,14 @@ public void testTracingErrorIpc() throws IOException {
556556 assertThrows (ServiceException .class ,
557557 () -> stub .error (null , EmptyRequestProto .getDefaultInstance ()));
558558 final InetSocketAddress isa = rpcServer .getListenerAddress ();
559- final Descriptors .MethodDescriptor errorMd =
560- SERVICE .getDescriptorForType ().findMethodByName ("error" );
561- final SpanData errorClientSpan = waitSpan (buildIpcClientSpanMatcher (errorMd ));
562- assertThat (errorClientSpan , buildIpcClientSpanAttributesMatcher (errorMd , isa ));
563- final SpanData errorServerSpan = waitSpan (buildIpcServerSpanMatcher (errorMd ));
564- assertThat (errorServerSpan , buildIpcServerSpanAttributesMatcher (errorMd ));
559+ final SpanData errorClientSpan = waitSpan (buildIpcClientSpanMatcher (
560+ "hbase.test.pb.TestProtobufRpcProto" , "error" ));
561+ assertThat (errorClientSpan , buildIpcClientSpanAttributesMatcher (
562+ "hbase.test.pb.TestProtobufRpcProto" , "error" , isa ));
563+ final SpanData errorServerSpan = waitSpan (buildIpcServerSpanMatcher (
564+ "hbase.test.pb.TestProtobufRpcProto" , "error" ));
565+ assertThat (errorServerSpan , buildIpcServerSpanAttributesMatcher (
566+ "hbase.test.pb.TestProtobufRpcProto" , "error" ));
565567 assertRemoteSpan ();
566568 assertFalse ("no spans provided" , traceRule .getSpans ().isEmpty ());
567569 assertThat (traceRule .getSpans (), everyItem (allOf (
0 commit comments