-
Notifications
You must be signed in to change notification settings - Fork 18.9k
choose rpc code to determine status code #32122
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
choose rpc code to determine status code #32122
Conversation
vdemeester
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
daemon/cluster/utils.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
daemon/cluster/utils.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a mouthful.
newHTTPErrorFromGRPC
daemon/cluster/utils.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect. 408 is only used when the client doesn't send a complete request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A 504 would work here.
daemon/cluster/utils.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
daemon/cluster/utils.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo s/non-exsiting/non-existing/ :joy:
|
Looks like some tests need updating |
cpuguy83
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for moving this, seems like a better place to handle it, and in line with the changes requested in #32144
api/server/httputils/errors.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
api/server/httputils/errors.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not implemented? Wouldn't this be StatusForbidden?
api/server/httputils/errors.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you propose instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
500
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
api/server/httputils/errors.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be conflict, I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not 400?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
400 works too, just not 500.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, technically I think 400 is for the HTTP server and shouldn't be used by us, but we do :)
api/server/httputils/errors.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OutOfRange should just be mapped to 400 Bad Request.
api/server/httputils/errors.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is swarm or containerd returning this ever? If so, is the HTTP code documented in the API?
api/server/httputils/errors.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can move this to the default case
api/server/httputils/errors.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this would ever happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? ☀️ |
api/server/httputils/errors.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <allen.sun@daocloud.io>
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably we need to update the swagger.yml as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 |
cpuguy83
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
thaJeztah
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, LGTM as well 😅
Signed-off-by: allencloud allen.sun@daocloud.io
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)