Skip to content

Commit

Permalink
update default
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Sep 30, 2024
1 parent 0435ead commit 68d0507
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import com.google.cloud.bigtable.data.v2.stub.metrics.MetricsProvider;
import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor;
import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsBatchingDescriptor;
import com.google.cloud.monitoring.v3.MetricServiceSettings;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
Expand All @@ -66,6 +65,7 @@
import java.util.Set;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.threeten.bp.Duration;

/**
Expand Down Expand Up @@ -251,7 +251,7 @@ public class EnhancedBigtableStubSettings extends StubSettings<EnhancedBigtableS
private final FeatureFlags featureFlags;

private final MetricsProvider metricsProvider;
private final String metricsEndpoint;
@Nullable private final String metricsEndpoint;

private EnhancedBigtableStubSettings(Builder builder) {
super(builder);
Expand Down Expand Up @@ -365,6 +365,11 @@ public boolean getEnableRetryInfo() {
return enableRetryInfo;
}

/**
* Gets the Google Cloud Monitoring endpoint for publishing client side metrics. If it's null,
* client will publish metrics to the default monitoring endpoint.
*/
@Nullable
public String getMetricsEndpoint() {
return metricsEndpoint;
}
Expand Down Expand Up @@ -691,7 +696,7 @@ public static class Builder extends StubSettings.Builder<EnhancedBigtableStubSet
private FeatureFlags.Builder featureFlags;

private MetricsProvider metricsProvider;
private String metricsEndpoint;
@Nullable private String metricsEndpoint;

/**
* Initializes a new Builder with sane defaults for all settings.
Expand All @@ -710,7 +715,6 @@ private Builder() {
this.enableRoutingCookie = true;
this.enableRetryInfo = true;
metricsProvider = DefaultMetricsProvider.INSTANCE;
metricsEndpoint = MetricServiceSettings.getDefaultEndpoint();

// Defaults provider
BigtableStubSettings.Builder baseDefaults = BigtableStubSettings.newBuilder();
Expand Down Expand Up @@ -1009,13 +1013,20 @@ public MetricsProvider getMetricsProvider() {
return this.metricsProvider;
}

/** Set the endpoint for publishing client side metrics. */
/**
* Built-in client side metrics are published through Google Cloud Monitoring endpoint. This
* setting overrides the default endpoint for publishing the metrics.
*/
public Builder setMetricsEndpoint(String endpoint) {
this.metricsEndpoint = endpoint;
return this;
}

/** Get the endpoint for client side metrics. */
/**
* Get the Google Cloud Monitoring endpoint for publishing client side metrics. If it's null,
* client will publish metrics to the default monitoring endpoint.
*/
@Nullable
public String getMetricsEndpoint() {
return metricsEndpoint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public final class BigtableCloudMonitoringExporter implements MetricExporter {
private static final Logger logger =
Logger.getLogger(BigtableCloudMonitoringExporter.class.getName());

// This system property can be used to override the monitoring endpoint
// to a different environment. It's meant for internal testing only and
// will be removed in future versions. Use settings in EnhancedBigtableStubSettings
// to override the endpoint.
private static final String MONITORING_ENDPOINT =
System.getProperty("bigtable.test-monitoring-endpoint");

private static final String APPLICATION_RESOURCE_PROJECT_ID = "project_id";

// This the quota limit from Cloud Monitoring. More details in
Expand Down Expand Up @@ -118,14 +125,22 @@ public final class BigtableCloudMonitoringExporter implements MetricExporter {
.collect(ImmutableList.toImmutableList());

public static BigtableCloudMonitoringExporter create(
String projectId, @Nullable Credentials credentials, String endpoint) throws IOException {
String projectId, @Nullable Credentials credentials, @Nullable String endpoint)
throws IOException {
MetricServiceSettings.Builder settingsBuilder = MetricServiceSettings.newBuilder();
CredentialsProvider credentialsProvider =
Optional.ofNullable(credentials)
.<CredentialsProvider>map(FixedCredentialsProvider::create)
.orElse(NoCredentialsProvider.create());
settingsBuilder.setCredentialsProvider(credentialsProvider);
settingsBuilder.setEndpoint(endpoint);
if (MONITORING_ENDPOINT != null) {
logger.warning(
"Setting the monitoring endpoint through system variable will be removed in future versions");
settingsBuilder.setEndpoint(MONITORING_ENDPOINT);
}
if (endpoint != null) {
settingsBuilder.setEndpoint(endpoint);
}

org.threeten.bp.Duration timeout = Duration.ofMinutes(1);
// TODO: createServiceTimeSeries needs special handling if the request failed. Leaving
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public static void registerBuiltinMetrics(

/**
* Register built-in metrics on the {@link SdkMeterProviderBuilder} with custom credentials and
* endpoint
* endpoint.
*/
public static void registerBuiltinMetrics(
String projectId,
@Nullable Credentials credentials,
SdkMeterProviderBuilder builder,
String endpoint)
@Nullable String endpoint)
throws IOException {
MetricExporter metricExporter =
BigtableCloudMonitoringExporter.create(projectId, credentials, endpoint);
Expand Down

0 comments on commit 68d0507

Please sign in to comment.