Skip to content

Commit

Permalink
Merge branch 'main' into primer
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf authored Dec 3, 2024
2 parents 5f91623 + 9ccf124 commit 41fcd47
Showing 1 changed file with 10 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
import static com.google.common.truth.TruthJUnit.assume;

import com.google.api.client.util.Lists;
import com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient;
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient;
import com.google.cloud.bigtable.admin.v2.models.AppProfile;
import com.google.cloud.bigtable.admin.v2.models.CreateAppProfileRequest;
import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest;
import com.google.cloud.bigtable.admin.v2.models.Table;
import com.google.cloud.bigtable.data.v2.BigtableDataClient;
Expand Down Expand Up @@ -94,12 +91,9 @@ public class BuiltinMetricsIT {
private BigtableDataClient clientCustomOtel;
private BigtableDataClient clientDefault;
private BigtableTableAdminClient tableAdminClient;
private BigtableInstanceAdminClient instanceAdminClient;
private MetricServiceClient metricClient;

private InMemoryMetricReader metricReader;
private String appProfileCustomOtel;
private String appProfileDefault;

public static String[] VIEWS = {
"operation_latencies",
Expand Down Expand Up @@ -131,19 +125,6 @@ public void setup() throws IOException {
metricClient = MetricServiceClient.create();

tableAdminClient = testEnvRule.env().getTableAdminClient();
instanceAdminClient = testEnvRule.env().getInstanceAdminClient();
appProfileCustomOtel = PrefixGenerator.newPrefix("test1");
appProfileDefault = PrefixGenerator.newPrefix("test2");
instanceAdminClient.createAppProfile(
CreateAppProfileRequest.of(testEnvRule.env().getInstanceId(), appProfileCustomOtel)
.setRoutingPolicy(
AppProfile.SingleClusterRoutingPolicy.of(testEnvRule.env().getPrimaryClusterId()))
.setIsolationPolicy(AppProfile.StandardIsolationPolicy.of(AppProfile.Priority.LOW)));
instanceAdminClient.createAppProfile(
CreateAppProfileRequest.of(testEnvRule.env().getInstanceId(), appProfileDefault)
.setRoutingPolicy(
AppProfile.SingleClusterRoutingPolicy.of(testEnvRule.env().getPrimaryClusterId()))
.setIsolationPolicy(AppProfile.StandardIsolationPolicy.of(AppProfile.Priority.LOW)));

// When using the custom OTEL instance, we can also register a InMemoryMetricReader on the
// SdkMeterProvider to verify the data exported on Cloud Monitoring with the in memory metric
Expand All @@ -162,9 +143,8 @@ public void setup() throws IOException {
BigtableDataClient.create(
settings
.setMetricsProvider(CustomOpenTelemetryMetricsProvider.create(openTelemetry))
.setAppProfileId(appProfileCustomOtel)
.build());
clientDefault = BigtableDataClient.create(settings.setAppProfileId(appProfileDefault).build());
clientDefault = BigtableDataClient.create(settings.build());
}

@After
Expand All @@ -178,12 +158,7 @@ public void tearDown() {
if (tableDefault != null) {
tableAdminClient.deleteTable(tableDefault.getId());
}
if (instanceAdminClient != null) {
instanceAdminClient.deleteAppProfile(
testEnvRule.env().getInstanceId(), appProfileCustomOtel, true);
instanceAdminClient.deleteAppProfile(
testEnvRule.env().getInstanceId(), appProfileDefault, true);
}

if (clientCustomOtel != null) {
clientCustomOtel.close();
}
Expand Down Expand Up @@ -231,8 +206,8 @@ public void testBuiltinMetricsWithDefaultOTEL() throws Exception {
String.format(
"metric.type=\"bigtable.googleapis.com/client/%s\" "
+ "AND resource.labels.instance=\"%s\" AND metric.labels.method=\"Bigtable.MutateRow\""
+ " AND resource.labels.table=\"%s\" AND metric.labels.app_profile=\"%s\"",
view, testEnvRule.env().getInstanceId(), tableDefault.getId(), appProfileDefault);
+ " AND resource.labels.table=\"%s\"",
view, testEnvRule.env().getInstanceId(), tableDefault.getId());
ListTimeSeriesRequest.Builder requestBuilder =
ListTimeSeriesRequest.newBuilder()
.setName(name.toString())
Expand All @@ -246,8 +221,8 @@ public void testBuiltinMetricsWithDefaultOTEL() throws Exception {
String.format(
"metric.type=\"bigtable.googleapis.com/client/%s\" "
+ "AND resource.labels.instance=\"%s\" AND metric.labels.method=\"Bigtable.ReadRows\""
+ " AND resource.labels.table=\"%s\" AND metric.labels.app_profile=\"%s\"",
view, testEnvRule.env().getInstanceId(), tableDefault.getId(), appProfileDefault);
+ " AND resource.labels.table=\"%s\"",
view, testEnvRule.env().getInstanceId(), tableDefault.getId());
requestBuilder.setFilter(metricFilter);

verifyMetricsArePublished(requestBuilder.build(), metricsPollingStopwatch, view);
Expand Down Expand Up @@ -299,11 +274,8 @@ public void testBuiltinMetricsWithCustomOTEL() throws Exception {
String.format(
"metric.type=\"bigtable.googleapis.com/client/%s\" "
+ "AND resource.labels.instance=\"%s\" AND metric.labels.method=\"Bigtable.MutateRow\""
+ " AND resource.labels.table=\"%s\" AND metric.labels.app_profile=\"%s\"",
view,
testEnvRule.env().getInstanceId(),
tableCustomOtel.getId(),
appProfileCustomOtel);
+ " AND resource.labels.table=\"%s\"",
view, testEnvRule.env().getInstanceId(), tableCustomOtel.getId());
ListTimeSeriesRequest.Builder requestBuilder =
ListTimeSeriesRequest.newBuilder()
.setName(name.toString())
Expand All @@ -320,11 +292,8 @@ public void testBuiltinMetricsWithCustomOTEL() throws Exception {
String.format(
"metric.type=\"bigtable.googleapis.com/client/%s\" "
+ "AND resource.labels.instance=\"%s\" AND metric.labels.method=\"Bigtable.ReadRows\""
+ " AND resource.labels.table=\"%s\" AND metric.labels.app_profile=\"%s\"",
view,
testEnvRule.env().getInstanceId(),
tableCustomOtel.getId(),
appProfileCustomOtel);
+ " AND resource.labels.table=\"%s\"",
view, testEnvRule.env().getInstanceId(), tableCustomOtel.getId());
requestBuilder.setFilter(metricFilter);

response = verifyMetricsArePublished(requestBuilder.build(), metricsPollingStopwatch, view);
Expand Down

0 comments on commit 41fcd47

Please sign in to comment.