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

Support passing a connection URL to Trino CLI #12587

Merged
merged 8 commits into from Jul 19, 2023

Conversation

nineinchnick
Copy link
Member

@nineinchnick nineinchnick commented May 28, 2022

Description

Allow the Trino CLI to accept an URL parameter instead of a (sometimes long) list of options. URLs are parsed same as JDBC URLs, but they don't have the jdbc: prefix. If any parameters are set in the URL, they can't be also set as options. But they can be present in the config file because these are only treated as default values and can be overridden.

Is this change a fix, improvement, new feature, refactoring, or other?
new feature

Is this a change to the core query engine, a connector, client library, or the SPI interfaces? (be specific)
cli

How would you describe this change to a non-technical end user or system administrator?
Trino CLI can accept an URL parameter.

Related issues, pull requests, and links

Documentation

( ) No documentation is needed.
(x) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

( ) No release notes entries required.
(x) Release notes entries required with the following suggested text:

# CLI
* Trino CLI now accepts a single URL with parameters as an alternative to passing command line arguments. ({issue}`12587`)

# JDBC
* Connection parameter validation errors are now actionable ({issue}`12587`)

@cla-bot cla-bot bot added the cla-signed label May 28, 2022
@github-actions github-actions bot added docs jdbc Relates to Trino JDBC driver labels May 28, 2022
Copy link
Member Author

@nineinchnick nineinchnick left a comment

Choose a reason for hiding this comment

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

To the reviewers, I understand this is pretty big and I'll try to split it up into multiple smaller commits.

@nineinchnick nineinchnick force-pushed the cli-urls branch 2 times, most recently from 6890ddd to 2110ae1 Compare May 30, 2022 09:39
.map(CommandLine.Model.OptionSpec::longestName)
.collect(Collectors.toList());

TrinoUri uri = clientOptions.getTrinoUri(providedOptions);
Copy link
Member Author

Choose a reason for hiding this comment

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

This has a nice side effect of always converting all CLI options into URLs that can be used as JDBC URLs. Would it be useful to log the resulting connection URL on a debug level?

Copy link
Member

Choose a reason for hiding this comment

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

If it won't expose the password I'm for it.

@nineinchnick
Copy link
Member Author

To the reviewers, I understand this is pretty big and I'll try to split it up into multiple smaller commits.

Done. If there's anything else I can do to make this easier to review please let me know.

@findepi findepi removed their request for review May 30, 2022 13:03
Copy link
Member

@mosabua mosabua left a comment

Choose a reason for hiding this comment

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

Docs only need minor changes. From the behaviour side of things I am not sure we want the new behavior to be the default and hence the one we use in the documentation.

And importantly I would like confirmation that the old behavior will continue to work... and we will continue to ensure that with test coverage.

docs/src/main/sphinx/installation/cli.rst Outdated Show resolved Hide resolved
docs/src/main/sphinx/installation/cli.rst Outdated Show resolved Hide resolved
@nineinchnick
Copy link
Member Author

Docs only need minor changes. From the behaviour side of things I am not sure we want the new behavior to be the default and hence the one we use in the documentation.

Let's wait for others to chime in about this. I made it the default since it's shorter. Users won't have to think about the option name (was it server, url, address or host?) and generally should be easier to type.

And importantly I would like confirmation that the old behavior will continue to work... and we will continue to ensure that with test coverage.

Yes, no existing behavior should change and there are lots of tests for that. I added a few test cases with URLs.

@willmostly
Copy link
Contributor

Useful feature for debugging @nineinchnick, looking forward to this!

@mosabua
Copy link
Member

mosabua commented May 31, 2022

Docs only need minor changes. From the behaviour side of things I am not sure we want the new behavior to be the default and hence the one we use in the documentation.

Let's wait for others to chime in about this. I made it the default since it's shorter. Users won't have to think about the option name (was it server, url, address or host?) and generally should be easier to type.

My concern is that it is NOT easier to type for any real use case beyond the URL only. In fact you need to know how to format the JDBC URL string.

My other questions would be .. how much does this work if you combine JDBC string and other parameters. Are all parameters from both input methods combined somehow? What if there are collisions .. does on override the other? Which one wins out? We need to make sure we understand that and also document it.

@nineinchnick
Copy link
Member Author

