Skip to content

Commit

Permalink
changed the host env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhigarg92 committed Dec 5, 2024
1 parent 8ad2163 commit f434c1d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ final class BuiltInOpenTelemetryMetricsProvider {
private BuiltInOpenTelemetryMetricsProvider() {}

OpenTelemetry getOrCreateOpenTelemetry(
String projectId, @Nullable Credentials credentials, @Nullable String metricsHost) {
String projectId, @Nullable Credentials credentials, @Nullable String monitoringHost) {
try {
if (this.openTelemetry == null) {
SdkMeterProviderBuilder sdkMeterProviderBuilder = SdkMeterProvider.builder();
BuiltInOpenTelemetryMetricsView.registerBuiltinMetrics(
SpannerCloudMonitoringExporter.create(projectId, credentials, metricsHost),
SpannerCloudMonitoringExporter.create(projectId, credentials, monitoringHost),
sdkMeterProviderBuilder);
this.openTelemetry =
OpenTelemetrySdk.builder().setMeterProvider(sdkMeterProviderBuilder.build()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SpannerCloudMonitoringExporter implements MetricExporter {
private final String spannerProjectId;

static SpannerCloudMonitoringExporter create(
String projectId, @Nullable Credentials credentials, @Nullable String metricsHost)
String projectId, @Nullable Credentials credentials, @Nullable String monitoringHost)
throws IOException {
MetricServiceSettings.Builder settingsBuilder = MetricServiceSettings.newBuilder();
CredentialsProvider credentialsProvider;
Expand All @@ -81,8 +81,8 @@ static SpannerCloudMonitoringExporter create(
credentialsProvider = FixedCredentialsProvider.create(credentials);
}
settingsBuilder.setCredentialsProvider(credentialsProvider);
if (metricsHost != null) {
settingsBuilder.setEndpoint(metricsHost);
if (monitoringHost != null) {
settingsBuilder.setEndpoint(monitoringHost);
}

org.threeten.bp.Duration timeout = Duration.ofMinutes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public class SpannerOptions extends ServiceOptions<Spanner, SpannerOptions> {
private final boolean enableBuiltInMetrics;
private final boolean enableExtendedTracing;
private final boolean enableEndToEndTracing;
private final String metricsHost;
private final String monitoringHost;

enum TracingFramework {
OPEN_CENSUS,
Expand Down Expand Up @@ -673,7 +673,7 @@ protected SpannerOptions(Builder builder) {
enableExtendedTracing = builder.enableExtendedTracing;
enableBuiltInMetrics = builder.enableBuiltInMetrics;
enableEndToEndTracing = builder.enableEndToEndTracing;
metricsHost = builder.metricsHost;
monitoringHost = builder.monitoringHost;
}

/**
Expand Down Expand Up @@ -715,7 +715,7 @@ default boolean isEnableEndToEndTracing() {
return false;
}

default String getMetricsHost() {
default String getMonitoringHost() {
return null;
}
}
Expand All @@ -734,7 +734,7 @@ private static class SpannerEnvironmentImpl implements SpannerEnvironment {
private static final String SPANNER_ENABLE_END_TO_END_TRACING =
"SPANNER_ENABLE_END_TO_END_TRACING";
private static final String SPANNER_DISABLE_BUILTIN_METRICS = "SPANNER_DISABLE_BUILTIN_METRICS";
private static final String SPANNER_METRICS_HOST = "SPANNER_METRICS_HOST";
private static final String SPANNER_MONITORING_HOST = "SPANNER_MONITORING_HOST";

private SpannerEnvironmentImpl() {}

Expand Down Expand Up @@ -772,8 +772,8 @@ public boolean isEnableEndToEndTracing() {
}

@Override
public String getMetricsHost() {
return System.getenv(SPANNER_METRICS_HOST);
public String getMonitoringHost() {
return System.getenv(SPANNER_MONITORING_HOST);
}
}

Expand Down Expand Up @@ -840,7 +840,7 @@ public static class Builder
private boolean enableExtendedTracing = SpannerOptions.environment.isEnableExtendedTracing();
private boolean enableEndToEndTracing = SpannerOptions.environment.isEnableEndToEndTracing();
private boolean enableBuiltInMetrics = SpannerOptions.environment.isEnableBuiltInMetrics();
private String metricsHost = SpannerOptions.environment.getMetricsHost();
private String monitoringHost = SpannerOptions.environment.getMonitoringHost();

private static String createCustomClientLibToken(String token) {
return token + " " + ServiceOptions.getGoogApiClientLibName();
Expand Down Expand Up @@ -908,7 +908,7 @@ protected Builder() {
this.enableExtendedTracing = options.enableExtendedTracing;
this.enableBuiltInMetrics = options.enableBuiltInMetrics;
this.enableEndToEndTracing = options.enableEndToEndTracing;
this.metricsHost = options.metricsHost;
this.monitoringHost = options.monitoringHost;
}

@Override
Expand Down Expand Up @@ -1431,9 +1431,9 @@ public Builder setBuiltInMetricsEnabled(boolean enableBuiltInMetrics) {
return this;
}

/** Sets the metrics host to be used for Built-in client side metrics */
public Builder setMetricsHost(String metricsHost) {
this.metricsHost = metricsHost;
/** Sets the monitoring host to be used for Built-in client side metrics */
public Builder setMonitoringHost(String monitoringHost) {
this.monitoringHost = monitoringHost;
return this;
}

Expand Down Expand Up @@ -1747,7 +1747,7 @@ private ApiTracerFactory getDefaultApiTracerFactory() {
private ApiTracerFactory createMetricsApiTracerFactory() {
OpenTelemetry openTelemetry =
this.builtInOpenTelemetryMetricsProvider.getOrCreateOpenTelemetry(
this.getProjectId(), getCredentials(), this.metricsHost);
this.getProjectId(), getCredentials(), this.monitoringHost);

return openTelemetry != null
? new MetricsTracerFactory(
Expand Down Expand Up @@ -1775,8 +1775,8 @@ public boolean isEnableBuiltInMetrics() {
}

/** Returns the override metrics Host. */
String getMetricsHost() {
return metricsHost;
String getMonitoringHost() {
return monitoringHost;
}

@BetaApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,15 +755,15 @@ public void testEndToEndTracingEnablement() {
}

@Test
public void testMetricsHost() {
public void testmonitoringHost() {
String metricsEndpoint = "test-endpoint:443";
assertNull(SpannerOptions.newBuilder().setProjectId("p").build().getMetricsHost());
assertNull(SpannerOptions.newBuilder().setProjectId("p").build().getMonitoringHost());
assertThat(
SpannerOptions.newBuilder()
.setProjectId("p")
.setMetricsHost(metricsEndpoint)
.setMonitoringHost(metricsEndpoint)
.build()
.getMetricsHost())
.getMonitoringHost())
.isEqualTo(metricsEndpoint);
}

Expand Down

0 comments on commit f434c1d

Please sign in to comment.