Skip to content

Commit

Permalink
feat: Add test profile to push metrics to test environment (#1921)
Browse files Browse the repository at this point in the history
feat:add test profile
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)

Fixes 299954521 ☕️

If you write sample code, please follow the [samples format](
https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
  • Loading branch information
meeral-k committed Oct 11, 2023
1 parent 29244f7 commit 2104315
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions google-cloud-bigtable-stats/pom.xml
Expand Up @@ -254,4 +254,12 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>test</id>
<properties>
<bigtable.test-monitoring-endpoint/>
</properties>
</profile>
</profiles>
</project>
Expand Up @@ -23,6 +23,7 @@
import com.google.cloud.monitoring.v3.MetricServiceClient;
import com.google.cloud.monitoring.v3.MetricServiceSettings;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import io.opencensus.common.Duration;
import io.opencensus.exporter.metrics.util.IntervalMetricReader;
Expand All @@ -44,6 +45,11 @@ public class BigtableStackdriverStatsExporter {
private static final Duration EXPORT_INTERVAL = Duration.create(60, 0);
private static final String RESOURCE_TYPE = "bigtable_client_raw";

private static final String MONITORING_ENDPOINT =
MoreObjects.firstNonNull(
System.getProperty("bigtable.test-monitoring-endpoint"),
MetricServiceSettings.getDefaultEndpoint());

private final IntervalMetricReader intervalMetricReader;

private BigtableStackdriverStatsExporter(
Expand Down Expand Up @@ -84,7 +90,7 @@ static MetricServiceClient createMetricServiceClient(Credentials credentials, Du
MetricServiceSettings.newBuilder()
.setTransportChannelProvider(InstantiatingGrpcChannelProvider.newBuilder().build());
settingsBuilder.setCredentialsProvider(FixedCredentialsProvider.create(credentials));

settingsBuilder.setEndpoint(MONITORING_ENDPOINT);
org.threeten.bp.Duration timeout = org.threeten.bp.Duration.ofMillis(deadline.toMillis());
settingsBuilder.createServiceTimeSeriesSettings().setSimpleTimeoutNoRetries(timeout);
return MetricServiceClient.create(settingsBuilder.build());
Expand Down

0 comments on commit 2104315

Please sign in to comment.