choose rpc code to determine status code#32122
Conversation
There was a problem hiding this comment.
I'd like to not propagate this usage.
At the very least we can catch grpc errors in the API package and produce the correct error code from there.
There was a problem hiding this comment.
Thanks for your feedback. Like you mentioned, I tried to move that part into api/server/httputils/errors.go. PTAL
@cpuguy83
a1ecc6f to
946ce45
Compare
There was a problem hiding this comment.
This is a mouthful.
newHTTPErrorFromGRPC
There was a problem hiding this comment.
This is incorrect. 408 is only used when the client doesn't send a complete request.
There was a problem hiding this comment.
Conflict is a specific http error. This should be a 400 or some other error. There is already an open issue about the incorrect usage of 409. @justincormack
There was a problem hiding this comment.
This is a specific http error that doesn't map to the same thing as the GRPC error code.
cd2e853 to
d2d607a
Compare
6263cdc to
6b4de0f
Compare
There was a problem hiding this comment.
typo s/non-exsiting/non-existing/ :joy:
|
Looks like some tests need updating |
There was a problem hiding this comment.
Can we move this up to top of the default case and instead pass the error directly rather than checking the error string?
Then we can gate the horrid string checking pattern currently above this with something like:
if statusCode == http.StatusInternalServerError {
// horrible string parser
}There was a problem hiding this comment.
Then we can gate the horrid string checking pattern currently above this with something like:
Sorry, actually I cannot follow this one.
There was a problem hiding this comment.
Basically, move this above this stuff:
{"not found", http.StatusNotFound},
{"cannot find", http.StatusNotFound},
{"no such", http.StatusNotFound},
{"bad parameter", http.StatusBadRequest},
{"no command", http.StatusBadRequest},
{"conflict", http.StatusConflict},
{"impossible", http.StatusNotAcceptable},
{"wrong login/password", http.StatusUnauthorized},
{"unauthorized", http.StatusUnauthorized},
{"hasn't been activated", http.StatusForbidden},
{"this node", http.StatusServiceUnavailable},
{"needs to be unlocked", http.StatusServiceUnavailable},
{"certificates have expired", http.StatusServiceUnavailable},
And only check that stuff if the parsed statusCode from the grpc check is 500.
There was a problem hiding this comment.
Why not implemented? Wouldn't this be StatusForbidden?
There was a problem hiding this comment.
This does not seem like the correct code.
This is used when the server is acting as a proxy. In this case something just went really wrong. I think this would just be a 500.
There was a problem hiding this comment.
While the engine may technically be acting as a proxy to containerd/swarm, I don't think this is something that should propagate up to the user.
There was a problem hiding this comment.
What do you propose instead?
There was a problem hiding this comment.
Yeah, in failed test:
11:17:28 docker_api_swarm_test.go:342:
11:17:28 c.Assert(status, checker.Equals, http.StatusInternalServerError, check.Commentf("deadline exceeded", string(out)))
11:17:28 ... obtained int = 504
11:17:28 ... expected int = 500
11:17:28 ... deadline exceeded%!(EXTRA string={"message":"rpc error: code = 4 desc = context deadline exceeded"}
11:17:28 )
11:17:28
11:17:28 [d0f11ccd4b298] exiting daemon
Original code is 500
There was a problem hiding this comment.
This should be conflict, I think
There was a problem hiding this comment.
well, technically I think 400 is for the HTTP server and shouldn't be used by us, but we do :)
There was a problem hiding this comment.
We probably shouldn't make up new status code usages here. The description of this status does not seem like anything we'd ever require.
There was a problem hiding this comment.
OutOfRange should just be mapped to 400 Bad Request.
There was a problem hiding this comment.
Is swarm or containerd returning this ever? If so, is the HTTP code documented in the API?
There was a problem hiding this comment.
Can move this to the default case
There was a problem hiding this comment.
I don't think this would ever happen?
There was a problem hiding this comment.
Yeah, updated. PTAL
f29dbe1 to
02b47ad
Compare
|
Yes, some tests need updating. @thaJeztah And I think I still need to update docs/api/version-history.md, WDYT? |
02b47ad to
b0936f9
Compare
|
I am afraid such kind of change may influence docker-py, here is some evidence which docekr-py test failed: Any input for this, or what should I do for this? @shin- |
4101773 to
30a8589
Compare
|
docker/docker-py#1621 was merged; can you try updating this PR? |
|
Thanks for your feedback, @thaJeztah The status code test error in docker-py never happens. While another error in docker-py occurs: I am still searching the error's root cause. |
|
@allencloud - I have a PR that is also blocked on the test_prune_images failure, which seems to be unrelated to the content of my PR. I haven't been able to reproduce it locally, but will share anything I find. |
30a8589 to
56fae16
Compare
|
Thanks @alfred-landrum In addition, I think we still to add more status code change in version_history.md, right? |
dffd995 to
3b5d5c4
Compare
|
Any update? ☀️ |
There was a problem hiding this comment.
This string check is probably more expensive, and certainly more fragile, than just checking statusCodeFromGRPCError in all cases.
If we move this to the top of the default case, in many cases we won't have to mess around with this string handling.
so...
default:
statusCode = statusCodeFromGRPCError(err)
if statusCode == http.StatusInternalServerError {
// nasty string comparison stuff
}There was a problem hiding this comment.
Thanks for your feedback. @cpuguy83 I think what you said is reasonable. Thanks a lot.
While I think CI fails according to accident. Can you re-trigger that? @thaJeztah
93429fc to
224dec0
Compare
Signed-off-by: allencloud <[email protected]>
224dec0 to
f257f77
Compare
|
Does the change I added seem OK for you, @cpuguy83 ? |
| * `DELETE /secrets/(name)` now returns status code 404 instead of 500 when the secret does not exist. | ||
| * `POST /secrets/create` now returns status code 409 instead of 500 when creating an already existing secret. | ||
| * `POST /secrets/(name)/update` now returns status code 400 instead of 500 when updating a secret's content which is not the labels. | ||
| * `POST /nodes/(name)/update` now returns status code 400 instead of 500 when demoting last node fails. |
There was a problem hiding this comment.
Probably we need to update the swagger.yml as well?
There was a problem hiding this comment.
I think there is no need to update swagger.yml.
|
@allencloud perfect! |
|
@cpuguy83 LGTY? feel free to merge if yes |
|
Just needs the changes requested by @thaJeztah |
|
I think there is no need to update swagger.yml, since in swagger.yml no change will be involved. So there will be no change for swagger.yml. |
Even better, thanks for checking 👍 |
Signed-off-by: allencloud [email protected]
Since docker daemon use gRPC to communicate with swarmkit, so when docker daemon accepts http request and transfers to swarmkit side, the at last, swarmkit will return a gRPC code to docker daemon. For the user's request, we definitely need to return a response with an HTTP status code. This PR hopes to determine the http status code from the gRPC code.
this fixes #31909
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)