Skip to content

Commit

Permalink
removed directpath enabled attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhigarg92 committed Sep 5, 2024
1 parent 3823d13 commit da5d07d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static com.google.cloud.opentelemetry.detection.GCPPlatformDetector.SupportedPlatform.GOOGLE_KUBERNETES_ENGINE;
import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_NAME_KEY;
import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_UID_KEY;
import static com.google.cloud.spanner.BuiltInMetricsConstant.DIRECT_PATH_ENABLED_KEY;
import static com.google.cloud.spanner.BuiltInMetricsConstant.INSTANCE_CONFIG_ID_KEY;
import static com.google.cloud.spanner.BuiltInMetricsConstant.LOCATION_ID_KEY;
import static com.google.cloud.spanner.BuiltInMetricsConstant.PROJECT_ID_KEY;
Expand Down Expand Up @@ -76,15 +75,12 @@ OpenTelemetry getOrCreateOpenTelemetry(String projectId, @Nullable Credentials c
}
}

Map<String, String> createClientAttributes(
String projectId, boolean isDirectPathChannelCreated, String client_name) {
Map<String, String> createClientAttributes(String projectId, String client_name) {
Map<String, String> clientAttributes = new HashMap<>();
clientAttributes.put(LOCATION_ID_KEY.getKey(), detectClientLocation());
clientAttributes.put(PROJECT_ID_KEY.getKey(), projectId);
// TODO: Replace this with real value.
clientAttributes.put(INSTANCE_CONFIG_ID_KEY.getKey(), "unknown");
clientAttributes.put(
DIRECT_PATH_ENABLED_KEY.getKey(), String.valueOf(isDirectPathChannelCreated));
clientAttributes.put(CLIENT_NAME_KEY.getKey(), client_name);
clientAttributes.put(CLIENT_UID_KEY.getKey(), getDefaultTaskValue());
return clientAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1652,16 +1652,15 @@ public OpenTelemetry getOpenTelemetry() {

@Override
public ApiTracerFactory getApiTracerFactory() {
return createApiTracerFactory(false, false, false);
return createApiTracerFactory(false, false);
}

public ApiTracerFactory getApiTracerFactory(
boolean isDirectPathChannelCreated, boolean isAdminClient, boolean isEmulatorEnabled) {
return createApiTracerFactory(isDirectPathChannelCreated, isAdminClient, isEmulatorEnabled);
public ApiTracerFactory getApiTracerFactory(boolean isAdminClient, boolean isEmulatorEnabled) {
return createApiTracerFactory(isAdminClient, isEmulatorEnabled);
}

private ApiTracerFactory createApiTracerFactory(
boolean isDirectPathChannelCreated, boolean isAdminClient, boolean isEmulatorEnabled) {
boolean isAdminClient, boolean isEmulatorEnabled) {
List<ApiTracerFactory> apiTracerFactories = new ArrayList<>();
// Prefer any direct ApiTracerFactory that might have been set on the builder.
apiTracerFactories.add(
Expand All @@ -1670,8 +1669,7 @@ private ApiTracerFactory createApiTracerFactory(
// Add Metrics Tracer factory if built in metrics are enabled and if the client is data client
// and if emulator is not enabled.
if (isEnableBuiltInMetrics() && !isAdminClient && !isEmulatorEnabled) {
ApiTracerFactory metricsTracerFactory =
createMetricsApiTracerFactory(isDirectPathChannelCreated);
ApiTracerFactory metricsTracerFactory = createMetricsApiTracerFactory();
if (metricsTracerFactory != null) {
apiTracerFactories.add(metricsTracerFactory);
}
Expand All @@ -1696,7 +1694,7 @@ private ApiTracerFactory getDefaultApiTracerFactory() {
return BaseApiTracerFactory.getInstance();
}

private ApiTracerFactory createMetricsApiTracerFactory(boolean isDirectPathChannelCreated) {
private ApiTracerFactory createMetricsApiTracerFactory() {
OpenTelemetry openTelemetry =
this.builtInOpenTelemetryMetricsProvider.getOrCreateOpenTelemetry(
getDefaultProjectId(), getCredentials());
Expand All @@ -1706,7 +1704,6 @@ private ApiTracerFactory createMetricsApiTracerFactory(boolean isDirectPathChann
new OpenTelemetryMetricsRecorder(openTelemetry, BuiltInMetricsConstant.METER_NAME),
builtInOpenTelemetryMetricsProvider.createClientAttributes(
getDefaultProjectId(),
isDirectPathChannelCreated,
"spanner-java/" + GaxProperties.getLibraryVersion(getClass())))
: null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,9 @@ public GapicSpannerRpc(final SpannerOptions options) {
// If it is enabled in options uses the channel pool provided by the gRPC-GCP extension.
maybeEnableGrpcGcpExtension(defaultChannelProviderBuilder, options);

InstantiatingGrpcChannelProvider defaultChannelProvider = null;
boolean isDirectPathChannelCreated = false;

if (options.getChannelProvider() == null) {
defaultChannelProvider = defaultChannelProviderBuilder.build();
isDirectPathChannelCreated =
defaultChannelProvider.canUseDirectPath()
&& defaultChannelProvider.isDirectPathXdsEnabled();
}

TransportChannelProvider channelProvider =
MoreObjects.firstNonNull(options.getChannelProvider(), defaultChannelProvider);
MoreObjects.firstNonNull(
options.getChannelProvider(), defaultChannelProviderBuilder.build());

CredentialsProvider credentialsProvider =
GrpcTransportOptions.setUpCredentialsProvider(options);
Expand Down Expand Up @@ -411,9 +402,7 @@ public GapicSpannerRpc(final SpannerOptions options) {
.setStreamWatchdogProvider(watchdogProvider)
.setTracerFactory(
options.getApiTracerFactory(
isDirectPathChannelCreated,
/* isAdminClient = */ false,
isEmulatorEnabled(options, emulatorHost)))
/* isAdminClient = */ false, isEmulatorEnabled(options, emulatorHost)))
.build());
this.readRetrySettings =
options.getSpannerStubSettings().streamingReadSettings().getRetrySettings();
Expand Down Expand Up @@ -443,9 +432,7 @@ public GapicSpannerRpc(final SpannerOptions options) {
.setStreamWatchdogProvider(watchdogProvider)
.setTracerFactory(
options.getApiTracerFactory(
isDirectPathChannelCreated,
/* isAdminClient = */ false,
isEmulatorEnabled(options, emulatorHost)))
/* isAdminClient = */ false, isEmulatorEnabled(options, emulatorHost)))
.executeSqlSettings()
.setRetrySettings(partitionedDmlRetrySettings);
pdmlSettings.executeStreamingSqlSettings().setRetrySettings(partitionedDmlRetrySettings);
Expand Down Expand Up @@ -474,9 +461,7 @@ public GapicSpannerRpc(final SpannerOptions options) {
.setStreamWatchdogProvider(watchdogProvider)
.setTracerFactory(
options.getApiTracerFactory(
isDirectPathChannelCreated,
/* isAdminClient = */ true,
isEmulatorEnabled(options, emulatorHost)))
/* isAdminClient = */ true, isEmulatorEnabled(options, emulatorHost)))
.build();
this.instanceAdminStub = GrpcInstanceAdminStub.create(instanceAdminStubSettings);

Expand All @@ -489,9 +474,7 @@ public GapicSpannerRpc(final SpannerOptions options) {
.setStreamWatchdogProvider(watchdogProvider)
.setTracerFactory(
options.getApiTracerFactory(
isDirectPathChannelCreated,
/* isAdminClient = */ true,
isEmulatorEnabled(options, emulatorHost)))
/* isAdminClient = */ true, isEmulatorEnabled(options, emulatorHost)))
.build();

// Automatically retry RESOURCE_EXHAUSTED for GetOperation if auto-throttling of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,12 @@ public static void setup() {

String client_name = "spanner-java/";
openTelemetry = OpenTelemetrySdk.builder().setMeterProvider(meterProvider.build()).build();
attributes = provider.createClientAttributes("test-project", true, client_name);
attributes = provider.createClientAttributes("test-project", client_name);

expectedBaseAttributes =
Attributes.builder()
.put(BuiltInMetricsConstant.PROJECT_ID_KEY, "test-project")
.put(BuiltInMetricsConstant.INSTANCE_CONFIG_ID_KEY, "unknown")
.put(BuiltInMetricsConstant.DIRECT_PATH_ENABLED_KEY, "true")
.put(
BuiltInMetricsConstant.LOCATION_ID_KEY,
BuiltInOpenTelemetryMetricsProvider.detectClientLocation())
Expand Down

0 comments on commit da5d07d

Please sign in to comment.