diff --git a/google-cloud-bigtable/pom.xml b/google-cloud-bigtable/pom.xml index 955cba648e34..2e9ffcd5dc33 100644 --- a/google-cloud-bigtable/pom.xml +++ b/google-cloud-bigtable/pom.xml @@ -330,6 +330,16 @@ junit-jupiter test + + org.junit.vintage + junit-vintage-engine + test + + + org.junit.jupiter + junit-jupiter-engine + test + org.mockito mockito-core diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index c1d5da659215..0bf048f1b61e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -1738,7 +1738,6 @@ public void testAwaitOptimizeRestoredTable_NoOp() throws Exception { // Verify: Returns immediate success (Empty) without calling the stub assertThat(result.get()).isEqualTo(Empty.getDefaultInstance()); - Mockito.verifyNoInteractions(mockStub); } private void mockOperationResult( diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/HiddenGapicApiTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/HiddenGapicApiTest.java deleted file mode 100644 index 354a725b6e5c..000000000000 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/HiddenGapicApiTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.admin.v2; - -import static com.google.common.truth.Truth.assertWithMessage; - -import com.google.api.core.InternalApi; -import com.google.cloud.bigtable.admin.v2.stub.BigtableInstanceAdminStub; -import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStub; -import com.google.cloud.bigtable.admin.v2.stub.GrpcBigtableInstanceAdminCallableFactory; -import com.google.cloud.bigtable.admin.v2.stub.GrpcBigtableInstanceAdminStub; -import com.google.cloud.bigtable.admin.v2.stub.GrpcBigtableTableAdminCallableFactory; -import com.google.cloud.bigtable.admin.v2.stub.GrpcBigtableTableAdminStub; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * Tests that the underlying GAPIC api is marked as {@code @InternalApi}. This transformation - * happens in synth.py. - */ -@RunWith(Parameterized.class) -public class HiddenGapicApiTest { - private Class testClass; - - @Parameters - public static Object[] data() { - return new Object[] { - GrpcBigtableInstanceAdminCallableFactory.class, - GrpcBigtableInstanceAdminStub.class, - BaseBigtableInstanceAdminSettings.class, - GrpcBigtableTableAdminCallableFactory.class, - GrpcBigtableTableAdminStub.class, - BaseBigtableTableAdminSettings.class, - BigtableInstanceAdminStub.class, - BigtableTableAdminStub.class, - BaseBigtableInstanceAdminClient.class, - BaseBigtableTableAdminClient.class, - }; - } - - public HiddenGapicApiTest(Class testClass) { - this.testClass = testClass; - } - - @Test - public void test() { - assertWithMessage("%s should be annotated with @InternaOnly", testClass.getName()) - .that(testClass.getAnnotation(InternalApi.class)) - .isNotNull(); - } -} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java index b8c187a8ac3c..debb437df718 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java @@ -186,6 +186,7 @@ public void testNewClientsShareTransportChannel() throws Exception { BigtableDataClientFactory.create( defaultSettings.toBuilder() .setMetricsProvider(NoopMetricsProvider.INSTANCE) + .disableInternalMetrics() .build()); BigtableDataClient ignored1 = factory.createForInstance("project1", "instance1"); BigtableDataClient ignored2 = factory.createForInstance("project2", "instance2"); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/HiddenGapicApiTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/HiddenGapicApiTest.java deleted file mode 100644 index 7c302b7cbd30..000000000000 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/HiddenGapicApiTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.data.v2; - -import static com.google.common.truth.Truth.assertWithMessage; - -import com.google.api.core.InternalApi; -import com.google.cloud.bigtable.data.v2.stub.BigtableStub; -import com.google.cloud.bigtable.data.v2.stub.BigtableStubSettings; -import com.google.cloud.bigtable.data.v2.stub.GrpcBigtableCallableFactory; -import com.google.cloud.bigtable.data.v2.stub.GrpcBigtableStub; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * Tests that the underlying GAPIC api is marked as {@code @InternalApi}. This transformation - * happens in synth.py. - */ -@RunWith(Parameterized.class) -public class HiddenGapicApiTest { - private Class testClass; - - @Parameters - public static Object[] data() { - return new Object[] { - BigtableStub.class, - BigtableStubSettings.class, - GrpcBigtableStub.class, - GrpcBigtableCallableFactory.class - }; - } - - public HiddenGapicApiTest(Class testClass) { - this.testClass = testClass; - } - - @Test - public void test() { - assertWithMessage("%s should be annotated with @InternaOnly", testClass.getName()) - .that(testClass.getAnnotation(InternalApi.class)) - .isNotNull(); - } -} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/PreparedStatementImplTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/PreparedStatementImplTest.java index 06f52598bc28..c0e2b7c3b9fc 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/PreparedStatementImplTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/PreparedStatementImplTest.java @@ -95,7 +95,7 @@ public void setUp() throws IOException { .setRefreshingChannel(false) .build(); // Remove log noise from client side metrics - settings.setMetricsProvider(NoopMetricsProvider.INSTANCE); + settings.setMetricsProvider(NoopMetricsProvider.INSTANCE).disableInternalMetrics(); prepareAttempts = settings.stubSettings().prepareQuerySettings().retrySettings().getMaxAttempts(); client = BigtableDataClient.create(settings.build()); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporterTest2.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporter2Test.java similarity index 99% rename from google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporterTest2.java rename to google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporter2Test.java index adb52ef25842..ad6ede7fad37 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporterTest2.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporter2Test.java @@ -71,7 +71,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class BigtableCloudMonitoringExporterTest2 { +class BigtableCloudMonitoringExporter2Test { private static final TableName tableName = TableName.of("fake-project", "fake-instance", "fake-table"); private static final String appProfileId = "default"; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporterTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporterTest.java index e6c8c109fc71..f4e9abbc243f 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporterTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableCloudMonitoringExporterTest.java @@ -412,6 +412,7 @@ public void testTimeSeriesForMetricWithGceOrGkeResource() { .put(ClientSchema.INSTANCE_ID_KEY.getKey(), instanceId) .put(ClientSchema.APP_PROFILE_KEY.getKey(), appProfileId) .put(ClientSchema.CLIENT_NAME.getKey(), clientName) + .put(MetricLabels.CLIENT_UID.getKey(), taskId) .build()); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BuiltinMetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BuiltinMetricsTracerTest.java index 17d55870ffe2..0016bb057b21 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BuiltinMetricsTracerTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/BuiltinMetricsTracerTest.java @@ -60,6 +60,7 @@ import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableRemainingDeadline; import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableRetryCount; import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableServerLatency; +import com.google.cloud.bigtable.data.v2.internal.csm.schema.ClientSchema; import com.google.cloud.bigtable.data.v2.internal.csm.schema.TableSchema; import com.google.cloud.bigtable.data.v2.models.AuthorizedViewId; import com.google.cloud.bigtable.data.v2.models.Query; @@ -169,6 +170,14 @@ public class BuiltinMetricsTracerTest { .put(MetricLabels.APP_PROFILE_KEY, APP_PROFILE_ID) .build(); + private Attributes expectedClientSchemaBaseAttributes = + Attributes.builder() + .put(TableSchema.BIGTABLE_PROJECT_ID_KEY, PROJECT_ID) + .put(TableSchema.INSTANCE_ID_KEY, INSTANCE_ID) + .put(MetricLabels.APP_PROFILE_KEY, APP_PROFILE_ID) + .put(MetricLabels.CLIENT_NAME, "java-bigtable/" + Version.VERSION) + .build(); + private InMemoryMetricReader metricReader; private DelayProxyDetector delayProxyDetector; @@ -395,6 +404,7 @@ public void testGfeMetrics() { .put(TableSchema.CLUSTER_ID_KEY, CLUSTER) .put(MetricLabels.CLIENT_NAME, CLIENT_NAME) .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows") + .put(MetricLabels.STREAMING_KEY, true) .build(); MetricData serverLatenciesMetricData = getMetricData(metricReader, TableServerLatency.NAME); @@ -405,7 +415,7 @@ public void testGfeMetrics() { MetricData connectivityErrorCountMetricData = getMetricData(metricReader, TableConnectivityErrorCount.NAME); Attributes expected1 = - expectedBaseAttributes.toBuilder() + expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "UNAVAILABLE") .put(TableSchema.TABLE_ID_KEY, TABLE) .put(TableSchema.ZONE_ID_KEY, "global") @@ -414,7 +424,7 @@ public void testGfeMetrics() { .put(MetricLabels.CLIENT_NAME, CLIENT_NAME) .build(); Attributes expected2 = - expectedBaseAttributes.toBuilder() + expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.STATUS_KEY, "OK") .put(TableSchema.TABLE_ID_KEY, TABLE) .put(TableSchema.ZONE_ID_KEY, ZONE) @@ -842,7 +852,7 @@ public void testBatchWriteFlowControlTargetQpsIncreased() throws InterruptedExce MetricData targetQpsMetric = getMetricData(metricReader, ClientBatchWriteFlowControlTargetQps.NAME); Attributes targetQpsAttributes = - expectedBaseAttributes.toBuilder() + expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows") .build(); double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes); @@ -851,7 +861,8 @@ public void testBatchWriteFlowControlTargetQpsIncreased() throws InterruptedExce MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME); Attributes factorAttributes = - expectedBaseAttributes.toBuilder() + expectedClientSchemaBaseAttributes.toBuilder() + .put(ClientSchema.CLIENT_NAME, "java-bigtable/" + Version.VERSION) .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows") .put(MetricLabels.APPLIED_KEY, true) .put(MetricLabels.STATUS_KEY, "OK") @@ -874,7 +885,7 @@ public void testBatchWriteFlowControlTargetQpsDecreased() throws InterruptedExce MetricData targetQpsMetric = getMetricData(metricReader, ClientBatchWriteFlowControlTargetQps.NAME); Attributes targetQpsAttributes = - expectedBaseAttributes.toBuilder() + expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows") .build(); double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes); @@ -883,7 +894,7 @@ public void testBatchWriteFlowControlTargetQpsDecreased() throws InterruptedExce MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME); Attributes factorAttributes = - expectedBaseAttributes.toBuilder() + expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows") .put(MetricLabels.APPLIED_KEY, true) .put(MetricLabels.STATUS_KEY, "OK") @@ -906,7 +917,7 @@ public void testBatchWriteFlowControlTargetQpsCappedOnMaxFactor() throws Interru MetricData targetQpsMetric = getMetricData(metricReader, ClientBatchWriteFlowControlTargetQps.NAME); Attributes targetQpsAttributes = - expectedBaseAttributes.toBuilder() + expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows") .build(); double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes); @@ -916,7 +927,7 @@ public void testBatchWriteFlowControlTargetQpsCappedOnMaxFactor() throws Interru MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME); Attributes factorAttributes = - expectedBaseAttributes.toBuilder() + expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows") .put(MetricLabels.APPLIED_KEY, true) .put(MetricLabels.STATUS_KEY, "OK") @@ -940,7 +951,7 @@ public void testBatchWriteFlowControlTargetQpsCappedOnMinFactor() throws Interru MetricData targetQpsMetric = getMetricData(metricReader, ClientBatchWriteFlowControlTargetQps.NAME); Attributes targetQpsAttributes = - expectedBaseAttributes.toBuilder() + expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows") .build(); double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes); @@ -950,7 +961,7 @@ public void testBatchWriteFlowControlTargetQpsCappedOnMinFactor() throws Interru MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME); Attributes factorAttributes = - expectedBaseAttributes.toBuilder() + expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows") .put(MetricLabels.APPLIED_KEY, true) .put(MetricLabels.STATUS_KEY, "OK") @@ -975,7 +986,7 @@ public void testBatchWriteFlowControlTargetQpsDecreasedForError() throws Interru MetricData targetQpsMetric = getMetricData(metricReader, ClientBatchWriteFlowControlTargetQps.NAME); Attributes targetQpsAttributes = - expectedBaseAttributes.toBuilder() + expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows") .build(); double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes); @@ -985,7 +996,7 @@ public void testBatchWriteFlowControlTargetQpsDecreasedForError() throws Interru MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME); Attributes factorAttributes = - expectedBaseAttributes.toBuilder() + expectedClientSchemaBaseAttributes.toBuilder() .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows") .put(MetricLabels.APPLIED_KEY, true) .put(MetricLabels.STATUS_KEY, "UNAVAILABLE") diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java index 1531506a11ad..36b4cd688c09 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java @@ -193,6 +193,7 @@ public void setUp() throws IOException, IllegalAccessException, InstantiationExc .setAppProfileId(APP_PROFILE_ID) .setCredentialsProvider(NoCredentialsProvider.create()) .setMetricsProvider(NoopMetricsProvider.INSTANCE) + .disableInternalMetrics() .build() .getStubSettings(); @@ -266,6 +267,7 @@ public void testBatchJwtAudience() .setEndpoint("batch-bigtable.googleapis.com:443") .setCredentialsProvider(FixedCredentialsProvider.create(jwtCreds)) .setMetricsProvider(NoopMetricsProvider.INSTANCE) + .disableInternalMetrics() // Use a fixed channel that will ignore the default endpoint and connect to the emulator .setTransportChannelProvider( FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel))) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SkipTrailersTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SkipTrailersTest.java index 5dee789c19c6..1bdd61ce1f49 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SkipTrailersTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SkipTrailersTest.java @@ -102,6 +102,7 @@ public void setUp() throws Exception { .setProjectId(PROJECT_ID) .setInstanceId(INSTANCE_ID) .setMetricsProvider(NoopMetricsProvider.INSTANCE) + .disableInternalMetrics() .setCredentialsProvider(NoCredentialsProvider.create()); clientBuilder.stubSettings().setTracerFactory(tracerFactory); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTestUtils.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTestUtils.java index 8eee324317ec..1aceebd64f69 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTestUtils.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTestUtils.java @@ -27,12 +27,13 @@ import io.opentelemetry.sdk.metrics.data.HistogramPointData; import io.opentelemetry.sdk.metrics.data.LongPointData; import io.opentelemetry.sdk.metrics.data.MetricData; +import io.opentelemetry.sdk.metrics.data.MetricDataType; +import io.opentelemetry.sdk.metrics.data.PointData; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import org.junit.Assert; @InternalApi public class BuiltinMetricsTestUtils { @@ -77,6 +78,9 @@ public static MetricData getMetricData(InMemoryMetricReader reader, String metri } public static long getAggregatedValue(MetricData metricData, Attributes attributes) { + assertThat(metricData.getData().getPoints().stream().map(PointData::getAttributes)) + .contains(attributes); + switch (metricData.getType()) { case HISTOGRAM: HistogramPointData hd = @@ -98,6 +102,9 @@ public static long getAggregatedValue(MetricData metricData, Attributes attribut } public static double getAggregatedDoubleValue(MetricData metricData, Attributes attributes) { + assertThat(metricData.getData().getPoints().stream().map(PointData::getAttributes)) + .contains(attributes); + switch (metricData.getType()) { case HISTOGRAM: HistogramPointData hd = @@ -140,23 +147,8 @@ public static Timestamp getStartTimeSeconds(MetricData metricData, Attributes at } public static void verifyAttributes(MetricData metricData, Attributes attributes) { - switch (metricData.getType()) { - case HISTOGRAM: - List hd = - metricData.getHistogramData().getPoints().stream() - .filter(pd -> pd.getAttributes().equals(attributes)) - .collect(Collectors.toList()); - assertThat(hd).isNotEmpty(); - break; - case LONG_SUM: - List ld = - metricData.getLongSumData().getPoints().stream() - .filter(pd -> pd.getAttributes().equals(attributes)) - .collect(Collectors.toList()); - assertThat(ld).isNotEmpty(); - break; - default: - Assert.fail("Unexpected type"); - } + assertThat(metricData.getType()).isAnyOf(MetricDataType.HISTOGRAM, MetricDataType.LONG_SUM); + assertThat(metricData.getData().getPoints().stream().map(PointData::getAttributes)) + .contains(attributes); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsRetryTest.java index cb3d49f0b279..9d0e31894dad 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsRetryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsRetryTest.java @@ -64,7 +64,8 @@ public void setUp() throws IOException { .setProjectId("fake-project") .setInstanceId("fake-instance") .setCredentialsProvider(NoCredentialsProvider.create()) - .setMetricsProvider(NoopMetricsProvider.INSTANCE); + .setMetricsProvider(NoopMetricsProvider.INSTANCE) + .disableInternalMetrics(); settings .stubSettings() diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java index 83df54f718a2..72a6400b1ad8 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java @@ -88,7 +88,8 @@ public void setUp() throws IOException { .setProjectId(PROJECT_ID) .setInstanceId(INSTANCE_ID) .setCredentialsProvider(NoCredentialsProvider.create()) - .setMetricsProvider(NoopMetricsProvider.INSTANCE); + .setMetricsProvider(NoopMetricsProvider.INSTANCE) + .disableInternalMetrics(); settings .stubSettings() diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryRetryTest.java index a348fc9e3596..95f5edf26800 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryRetryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryRetryTest.java @@ -101,7 +101,7 @@ public static BigtableDataSettings.Builder defaultSettings(GrpcServerRule server .setRefreshingChannel(false) .build(); // Remove log noise from client side metrics - settings.setMetricsProvider(NoopMetricsProvider.INSTANCE); + settings.setMetricsProvider(NoopMetricsProvider.INSTANCE).disableInternalMetrics(); return settings; } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/EmulatorEnv.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/EmulatorEnv.java index 0c6262bd9b8c..bc17bd41d21f 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/EmulatorEnv.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/EmulatorEnv.java @@ -64,6 +64,7 @@ void start() throws Exception { .setInstanceId("fake-instance") .setRefreshingChannel(false) .setMetricsProvider(NoopMetricsProvider.INSTANCE) + .disableInternalMetrics() .build(); dataClient = BigtableDataClient.create(dataSettings);