2929import io .opentelemetry .sdk .metrics .data .MetricData ;
3030import io .opentelemetry .sdk .metrics .data .PointData ;
3131import io .opentelemetry .sdk .testing .exporter .InMemoryMetricReader ;
32+ import java .util .Arrays ;
3233import java .util .Collection ;
3334import java .util .Optional ;
3435import org .junit .After ;
3536import org .junit .Before ;
3637import org .junit .Test ;
3738import org .junit .runner .RunWith ;
38- import org .junit .runners .JUnit4 ;
39+ import org .junit .runners .Parameterized ;
3940
4041/**
4142 * Integration test that verifies both the default built-in Cloud Monitoring export path and a
8283 *
8384 * <p>Data may take up to 60 seconds (one periodic flush interval) to appear.
8485 */
85- @ RunWith (JUnit4 .class )
86+ @ RunWith (Parameterized .class )
8687@ SuppressWarnings ("checkstyle:abbreviationaswordinname" )
8788public class ITDatastoreBuiltInAndCustomMetrics {
8889
8990 private static final String PROJECT_ID = System .getenv ("GOOGLE_CLOUD_PROJECT" );
9091 private static final String DATABASE_ID =
9192 System .getenv ().getOrDefault ("DATASTORE_DATABASE_ID" , "" );
9293
94+ private final boolean useGrpc ;
95+
96+ public ITDatastoreBuiltInAndCustomMetrics (boolean useGrpc ) {
97+ this .useGrpc = useGrpc ;
98+ }
99+
100+ @ Parameterized .Parameters (name = "useGrpc: {0}" )
101+ public static Iterable <Object []> data () {
102+ return Arrays .asList (new Object [][] {{true }, {false }});
103+ }
104+
93105 /**
94106 * Delta temporality is used so that each {@link InMemoryMetricReader#collectAllMetrics()} call
95107 * returns only the new data points recorded since the last collection, and automatically resets
@@ -122,7 +134,7 @@ public void setUp() {
122134 //
123135 // The resulting DatastoreMetricsRecorder will be a CompositeDatastoreMetricsRecorder that
124136 // fans out all recording calls to both backends simultaneously.
125- DatastoreOptions options =
137+ DatastoreOptions . Builder builder =
126138 DatastoreOptions .newBuilder ()
127139 .setProjectId (PROJECT_ID )
128140 .setDatabaseId (DATABASE_ID )
@@ -131,9 +143,15 @@ public void setUp() {
131143 .setMetricsEnabled (true )
132144 .setOpenTelemetry (customOtel )
133145 .setExportBuiltinMetricsToGoogleCloudMonitoring (true )
134- .build ())
135- .build ();
136- datastore = options .getService ();
146+ .build ());
147+
148+ if (useGrpc ) {
149+ builder .setTransportOptions (DatastoreOptions .getDefaultGrpcTransportOptions ());
150+ } else {
151+ builder .setTransportOptions (DatastoreOptions .getDefaultHttpTransportOptions ());
152+ }
153+
154+ datastore = builder .build ().getService ();
137155
138156 // Drain any metrics emitted during client initialisation so test assertions only capture
139157 // data from the operations performed within the test method itself.
0 commit comments