My concern is that it is NOT easier to type for any real use case beyond the URL only. In fact you need to know how to format the JDBC URL string.

I meant it's easier only in the most basic use case, trino --server https://some.host --catalog bigdata --schema foo vs trino https://some.host/bigdata/foo.

My other questions would be .. how much does this work if you combine JDBC string and other parameters. Are all parameters from both input methods combined somehow? What if there are collisions .. does on override the other? Which one wins out? We need to make sure we understand that and also document it.

You can combine options, start with the URL only and add more options instead of URL parameters. You can't specify the same parameter both in the URL and as a CLI option. There's one sentence clarifying this in the docs update.

@nineinchnick
Copy link
Member Author

@electrum PTAL

@nineinchnick nineinchnick force-pushed the cli-urls branch 2 times, most recently from ff31cda to 158310b Compare July 18, 2023 06:13
@nineinchnick
Copy link
Member Author

Rebased to include the new KerberosConstrainedDelegation parameter. I actually found and fixed one issue after the last rebase, where I missed hostnameInCertificate in one place. Maybe we're missing a test for this.

sslUseSystemTrustStore.orElse(false));
}

public void setupClient(OkHttpClient.Builder builder)
Copy link
Contributor

Choose a reason for hiding this comment

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

in both of the usages we are passing new, fresh OkHttpClient.Builder here.

Can we instead do: public OkHttpClient.Builder toHttpClientBuilder() ?

this.sslSetup = OkHttpUtil::setupInsecureSsl;
OkHttpClient.Builder builder = new OkHttpClient.Builder();
try {
sslSetup = uri.getSetupSsl();
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this sslSetup at all?

Isn't uri.setupClient(builder); already doing required SSL initialization?

@nineinchnick nineinchnick force-pushed the cli-urls branch 2 times, most recently from 9bbadd6 to 78f2845 Compare July 18, 2023 16:24
Copy link
Member

@mosabua mosabua left a comment

Choose a reason for hiding this comment

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

Just a whole bunch of minor wording improvements .. essentially though this is good to go. BIG change!

@wendigo
Copy link
Contributor

wendigo commented Jul 19, 2023

There is related failure in suite-ldap @nineinchnick:

tests               | Expecting throwable message:
tests               |   "Authentication using username/password requires SSL to be enabled"
tests               | to contain:
tests               |   "TLS/SSL is required for authentication with username and password"
tests               | but did not.

@wendigo
Copy link
Contributor

wendigo commented Jul 19, 2023

@nineinchnick can you update release notes:

Trino CLI now accepts a single URL with parameters as an alternative to passing command line arguments.

@@ -46,7 +46,7 @@ databases:
jdbc_driver_class: ${databases.presto.jdbc_driver_class}
jdbc_url: jdbc:trino://${databases.presto.host}:${databases.presto.port}/hive/tpcds
jdbc_user: hive
jdbc_password: "***empty***"
jdbc_password: ""
Copy link
Contributor

Choose a reason for hiding this comment

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

<3

@wendigo wendigo requested a review from mosabua July 19, 2023 14:28
Copy link
Member

@mosabua mosabua left a comment

Choose a reason for hiding this comment

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

All good now. Lets ship this!

@wendigo
Copy link
Contributor

wendigo commented Jul 19, 2023

All tests have passed. I have a small refactor around creating http client used by the jdbc and client but I’ll follow up in a separate PR. Merging this as-is for now. Thanks @nineinchnick for improving CLI and making it consistent with JDBC driver.

@wendigo wendigo merged commit 86217f1 into trinodb:master Jul 19, 2023
101 checks passed
@nineinchnick nineinchnick deleted the cli-urls branch July 19, 2023 17:58
@nineinchnick
Copy link
Member Author

BTW there's one last improvement to be done in JDBC error messages, when the value is being converted, for example from a string to a boolean, the error now looks like:

Connection property SSL value is invalid: 2

But we could say how the expected values look like, for example:

Connection property SSL value '2' is invalid, expected 'true' or 'false'

I'll follow up with another small PR.

@github-actions github-actions bot added this to the 423 milestone Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed docs jdbc Relates to Trino JDBC driver
Development

Successfully merging this pull request may close these issues.

Pass a connection URL to Trino CLI
6 participants