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

Replace cassandra session wrapper with jdk proxy #8041

Merged
merged 3 commits into from
Mar 16, 2023

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Mar 13, 2023

Resolves #8026

@laurit laurit requested a review from a team as a code owner March 13, 2023 17:41
Copy link
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

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

Other than a few nitpicky readability comments, looks good!

if (method.getParameterTypes()[0] == String.class) {
String query = (String) args[0];
return execute(session, query);
} else if (method.getParameterTypes()[0] == Statement.class) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know the datastax class tree well enough to say if this matters, but would method.getParameterTypes()[0].isAssignableFrom(Statement.class) be a little safer or future-proof?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really. If in the future there is a method that accepts a subclass of Statement there must be a reason why this method was created, some kind of behavioural difference from the one that just accepts Statement. If we'd accept subclasses of Statement here we would risk loosing this behavioural difference as our instrumentation delegates to the method that accepts plain Statement.

session.getClass().getClassLoader(),
interfaces.toArray(new Class<?>[0]),
(proxy, method, args) -> {
if ("execute".equals(method.getName()) && method.getParameterCount() == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The getParameterCount() == 1 check is duplicated in each if. If you pulled those up and returned early it could simplify a little bit.

Then, knowing that you've guarded against multiple or zero params, you can pull the method.getParameterTypes()[0] into a local variable to further simplify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you should view the fact that we instrument only methods that take a single parameter as a coincidence. For example the methods that we instrument delegate to https://docs.datastax.com/en/drivers/java/4.0/com/datastax/oss/driver/api/core/session/Session.html#execute-RequestT-com.datastax.oss.driver.api.core.type.reflect.GenericType- that we don't instrument, but probably should for completeness.

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

Successfully merging this pull request may close these issues.

cassandra-quarkus-client TracingCqlSession cast error
3 participants