Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of generic Mongo params via connection string #356

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static dev.responsive.kafka.api.config.ResponsiveConfig.ASYNC_MAX_EVENTS_QUEUED_PER_ASYNC_THREAD_CONFIG;
import static dev.responsive.kafka.api.config.ResponsiveConfig.ASYNC_THREAD_POOL_SIZE_CONFIG;
import static dev.responsive.kafka.api.config.ResponsiveConfig.METRICS_ENABLED_CONFIG;
import static dev.responsive.kafka.api.config.ResponsiveConfig.MONGO_ADDITIONAL_CONNECTION_STRING_PARAMS_CONFIG;
import static dev.responsive.kafka.api.config.ResponsiveConfig.MONGO_ENDPOINT_CONFIG;
import static dev.responsive.kafka.api.config.ResponsiveConfig.MONGO_PASSWORD_CONFIG;
import static dev.responsive.kafka.api.config.ResponsiveConfig.MONGO_USERNAME_CONFIG;
Expand Down Expand Up @@ -493,7 +494,8 @@ public Params build() {
final var mongoClient = SessionUtil.connect(
hostname,
clientId,
clientSecret == null ? null : clientSecret.value()
clientSecret == null ? null : clientSecret.value(),
responsiveConfig.getString(MONGO_ADDITIONAL_CONNECTION_STRING_PARAMS_CONFIG)
);
final boolean timestampFirstOrder =
responsiveConfig.getBoolean(MONGO_WINDOWED_KEY_TIMESTAMP_FIRST_CONFIG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public class ResponsiveConfig extends AbstractConfig {
public static final String MONGO_ENDPOINT_CONFIG = "responsive.mongo.endpoint";
private static final String MONGO_ENDPOINT_DOC = "The MongoDB endpoint to connect to.";

public static final String MONGO_ADDITIONAL_CONNECTION_STRING_PARAMS_CONFIG = "responsive.mongo.additional.connection.string.params";
private static final String MONGO_ADDITIONAL_CONNECTION_STRING_PARAMS_DOC = "Additional MongoDB config options to be appended to the "
+ "connection string. ";

public static final String MONGO_COLLECTION_SHARDING_ENABLED_CONFIG = "responsive.mongo.collection.sharding.enabled";
private static final boolean MONGO_COLLECTION_SHARDING_ENABLED_DEFAULT = false;
private static final String MONGO_COLLECTION_SHARDING_ENABLED_DOC = "Toggles use of sharded collections. Set "
Expand Down Expand Up @@ -503,6 +507,12 @@ public class ResponsiveConfig extends AbstractConfig {
MONGO_WINDOWED_KEY_TIMESTAMP_FIRST_DEFAULT,
Importance.LOW,
MONGO_WINDOWED_KEY_TIMESTAMP_FIRST_DOC
).define(
MONGO_ADDITIONAL_CONNECTION_STRING_PARAMS_CONFIG,
Type.STRING,
"",
Importance.LOW,
MONGO_ADDITIONAL_CONNECTION_STRING_PARAMS_DOC
).define(
WINDOW_BLOOM_FILTER_COUNT_CONFIG,
Type.INT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public static CqlSession connect(
public static MongoClient connect(
final String hostname,
@Nullable final String clientId,
@Nullable final String clientSecret
@Nullable final String clientSecret,
final String additionalParams
) {
final String connectionString;
if (clientId != null && clientSecret != null) {
Expand All @@ -115,12 +116,16 @@ public static MongoClient connect(
connectionString = hostname;
}

final String connectionStringWithParams = additionalParams.equals("")
? connectionString
: connectionString + "/?" + additionalParams;

ServerApi serverApi = ServerApi.builder()
.version(ServerApiVersion.V1)
.build();

MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(new ConnectionString(connectionString))
.applyConnectionString(new ConnectionString(connectionStringWithParams))
.readConcern(ReadConcern.MAJORITY)
.writeConcern(WriteConcern.MAJORITY)
.serverApi(serverApi)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static org.hamcrest.Matchers.hasItems;

import dev.responsive.kafka.api.ResponsiveKafkaStreams;
import dev.responsive.kafka.api.config.ResponsiveConfig;
import dev.responsive.kafka.api.config.StorageBackend;
import dev.responsive.kafka.testutils.ResponsiveConfigParam;
import dev.responsive.kafka.testutils.ResponsiveExtension;
Expand Down Expand Up @@ -72,7 +73,7 @@
public class MinimalIntegrationTest {

@RegisterExtension
static ResponsiveExtension EXTENSION = new ResponsiveExtension(StorageBackend.CASSANDRA);
static ResponsiveExtension EXTENSION = new ResponsiveExtension(StorageBackend.MONGO_DB);

private static final String INPUT_TOPIC = "input";
private static final String OUTPUT_TOPIC = "output";
Expand Down Expand Up @@ -160,6 +161,10 @@ private Map<String, Object> getMutableProperties() {
properties.put(STORE_FLUSH_RECORDS_TRIGGER_CONFIG, 1);
properties.put(COMMIT_INTERVAL_MS_CONFIG, 1);

properties.put(
ResponsiveConfig.MONGO_ADDITIONAL_CONNECTION_STRING_PARAMS_CONFIG, "maxIdleTimeMs=60000"
);

properties.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 1);
properties.put(consumerPrefix(ConsumerConfig.METADATA_MAX_AGE_CONFIG), "1000");
properties.put(consumerPrefix(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG), "earliest");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void shouldDefaultToResponsiveStoresWhenUsingDsl() throws Exception {

// Then:
try (
final var mongoClient = SessionUtil.connect(mongo.getConnectionString(), null, null);
final var mongoClient = SessionUtil.connect(mongo.getConnectionString(), null, null, "");
final var deserializer = new StringDeserializer();
) {
final List<String> dbs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ private RemoteKVTable<?> remoteKVTable(
final var mongoClient = SessionUtil.connect(
hostname,
user,
pass == null ? null : pass.value()
pass == null ? null : pass.value(),
""
);
table = new MongoKVTable(
mongoClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void before(
name = info.getDisplayName().replace("()", "");

final String mongoConnection = (String) props.get(MONGO_ENDPOINT_CONFIG);
client = SessionUtil.connect(mongoConnection, null, null);
client = SessionUtil.connect(mongoConnection, null, null, "");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void before(
name = info.getDisplayName().replace("()", "");

final String mongoConnection = (String) props.get(MONGO_ENDPOINT_CONFIG);
client = SessionUtil.connect(mongoConnection, null, null);
client = SessionUtil.connect(mongoConnection, null, null, "");
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void before(
name = info.getDisplayName().replace("()", "");

final String mongoConnection = (String) props.get(MONGO_ENDPOINT_CONFIG);
client = SessionUtil.connect(mongoConnection, null, null);
client = SessionUtil.connect(mongoConnection, null, null, "");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void before(
name = info.getDisplayName().replace("()", "");

final String mongoConnection = (String) props.get(MONGO_ENDPOINT_CONFIG);
client = SessionUtil.connect(mongoConnection, null, null);
client = SessionUtil.connect(mongoConnection, null, null, "");

partitioner = new WindowSegmentPartitioner(10_000L, 1_000L, false);
segment = partitioner.segmenter().activeSegments(0, 100).get(0);
Expand Down
Loading