From 210431523ce54029db846a0d6777d5e417e039dd Mon Sep 17 00:00:00 2001 From: meeral-k <108340829+meeral-k@users.noreply.github.com> Date: Wed, 11 Oct 2023 16:48:14 -0400 Subject: [PATCH] feat: Add test profile to push metrics to test environment (#1921) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- google-cloud-bigtable-stats/pom.xml | 8 ++++++++ .../bigtable/stats/BigtableStackdriverStatsExporter.java | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/google-cloud-bigtable-stats/pom.xml b/google-cloud-bigtable-stats/pom.xml index 0c3e9df779..2ccabaaea9 100644 --- a/google-cloud-bigtable-stats/pom.xml +++ b/google-cloud-bigtable-stats/pom.xml @@ -254,4 +254,12 @@ + + + test + + + + + diff --git a/google-cloud-bigtable-stats/src/main/java/com/google/cloud/bigtable/stats/BigtableStackdriverStatsExporter.java b/google-cloud-bigtable-stats/src/main/java/com/google/cloud/bigtable/stats/BigtableStackdriverStatsExporter.java index f6c80fdf88..76a36215c6 100644 --- a/google-cloud-bigtable-stats/src/main/java/com/google/cloud/bigtable/stats/BigtableStackdriverStatsExporter.java +++ b/google-cloud-bigtable-stats/src/main/java/com/google/cloud/bigtable/stats/BigtableStackdriverStatsExporter.java @@ -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; @@ -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( @@ -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());