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

Add POST /query endpoint and warning messages for using GET with write operations #6390

Merged
merged 1 commit into from
Apr 29, 2016

Conversation

jsternberg
Copy link
Contributor

In order to follow REST a bit more carefully, all write operations
should go through a POST in the future. We still allow read operations
through either GET or POST (similar to the Graphite /render endpoint),
but write operations will trigger a returned warning as part of the JSON
response and will eventually return an error.

Fixes #6290.

@jsternberg jsternberg added this to the 0.13.0 milestone Apr 15, 2016
@jsternberg jsternberg force-pushed the js-6290-query-post-endpoint branch 6 times, most recently from 72a62f8 to ceb69c5 Compare April 20, 2016 14:21
@@ -148,13 +151,13 @@ func (e *QueryExecutor) Close() error {
}

// ExecuteQuery executes each statement within a query.
func (e *QueryExecutor) ExecuteQuery(query *Query, database string, chunkSize int, closing chan struct{}) <-chan *Result {
func (e *QueryExecutor) ExecuteQuery(query *Query, database string, chunkSize int, readonly bool, closing chan struct{}) <-chan *Result {
Copy link
Contributor

Choose a reason for hiding this comment

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

Signature is getting lot of parameters (6 now). May want to refactor this in another PR.

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 agree. Most of this stuff is included in ExecutionContext so that can probably just be used. We're going to have to change this at some point to include the user, so I'll change it then.

@e-dard
Copy link
Contributor

e-dard commented Apr 22, 2016

@jsternberg Sending parameters on the URL is somewhat unusual for a POST request. Usually you would send the URL-encoded parameters within the body of the request.

You could achieve this by doing something like:

// client/influxdb.go

// don't add the values to u.RawQuery, then:
body := strings.NewReader(values.Encode())
req, err := http.NewRequest("POST", u.String(), body)
...

Then, in the handler where we're doing things like:

q := r.URL.Query()
pretty := q.Get("pretty") == "true"

we should be doing:

pretty := r.FormValue.Get("pretty") == "true"

which will support request that come in both via GET (with query parameters) and POST (with request body parameters).

@jsternberg
Copy link
Contributor Author

@e-dard you're right, but we do the same thing with /write. We can support both, which is what using the form value would do, but it also makes the code more complicated since GET and POST now need to be treated differently.

@e-dard
Copy link
Contributor

e-dard commented Apr 22, 2016

@jsternberg why would they need to be treated differently?

@jsternberg
Copy link
Contributor Author

jsternberg commented Apr 22, 2016

I just read the full of what you wrote and I'm likely wrong. I'll modify and try it out.

This is why skim reading isn't a real thing.

@jsternberg
Copy link
Contributor Author

@e-dard updated, but credentials still have to be in the query url since the code for that one is shared with /write. Maybe we can update that in the future, but I think that should be good enough for this one.

@jsternberg jsternberg force-pushed the js-6290-query-post-endpoint branch 3 times, most recently from 7c2137d to 86cfe40 Compare April 22, 2016 16:38
@joelegasse
Copy link
Contributor

URL parameters with POST is perfectly acceptable. It allows setting parameters and a payload separately. It also means the payload can be something other than URL-encoded parameters. We do this for /write: database, retention policy, and precision are set in the URL and the body is the text line protocol for the points. We just fixed a bug caused by using FormValue in the /write endpoint, and I'd rather not re-introduce it.

@jwilder
Copy link
Contributor

jwilder commented Apr 29, 2016

LGTM 👍

…e operations

In order to follow REST a bit more carefully, all write operations
should go through a POST in the future. We still allow read operations
through either GET or POST (similar to the Graphite /render endpoint),
but write operations will trigger a returned warning as part of the JSON
response and will eventually return an error.

Also updates the Golang client libraries to always use POST instead of
GET.

Fixes #6290.
@jsternberg jsternberg merged commit 61cdecb into master Apr 29, 2016
@jsternberg jsternberg deleted the js-6290-query-post-endpoint branch April 29, 2016 13:31
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.

None yet

4 participants