Skip to content

Commit 090982d

Browse files
Allow to disable driver baggage
1 parent 3e5429d commit 090982d

File tree

7 files changed

+38
-11
lines changed

7 files changed

+38
-11
lines changed

core/src/main/java/com/datastax/oss/driver/api/core/config/DefaultDriverOption.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,13 @@ public enum DefaultDriverOption implements DriverOption {
10351035
*
10361036
* <p>Value-Type: boolean
10371037
*/
1038-
ADDRESS_TRANSLATOR_RESOLVE_ADDRESSES("advanced.address-translator.resolve-addresses");
1038+
ADDRESS_TRANSLATOR_RESOLVE_ADDRESSES("advanced.address-translator.resolve-addresses"),
1039+
/**
1040+
* Option to include driver configuration parameters in startup message.
1041+
*
1042+
* <p>Value-type: boolean
1043+
*/
1044+
REQUEST_STARTUP_BAGGAGE_ENABLED("advanced.request.startup-baggage-enabled");
10391045

10401046
private final String path;
10411047

core/src/main/java/com/datastax/oss/driver/api/core/config/OptionsMap.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ protected static void fillWithDriverDefaults(OptionsMap map) {
383383
map.put(TypedDriverOption.METRICS_GENERATE_AGGREGABLE_HISTOGRAMS, true);
384384
map.put(
385385
TypedDriverOption.LOAD_BALANCING_DC_FAILOVER_PREFERRED_REMOTE_DCS, ImmutableList.of(""));
386+
map.put(TypedDriverOption.REQUEST_STARTUP_BAGGAGE_ENABLED, true);
386387
}
387388

388389
@Immutable

core/src/main/java/com/datastax/oss/driver/api/core/config/TypedDriverOption.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,11 @@ public String toString() {
920920
DefaultDriverOption.LOAD_BALANCING_DC_FAILOVER_PREFERRED_REMOTE_DCS,
921921
GenericType.listOf(String.class));
922922

923+
/** Option to include driver configuration parameters in startup message. */
924+
public static final TypedDriverOption<Boolean> REQUEST_STARTUP_BAGGAGE_ENABLED =
925+
new TypedDriverOption<>(
926+
DefaultDriverOption.REQUEST_STARTUP_BAGGAGE_ENABLED, GenericType.BOOLEAN);
927+
923928
private static Iterable<TypedDriverOption<?>> introspectBuiltInValues() {
924929
try {
925930
ImmutableList.Builder<TypedDriverOption<?>> result = ImmutableList.builder();

core/src/main/java/com/datastax/oss/driver/internal/core/context/DefaultDriverContext.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ public class DefaultDriverContext implements InternalDriverContext {
216216
new LazyReference<>("metricIdGenerator", this::buildMetricIdGenerator, cycleDetector);
217217
private final LazyReference<RequestThrottler> requestThrottlerRef =
218218
new LazyReference<>("requestThrottler", this::buildRequestThrottler, cycleDetector);
219-
private final LazyReference<Map<String, String>> startupOptionsRef =
220-
new LazyReference<>("startupOptions", this::buildStartupOptions, cycleDetector);
219+
private final LazyReference<StartupOptionsBuilder> startupOptionsRef =
220+
new LazyReference<>("startupOptionsFactory", this::buildStartupOptionsFactory, cycleDetector);
221221
private final LazyReference<NodeStateListener> nodeStateListenerRef;
222222
private final LazyReference<SchemaChangeListener> schemaChangeListenerRef;
223223
private final LazyReference<RequestTracker> requestTrackerRef;
@@ -335,16 +335,15 @@ public DefaultDriverContext(
335335
}
336336

337337
/**
338-
* Builds a map of options to send in a Startup message.
338+
* Returns builder of options to send in a Startup message.
339339
*
340340
* @see #getStartupOptions()
341341
*/
342-
protected Map<String, String> buildStartupOptions() {
342+
protected StartupOptionsBuilder buildStartupOptionsFactory() {
343343
return new StartupOptionsBuilder(this)
344344
.withClientId(startupClientId)
345345
.withApplicationName(startupApplicationName)
346-
.withApplicationVersion(startupApplicationVersion)
347-
.build();
346+
.withApplicationVersion(startupApplicationVersion);
348347
}
349348

350349
protected Map<String, LoadBalancingPolicy> buildLoadBalancingPolicies() {
@@ -1013,7 +1012,8 @@ public ProtocolVersion getProtocolVersion() {
10131012
@NonNull
10141013
@Override
10151014
public Map<String, String> getStartupOptions() {
1016-
return startupOptionsRef.get();
1015+
// startup options are calculated dynamically and maj vary per connection
1016+
return startupOptionsRef.get().build();
10171017
}
10181018

10191019
protected RequestLogFormatter buildRequestLogFormatter() {

core/src/main/java/com/datastax/oss/driver/internal/core/context/StartupOptionsBuilder.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.datastax.oss.driver.internal.core.context;
1919

2020
import com.datastax.dse.driver.api.core.config.DseDriverOption;
21+
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
2122
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
2223
import com.datastax.oss.driver.api.core.loadbalancing.LoadBalancingPolicy;
2324
import com.datastax.oss.driver.api.core.session.Session;
@@ -129,8 +130,12 @@ public Map<String, String> build() {
129130
if (applicationVersion != null) {
130131
builder.put(APPLICATION_VERSION_KEY, applicationVersion);
131132
}
132-
// do not cache local DC as it can change within LBP implementation
133-
driverBaggage().ifPresent(s -> builder.put(DRIVER_BAGGAGE, s));
133+
boolean baggageEnabled =
134+
config.getBoolean(DefaultDriverOption.REQUEST_STARTUP_BAGGAGE_ENABLED, true);
135+
if (baggageEnabled) {
136+
// do not cache local DC as it can change within LBP implementation
137+
driverBaggage().ifPresent(s -> builder.put(DRIVER_BAGGAGE, s));
138+
}
134139

135140
return builder.build();
136141
}

core/src/main/resources/reference.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,14 @@ datastax-java-driver {
11501150
# Overridable in a profile: no
11511151
warn-if-set-keyspace = true
11521152

1153+
# Enable publishing driver baggage with Startup message that contains
1154+
# driver configuration details.
1155+
#
1156+
# Required: no
1157+
# Modifiable at runtime: yes
1158+
# Overridable in a profile: no
1159+
startup-baggage-enabled = true
1160+
11531161
# If tracing is enabled for a query, this controls how the trace is fetched.
11541162
trace {
11551163
# How many times the driver will attempt to fetch the query if it is not ready yet.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
import org.mockito.Mock;
5959

6060
@RunWith(DataProviderRunner.class)
61-
public class DseStartupOptionsBuilderTest {
61+
public class StartupOptionsBuilderTest {
6262

6363
private DefaultDriverContext driverContext;
6464

@@ -73,6 +73,8 @@ public void before() {
7373
when(configLoader.getInitialConfig()).thenReturn(driverConfig);
7474
when(driverConfig.getDefaultProfile()).thenReturn(defaultProfile);
7575
when(defaultProfile.isDefined(DseDriverOption.CONTINUOUS_PAGING_PAGE_SIZE)).thenReturn(true);
76+
when(defaultProfile.getBoolean(DefaultDriverOption.REQUEST_STARTUP_BAGGAGE_ENABLED, true))
77+
.thenReturn(true);
7678
}
7779

7880
private void buildContext(

0 commit comments

Comments
 (0)