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

SQL: JDBC should validate existance of SQL url #30009

Closed
elasticmachine opened this issue Apr 19, 2018 · 8 comments
Closed

SQL: JDBC should validate existance of SQL url #30009

elasticmachine opened this issue Apr 19, 2018 · 8 comments

Comments

@elasticmachine
Copy link
Collaborator

Original comment by @costin:

Trying JDBC against a vanilla Elasticsearch, without X-Pack or SQL returns a 'weird' error:

Caused by: java.sql.SQLException: Server sent bad type [illegal_argument_exception]. Original type was [request [/_xpack/sql] contains unrecognized parameter: [mode]]. [java.lang.IllegalArgumentException: request [/_xpack/sql] contains unrecognized parameter: [mode]
	at org.elasticsearch.rest.BaseRestHandler.handleRequest(BaseRestHandler.java:92)
	at org.elasticsearch.rest.RestController.dispatchRequest(RestController.java:239)
	at org.elasticsearch.rest.RestController.tryAllHandlers(RestController.java:335)
	at org.elasticsearch.rest.RestController.dispatchRequest(RestController.java:173)

Notice that the error complains an obscure mode parameter when in fact the endpoint does not exist and hence the query is handled by the base handler which triggers the exception above.

The driver should be smarter than this and return an appropriate error message.
There are several approaches:

  1. validate the connection

Before doing something on a connection do some kind of validation call (HTTP HEAD) or something along those lines. The issue however is that this adds up over time (we keep validating each connection so x2 calls) and it's also fairly light - we only know the endpoint is there, nothing beyond that.

  1. recognize the exception pattern

Except the exception and handle it appropriately - this is similar to the security case, where we can look at the body and understand what went wrong without having to waste any extra calls. It's also something we can extend long term for things like not being able to open a connection, etc... (client issues).

My preference would be for 2.
Thoughts?

@elasticmachine
Copy link
Collaborator Author

Original comment by @nik9000:

+1 for a better error message. Probably worth having something for when SQL is disabled or not installed. I think we already have something for when SQL's license isn't valid, but I imagine we don't test the CLI with it so I expect the error message isn't great.

@bleskes
Copy link
Contributor

bleskes commented Jun 15, 2018

A nice error message saying xpack needs to be installed is always nicer then a cryptic internal message. FixedItFriday is in favour of implementing.

PS - this specific error is weird - it should complain about a path not being registered.

@tvernum
Copy link
Contributor

tvernum commented Jun 15, 2018

PS - this specific error is weird - it should complain about a path not being registered.

I believe it's just hitting RestIndexAction.
https://github.com/elastic/elasticsearch/blob/v6.3.0/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java#L41

The rest controlled doesn't care that _xpack is not a valid index name, so when RestSqlQueryAction isn't registered, a POST /_xpack/sql will end up routing to RestIndexAction.

@tvernum
Copy link
Contributor

tvernum commented Jun 15, 2018

In setup-passwords we implemented a similar check that xpack exists, and security is enabled (because those were actual problems that users were having)
https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/esnative/tool/SetupPasswordTool.java#L355

@costin
Copy link
Member

costin commented Jun 15, 2018

Thanks for the pointer @tvernum (I see the familiar JDK HttpUrlConnection being used).
We're likely to end up with something quite similar.

Cheers,

@pendext
Copy link
Contributor

pendext commented Sep 7, 2018

I'd like to pick this issue up.

@astefan
Copy link
Contributor

astefan commented Oct 25, 2018

Master: a7e08f4
6.6.0: 12e1806

@astefan astefan closed this as completed Oct 25, 2018
@astefan astefan added v7.0.0 and removed help wanted adoptme labels Oct 25, 2018
@astefan
Copy link
Contributor

astefan commented Oct 25, 2018

Backported to 6.5.x: 8d83b2d

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

No branches or pull requests

8 participants