3030
3131package com .google .showcase .v1beta1 .it ;
3232
33+ import static com .google .common .truth .Truth .assertThat ;
34+ import static java .nio .charset .StandardCharsets .UTF_8 ;
35+ import static org .junit .Assert .assertThrows ;
36+
3337import com .google .api .client .http .HttpTransport ;
3438import com .google .api .gax .core .NoCredentialsProvider ;
3539import com .google .api .gax .retrying .RetrySettings ;
3640import com .google .api .gax .rpc .StatusCode ;
3741import com .google .api .gax .rpc .TransportChannelProvider ;
3842import com .google .api .gax .rpc .UnavailableException ;
39- import com .google .api .gax .tracing .OpenTelemetryMetricsFactory ;
4043import com .google .api .gax .tracing .ObservabilityAttributes ;
44+ import com .google .api .gax .tracing .OpenTelemetryMetricsFactory ;
4145import com .google .common .collect .ImmutableList ;
4246import com .google .showcase .v1beta1 .EchoClient ;
4347import com .google .showcase .v1beta1 .EchoRequest ;
5559import io .opentelemetry .sdk .metrics .SdkMeterProvider ;
5660import io .opentelemetry .sdk .metrics .data .MetricData ;
5761import io .opentelemetry .sdk .testing .exporter .InMemoryMetricReader ;
58- import org .junit .jupiter .api .AfterEach ;
59- import org .junit .jupiter .api .BeforeEach ;
60- import org .junit .jupiter .api .Test ;
61-
6262import java .io .ByteArrayInputStream ;
6363import java .io .InputStream ;
6464import java .time .Duration ;
6565import java .util .Collection ;
66-
67- import static com .google .common .truth .Truth .assertThat ;
68- import static java .nio .charset .StandardCharsets .UTF_8 ;
69- import static org .junit .Assert .assertThrows ;
66+ import org .junit .jupiter .api .AfterEach ;
67+ import org .junit .jupiter .api .BeforeEach ;
68+ import org .junit .jupiter .api .Test ;
7069
7170class ITOtelGoldenMetrics {
7271 private static final String SHOWCASE_SERVER_ADDRESS = "localhost" ;
@@ -95,8 +94,7 @@ void tearDown() {
9594
9695 @ Test
9796 void testMetrics_successfulEcho_grpc () throws Exception {
98- OpenTelemetryMetricsFactory tracerFactory =
99- new OpenTelemetryMetricsFactory (openTelemetrySdk );
97+ OpenTelemetryMetricsFactory tracerFactory = new OpenTelemetryMetricsFactory (openTelemetrySdk );
10098
10199 try (EchoClient client =
102100 TestClientInitializer .createGrpcEchoClientOpentelemetry (tracerFactory )) {
@@ -152,8 +150,7 @@ void testMetrics_successfulEcho_grpc() throws Exception {
152150
153151 @ Test
154152 void testMetrics_failedEcho_grpc_recordsErrorType () throws Exception {
155- OpenTelemetryMetricsFactory tracerFactory =
156- new OpenTelemetryMetricsFactory (openTelemetrySdk );
153+ OpenTelemetryMetricsFactory tracerFactory = new OpenTelemetryMetricsFactory (openTelemetrySdk );
157154
158155 ClientInterceptor interceptor =
159156 new ClientInterceptor () {
@@ -220,8 +217,7 @@ public void sendMessage(ReqT message) {}
220217
221218 @ Test
222219 void testMetrics_successfulEcho_httpjson () throws Exception {
223- OpenTelemetryMetricsFactory tracerFactory =
224- new OpenTelemetryMetricsFactory (openTelemetrySdk );
220+ OpenTelemetryMetricsFactory tracerFactory = new OpenTelemetryMetricsFactory (openTelemetrySdk );
225221
226222 try (EchoClient client =
227223 TestClientInitializer .createHttpJsonEchoClientOpentelemetry (tracerFactory )) {
@@ -280,8 +276,7 @@ void testMetrics_successfulEcho_httpjson() throws Exception {
280276
281277 @ Test
282278 void testMetrics_failedEcho_httpjson_recordsErrorType () throws Exception {
283- OpenTelemetryMetricsFactory tracerFactory =
284- new OpenTelemetryMetricsFactory (openTelemetrySdk );
279+ OpenTelemetryMetricsFactory tracerFactory = new OpenTelemetryMetricsFactory (openTelemetrySdk );
285280
286281 HttpTransport mockTransport =
287282 new HttpTransport () {
@@ -400,8 +395,7 @@ public String getHeaderValue(int index) {
400395
401396 @ Test
402397 void testMetrics_clientTimeout_grpc () throws Exception {
403- OpenTelemetryMetricsFactory tracerFactory =
404- new OpenTelemetryMetricsFactory (openTelemetrySdk );
398+ OpenTelemetryMetricsFactory tracerFactory = new OpenTelemetryMetricsFactory (openTelemetrySdk );
405399
406400 // Using 1ms as 0ms might be rejected by some validation or trigger immediate failure before
407401 // metrics
@@ -446,8 +440,7 @@ void testMetrics_clientTimeout_grpc() throws Exception {
446440
447441 @ Test
448442 void testMetrics_clientTimeout_httpjson () throws Exception {
449- OpenTelemetryMetricsFactory tracerFactory =
450- new OpenTelemetryMetricsFactory (openTelemetrySdk );
443+ OpenTelemetryMetricsFactory tracerFactory = new OpenTelemetryMetricsFactory (openTelemetrySdk );
451444
452445 RetrySettings zeroRetrySettings =
453446 RetrySettings .newBuilder ()
@@ -490,8 +483,7 @@ void testMetrics_clientTimeout_httpjson() throws Exception {
490483
491484 @ Test
492485 void testMetrics_retryShouldResultInOneMetric_grpc () throws Exception {
493- OpenTelemetryMetricsFactory tracerFactory =
494- new OpenTelemetryMetricsFactory (openTelemetrySdk );
486+ OpenTelemetryMetricsFactory tracerFactory = new OpenTelemetryMetricsFactory (openTelemetrySdk );
495487
496488 RetrySettings retrySettings =
497489 RetrySettings .newBuilder ()
@@ -501,7 +493,8 @@ void testMetrics_retryShouldResultInOneMetric_grpc() throws Exception {
501493 .setMaxAttempts (3 )
502494 .build ();
503495
504- java .util .concurrent .atomic .AtomicInteger attemptCount = new java .util .concurrent .atomic .AtomicInteger (0 );
496+ java .util .concurrent .atomic .AtomicInteger attemptCount =
497+ new java .util .concurrent .atomic .AtomicInteger (0 );
505498
506499 ClientInterceptor interceptor =
507500 new ClientInterceptor () {
@@ -534,7 +527,8 @@ public void sendMessage(ReqT message) {}
534527 }
535528 };
536529
537- java .util .Set <StatusCode .Code > retryableCodes = java .util .Collections .singleton (StatusCode .Code .UNAVAILABLE );
530+ java .util .Set <StatusCode .Code > retryableCodes =
531+ java .util .Collections .singleton (StatusCode .Code .UNAVAILABLE );
538532
539533 try (EchoClient client =
540534 TestClientInitializer .createGrpcEchoClientOpentelemetry (
@@ -568,8 +562,7 @@ public void sendMessage(ReqT message) {}
568562
569563 @ Test
570564 void testMetrics_retryShouldResultInOneMetric_httpjson () throws Exception {
571- OpenTelemetryMetricsFactory tracerFactory =
572- new OpenTelemetryMetricsFactory (openTelemetrySdk );
565+ OpenTelemetryMetricsFactory tracerFactory = new OpenTelemetryMetricsFactory (openTelemetrySdk );
573566
574567 RetrySettings retrySettings =
575568 RetrySettings .newBuilder ()
@@ -579,7 +572,8 @@ void testMetrics_retryShouldResultInOneMetric_httpjson() throws Exception {
579572 .setMaxAttempts (3 )
580573 .build ();
581574
582- java .util .concurrent .atomic .AtomicInteger requestCount = new java .util .concurrent .atomic .AtomicInteger (0 );
575+ java .util .concurrent .atomic .AtomicInteger requestCount =
576+ new java .util .concurrent .atomic .AtomicInteger (0 );
583577
584578 HttpTransport mockTransport =
585579 new HttpTransport () {
@@ -601,73 +595,111 @@ public InputStream getContent() {
601595 }
602596
603597 @ Override
604- public String getContentEncoding () { return null ; }
598+ public String getContentEncoding () {
599+ return null ;
600+ }
605601
606602 @ Override
607- public long getContentLength () { return 2 ; }
603+ public long getContentLength () {
604+ return 2 ;
605+ }
608606
609607 @ Override
610- public String getContentType () { return "application/json" ; }
608+ public String getContentType () {
609+ return "application/json" ;
610+ }
611611
612612 @ Override
613- public String getStatusLine () { return "HTTP/1.1 503 Service Unavailable" ; }
613+ public String getStatusLine () {
614+ return "HTTP/1.1 503 Service Unavailable" ;
615+ }
614616
615617 @ Override
616- public int getStatusCode () { return 503 ; }
618+ public int getStatusCode () {
619+ return 503 ;
620+ }
617621
618622 @ Override
619- public String getReasonPhrase () { return "Service Unavailable" ; }
623+ public String getReasonPhrase () {
624+ return "Service Unavailable" ;
625+ }
620626
621627 @ Override
622- public int getHeaderCount () { return 0 ; }
628+ public int getHeaderCount () {
629+ return 0 ;
630+ }
623631
624632 @ Override
625- public String getHeaderName (int index ) { return null ; }
633+ public String getHeaderName (int index ) {
634+ return null ;
635+ }
626636
627637 @ Override
628- public String getHeaderValue (int index ) { return null ; }
638+ public String getHeaderValue (int index ) {
639+ return null ;
640+ }
629641 };
630642 } else {
631643 return new com .google .api .client .http .LowLevelHttpResponse () {
632644 @ Override
633645 public InputStream getContent () {
634- return new ByteArrayInputStream ("{\" content\" :\" metrics-test\" }" .getBytes (UTF_8 ));
646+ return new ByteArrayInputStream (
647+ "{\" content\" :\" metrics-test\" }" .getBytes (UTF_8 ));
635648 }
636649
637650 @ Override
638- public String getContentEncoding () { return null ; }
651+ public String getContentEncoding () {
652+ return null ;
653+ }
639654
640655 @ Override
641- public long getContentLength () { return 24 ; }
656+ public long getContentLength () {
657+ return 24 ;
658+ }
642659
643660 @ Override
644- public String getContentType () { return "application/json" ; }
661+ public String getContentType () {
662+ return "application/json" ;
663+ }
645664
646665 @ Override
647- public String getStatusLine () { return "HTTP/1.1 200 OK" ; }
666+ public String getStatusLine () {
667+ return "HTTP/1.1 200 OK" ;
668+ }
648669
649670 @ Override
650- public int getStatusCode () { return 200 ; }
671+ public int getStatusCode () {
672+ return 200 ;
673+ }
651674
652675 @ Override
653- public String getReasonPhrase () { return "OK" ; }
676+ public String getReasonPhrase () {
677+ return "OK" ;
678+ }
654679
655680 @ Override
656- public int getHeaderCount () { return 0 ; }
681+ public int getHeaderCount () {
682+ return 0 ;
683+ }
657684
658685 @ Override
659- public String getHeaderName (int index ) { return null ; }
686+ public String getHeaderName (int index ) {
687+ return null ;
688+ }
660689
661690 @ Override
662- public String getHeaderValue (int index ) { return null ; }
691+ public String getHeaderValue (int index ) {
692+ return null ;
693+ }
663694 };
664695 }
665696 }
666697 };
667698 }
668699 };
669700
670- java .util .Set <StatusCode .Code > retryableCodes = java .util .Collections .singleton (StatusCode .Code .UNAVAILABLE );
701+ java .util .Set <StatusCode .Code > retryableCodes =
702+ java .util .Collections .singleton (StatusCode .Code .UNAVAILABLE );
671703
672704 try (EchoClient client =
673705 TestClientInitializer .createHttpJsonEchoClientOpentelemetry (
0 commit comments