-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add integration test for builtin metrics
- Loading branch information
Showing
5 changed files
with
137 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...e-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package com.google.cloud.bigtable.data.v2.it; | ||
|
||
import static com.google.common.truth.TruthJUnit.assume; | ||
|
||
import com.google.api.client.util.Lists; | ||
import com.google.cloud.bigtable.data.v2.BigtableDataSettings; | ||
import com.google.cloud.bigtable.data.v2.models.Query; | ||
import com.google.cloud.bigtable.data.v2.models.Row; | ||
import com.google.cloud.bigtable.data.v2.models.RowMutation; | ||
import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv; | ||
import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; | ||
import com.google.cloud.monitoring.v3.MetricServiceClient; | ||
import com.google.common.truth.Truth; | ||
import com.google.monitoring.v3.ListTimeSeriesRequest; | ||
import com.google.monitoring.v3.ListTimeSeriesResponse; | ||
import com.google.monitoring.v3.ProjectName; | ||
import com.google.monitoring.v3.TimeInterval; | ||
import com.google.protobuf.util.Timestamps; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
public class BuiltinMetricsIT { | ||
@ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); | ||
public static MetricServiceClient metricClient; | ||
|
||
public static String[] VIEWS = { | ||
"operation_latencies", | ||
"retry_count", | ||
"attempt_latencies", | ||
"server_latencies", | ||
"connectivity_error_count", | ||
"application_latencies" | ||
}; | ||
|
||
@BeforeClass | ||
public static void setUpClass() throws IOException { | ||
assume() | ||
.withMessage("Builtin metrics integration test is not supported by emulator") | ||
.that(testEnvRule.env()) | ||
.isNotInstanceOf(EmulatorEnv.class); | ||
|
||
// Enable built in metrics | ||
BigtableDataSettings.enableBuiltinMetrics(); | ||
|
||
// Create a cloud monitoring client | ||
metricClient = MetricServiceClient.create(); | ||
} | ||
|
||
@Test | ||
public void testBuiltinMetrics() throws Exception { | ||
// Send a MutateRow and ReadRows request | ||
testEnvRule | ||
.env() | ||
.getDataClient() | ||
.mutateRow( | ||
RowMutation.create(testEnvRule.env().getTableId(), "a-new-key") | ||
.setCell(testEnvRule.env().getFamilyId(), "q", "abc")); | ||
ArrayList<Row> rows = | ||
Lists.newArrayList( | ||
testEnvRule | ||
.env() | ||
.getDataClient() | ||
.readRows(Query.create(testEnvRule.env().getTableId()).limit(10))); | ||
|
||
// Sleep 5 minutes so the metrics could be published and precomputation is done | ||
Thread.sleep(60 * 5 * 1000); | ||
|
||
ProjectName name = ProjectName.of(testEnvRule.env().getProjectId()); | ||
|
||
// Restrict time to last 10 minutes | ||
long startMillis = System.currentTimeMillis() - ((60 * 10) * 1000); | ||
TimeInterval interval = | ||
TimeInterval.newBuilder() | ||
.setStartTime(Timestamps.fromMillis(startMillis)) | ||
.setEndTime(Timestamps.fromMillis(System.currentTimeMillis())) | ||
.build(); | ||
|
||
for (String view : VIEWS) { | ||
// Filter on instance and method name | ||
// Verify that metrics are published for MutateRow request | ||
String metricFilter = | ||
String.format( | ||
"metric.type=\"bigtable.googleapis.com/client/%s\" " | ||
+ "AND resource.labels.instance=\"%s\" AND metric.labels.method=\"Bigtable.MutateRow\"", | ||
view, testEnvRule.env().getInstanceId()); | ||
ListTimeSeriesRequest.Builder requestBuilder = | ||
ListTimeSeriesRequest.newBuilder() | ||
.setName(name.toString()) | ||
.setFilter(metricFilter) | ||
.setInterval(interval) | ||
.setView(ListTimeSeriesRequest.TimeSeriesView.FULL); | ||
ListTimeSeriesResponse response = | ||
metricClient.listTimeSeriesCallable().call(requestBuilder.build()); | ||
Truth.assertThat(response.getTimeSeriesCount()).isGreaterThan(0); | ||
|
||
// Verify that metrics are published for ReadRows request | ||
metricFilter = | ||
String.format( | ||
"metric.type=\"bigtable.googleapis.com/client/operation_latencies\" " | ||
+ "AND resource.labels.instance=\"%s\" AND metric.labels.method=\"Bigtable.ReadRows\"", | ||
testEnvRule.env().getInstanceId()); | ||
requestBuilder.setFilter(metricFilter); | ||
response = metricClient.listTimeSeriesCallable().call(requestBuilder.build()); | ||
Truth.assertThat(response.getTimeSeriesCount()).isGreaterThan(0); | ||
} | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() { | ||
metricClient.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters