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

Include support for comma seperated strings for basic.contact-points #1897

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from

Conversation

utkuaydn
Copy link

@utkuaydn utkuaydn commented Dec 4, 2023

The motivation for the PR is that in my project while using environment variables for the configuration via a Helm chart, I am unable to pass an array as an environment variable because it ends up as a string in the application configuration. Please let me know if I missed anything in the PR. I have already signed the CLA.

@utkuaydn
Copy link
Author

utkuaydn commented Feb 16, 2024

This has been sitting here for a while, can anyone take a look? @absurdfarce

Copy link
Contributor

@aratno aratno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a unit test? I'd go about this by extracting the contact points behavior to a method in SessionBuilder, and testing that. There are also quite a few failing unit tests, so run mvn clean verify locally to see those. As a project, we're working on getting CI moved over to the new repo under ASF.

In terms of behavior - I'd prefer if we permitted lists but expanded comma-separated entries, so providing a list like this:

["a,b", "c"]

yielded contact points:

["a", "b", "c"]

The current implementation of the patch could change the interpretation of lists for existing users, which we shouldn't break. But individual hostnames shouldn't include commas, so would be safe to split those.

# This must be a list of strings with each contact point specified as "host:port". If the host is
# a DNS name that resolves to multiple A-records, all the corresponding addresses will be used. Do
# not use "localhost" as the host name (since it resolves to both IPv4 and IPv6 addresses on some
# This must be a list of strings or a comma seperated string with each contact point specified as "host:port".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# This must be a list of strings or a comma seperated string with each contact point specified as "host:port".
# This must be a list of strings or a comma separated string with each contact point specified as "host:port".

Copy link
Contributor

@aratno aratno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm revising my review here - I think it would be confusing for users if some list-based configs supported comma-delimited values, and others didn't. You can set contact points using the programmatic config loader like this:

List<String> contactPoints = new ArrayList();
contactPoints.add("host1");
DriverConfigLoader configLoader = new DefaultProgrammaticDriverConfigLoaderBuilder()
        .withStringList(DefaultDriverOption.CONTACT_POINTS, contactPoints)
        .build();
try (CqlSession session = CqlSession.builder().withConfigLoader(configLoader).build()) {
    // ...
}

I think we should encourage use of the programmatic builder in cases like your example, rather than creating new syntax for them.

@utkuaydn
Copy link
Author

utkuaydn commented Feb 23, 2024

I understand your point of view but the fact is that the approach you are suggesting is unusable with environment variables and configmaps from a HOCON point of view. Moreover, in our case, we are not using the library directly, but rather a Pekko library that uses this driver. So even if we could have one environment variable for multiple contact points, we cannot build a CqlSession and pass it along as an underlying session to the Pekko connector. Also, about the first review you posted, I don't think having ["a,b", "c"] makes much sense because I doubt that users will have comma-separated items and other single items in the list at the same time.

@aratno
Copy link
Contributor

aratno commented Feb 27, 2024

Is there a reason you can't configure Pekko to use a custom session? It looks like that should be possible from this documentation: https://pekko.apache.org/docs/pekko-connectors/current/cassandra.html#custom-session-creation

You can create a custom CqlSessionProvider that sets contact points based on the environment: https://pekko.apache.org/api/pekko-connectors/snapshot/org/apache/pekko/stream/connectors/cassandra/CqlSessionProvider.html

The main drawbacks of the implementation in this PR are:

  1. Changing the parsing behavior of basic.contact-points could break existing client configurations
  2. Allowing some list-typed configurations to support comma-separated strings when others don't is confusing for users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants