Skip to content

Commit

Permalink
udpate
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Aug 19, 2022
1 parent edd4102 commit c33e6db
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.cloud.bigtable.stats;

import com.google.api.MonitoredResource;
import com.google.api.gax.grpc.GrpcResponseMetadata;
import com.google.cloud.monitoring.v3.MetricServiceClient;
import com.google.monitoring.v3.CreateTimeSeriesRequest;
import com.google.monitoring.v3.ProjectName;
Expand Down Expand Up @@ -72,12 +73,16 @@ public void export(Collection<Metric> metrics) {
for (Map.Entry<String, List<com.google.monitoring.v3.TimeSeries>> entry :
projectToTimeSeries.entrySet()) {
ProjectName projectName = ProjectName.of(entry.getKey());
GrpcResponseMetadata metadata = new GrpcResponseMetadata();
CreateTimeSeriesRequest request =
CreateTimeSeriesRequest.newBuilder()
.setName(projectName.toString())
.addAllTimeSeries(entry.getValue())
.build();
this.metricServiceClient.createServiceTimeSeries(request);
this.metricServiceClient
.createTimeSeriesCallable()
.call(request, metadata.createContextWithHandlers());
// this.metricServiceClient.createServiceTimeSeries(request);
}
} catch (Throwable e) {
logger.log(Level.WARNING, "Exception thrown when exporting TimeSeries.", e);
Expand Down
32 changes: 30 additions & 2 deletions google-cloud-bigtable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-monitoring-bom</artifactId>
<version>3.4.1</version> <!-- needs to be in sync with google-cloud-bigtable-stats -->
<type>pom</type>
<scope>import</scope>
</dependency>

</dependencies>
</dependencyManagement>

Expand All @@ -63,8 +71,9 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigtable-stats</artifactId>
<!-- Exclude all the shaded transitive dependencies. After mvn clean install is run,
we don't need to depend on io.opencensus anymore since this package is relocated. -->
<!-- Exclude all dependencies that have been shaded. This is to workaround maven's immutable project structure:
after shading, the maven-shade-plugin tries to remove shaded dependencies, but it can't since the project
structure is immutable. So we have to manually exclude the shaded transitive dependencies manually. -->
<exclusions>
<exclusion>
<groupId>io.opencensus</groupId>
Expand Down Expand Up @@ -254,6 +263,16 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-monitoring</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-monitoring-v3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
Expand Down Expand Up @@ -645,7 +664,16 @@
<usedDependencies>io.grpc:grpc-auth,io.grpc:grpc-grpclb</usedDependencies>
<ignoredUsedUndeclaredDependencies>
<ignoredUsedUndeclaredDependency>io.opencensus:opencensus-impl-core</ignoredUsedUndeclaredDependency>
<!-- <ignoredUsedUndeclaredDependency>com.google.cloud:google-cloud-monitoring</ignoredUsedUndeclaredDependency>-->
<!-- <ignoredUsedUndeclaredDependency>com.google.api.grpc:proto-google-cloud-monitoring-v3</ignoredUsedUndeclaredDependency>-->
</ignoredUsedUndeclaredDependencies>
<!-- <ignoredNonTestScopedDependencies>-->
<!-- <ignoredNonTestScopedDependency>com.google.cloud:google-cloud-monitoring</ignoredNonTestScopedDependency>-->
<!-- <ignoredNonTestScopedDependency>com.google.api.grpc:proto-google-cloud-monitoring-v3</ignoredNonTestScopedDependency>-->
<!-- <ignoredNonTestScopedDependency>io.grpc:grpc-netty-shaded</ignoredNonTestScopedDependency>-->
<!-- <ignoredNonTestScopedDependency>io.grpc:grpc-context</ignoredNonTestScopedDependency>-->
<!-- <ignoredNonTestScopedDependency>io.grpc:grpc-core</ignoredNonTestScopedDependency>-->
<!-- </ignoredNonTestScopedDependencies>-->
</configuration>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.cloud.bigtable.data.v2.it;

import static com.google.common.truth.TruthJUnit.assume;
import static com.google.common.truth.Truth.assertThat;

import com.google.api.client.util.Lists;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
Expand All @@ -26,19 +27,24 @@
import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
import com.google.cloud.monitoring.v3.MetricServiceClient;
import com.google.cloud.monitoring.v3.MetricServiceSettings;
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.time.Duration;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

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 {
@ClassRule public static TestEnvRule testEnvRule = new TestEnvRule();
public static MetricServiceClient metricClient;
Expand Down Expand Up @@ -70,6 +76,11 @@ public static void setUpClass() throws IOException {
metricClient = MetricServiceClient.create(settings);
}

@AfterClass
public static void tearDown() {
metricClient.close();
}

@Test
public void testBuiltinMetrics() throws Exception {
// Send a MutateRow and ReadRows request
Expand All @@ -87,12 +98,12 @@ public void testBuiltinMetrics() throws Exception {
.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);
Thread.sleep(Duration.ofMinutes(5).toMillis());

ProjectName name = ProjectName.of(testEnvRule.env().getProjectId());

// Restrict time to last 10 minutes
long startMillis = System.currentTimeMillis() - ((60 * 10) * 1000);
long startMillis = System.currentTimeMillis() - Duration.ofMinutes (10).toMillis();
TimeInterval interval =
TimeInterval.newBuilder()
.setStartTime(Timestamps.fromMillis(startMillis))
Expand All @@ -115,7 +126,7 @@ public void testBuiltinMetrics() throws Exception {
.setView(ListTimeSeriesRequest.TimeSeriesView.FULL);
ListTimeSeriesResponse response =
metricClient.listTimeSeriesCallable().call(requestBuilder.build());
Truth.assertThat(response.getTimeSeriesCount()).isGreaterThan(0);
assertThat(response.getTimeSeriesCount()).isGreaterThan(0);

// Verify that metrics are published for ReadRows request
metricFilter =
Expand All @@ -125,12 +136,7 @@ public void testBuiltinMetrics() throws Exception {
testEnvRule.env().getInstanceId());
requestBuilder.setFilter(metricFilter);
response = metricClient.listTimeSeriesCallable().call(requestBuilder.build());
Truth.assertThat(response.getTimeSeriesCount()).isGreaterThan(0);
assertThat(response.getTimeSeriesCount()).isGreaterThan(0);
}
}

@AfterClass
public static void tearDown() {
metricClient.close();
}
}

0 comments on commit c33e6db

Please sign in to comment.