-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add integration test for builtin metrics #1360
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
509e772
test: add integration test for builtin metrics
mutianf 4752130
add license
mutianf edd4102
test on staging
mutianf c33e6db
udpate
mutianf f0d424b
address comments
mutianf 00b540d
remove debugging
mutianf 954c0ef
fix dependency test
mutianf ed532cb
update comment
mutianf 535ba53
update integration test to only close client if it's not null
mutianf 1ed7df1
explain why we're including grpc-xds
mutianf 6cfea25
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
137 changes: 137 additions & 0 deletions
137
...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,137 @@ | ||
/* | ||
* Copyright 2022 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.it; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
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.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.time.Duration; | ||
import java.util.ArrayList; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public class BuiltinMetricsIT { | ||
mutianf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@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(); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() { | ||
if (metricClient != null) { | ||
metricClient.close(); | ||
} | ||
} | ||
|
||
@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(Duration.ofMinutes(5).toMillis()); | ||
|
||
ProjectName name = ProjectName.of(testEnvRule.env().getProjectId()); | ||
|
||
// Restrict time to last 10 minutes | ||
long startMillis = System.currentTimeMillis() - Duration.ofMinutes(10).toMillis(); | ||
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()); | ||
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()); | ||
assertThat(response.getTimeSeriesCount()).isGreaterThan(0); | ||
} | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed, please add a bit more info here