diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableExporterUtils.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableExporterUtils.java index 21cab9a19d..797f7f1eca 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableExporterUtils.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableExporterUtils.java @@ -111,9 +111,9 @@ static String getProjectId(PointData pointData) { return pointData.getAttributes().get(BIGTABLE_PROJECT_ID_KEY); } + // Returns a list of timeseries by project id static Map> convertToBigtableTimeSeries( List collection, String taskId) { - // List of timeseries by project id Map> allTimeSeries = new HashMap<>(); for (MetricData metricData : collection) { diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/DefaultMetricsProviderTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/DefaultMetricsProviderTest.java index 8eea857159..05bbf6db02 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/DefaultMetricsProviderTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/DefaultMetricsProviderTest.java @@ -15,10 +15,15 @@ */ package com.google.cloud.bigtable.data.v2.stub.metrics; -import com.google.auth.oauth2.GoogleCredentials; +import com.google.auth.Credentials; import com.google.cloud.NoCredentials; +import com.google.common.collect.ImmutableMap; import io.opentelemetry.api.OpenTelemetry; import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import java.util.List; +import java.util.Map; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -38,8 +43,7 @@ public void test() throws IOException { // different endpoint and credential should return a different instance OpenTelemetry otel3 = provider.getOpenTelemetry(null, null); // same endpoint, different credential, should return a different instance - OpenTelemetry otel4 = - provider.getOpenTelemetry("fake-endpoint:123", GoogleCredentials.getApplicationDefault()); + OpenTelemetry otel4 = provider.getOpenTelemetry("fake-endpoint:123", new FakeCredentials()); // everything is the same, should return the same instance OpenTelemetry otel5 = provider.getOpenTelemetry("fake-endpoint:123", NoCredentials.getInstance()); @@ -51,4 +55,29 @@ public void test() throws IOException { provider.toString(); } + + private static class FakeCredentials extends Credentials { + @Override + public String getAuthenticationType() { + return "fake"; + } + + @Override + public Map> getRequestMetadata(URI uri) throws IOException { + return ImmutableMap.of("my-header", Arrays.asList("fake-credential")); + } + + @Override + public boolean hasRequestMetadata() { + return true; + } + + @Override + public boolean hasRequestMetadataOnly() { + return true; + } + + @Override + public void refresh() throws IOException {} + } }