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

api: acl bootstrap errors aren't 500 #6421

Merged
merged 4 commits into from
Nov 20, 2019
Merged

Conversation

notnoop
Copy link
Contributor

@notnoop notnoop commented Oct 4, 2019

Noticed that ACL endpoints return 500 status code for user errors. This
is confusing and can lead to false monitoring alerts.

Here, I introduce a concept of RPCCoded errors to be returned by RPC
that signal a code in addition to error message. Codes for now match
HTTP codes to ease reasoning.

Here, I start with ACL endpoints, but we can propagate status code for other endpoints as necessary.

I see that we have special cased permission and not found errors for some endpoints, but I didn't want to follow this pattern as it seems brittle and wrapping seems like too much magic for my taste.

# before
$ nomad acl bootstrap
Error bootstrapping: Unexpected response code: 500 (ACL bootstrap already done (reset index: 9))

# after
$ nomad acl bootstrap
Error bootstrapping: Unexpected response code: 400 (ACL bootstrap already done (reset index: 9))

@preetapan preetapan added this to the 0.10.1 milestone Oct 4, 2019
@schmichael schmichael modified the milestones: 0.10.1, 0.10.2 Nov 5, 2019
}
if out == nil {
return fmt.Errorf("cannot find token %s", token.AccessorID)
return structs.NewErrRPCCodedf(400, "cannot find token %s", token.AccessorID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a 404?

Mahmood Ali added 3 commits November 19, 2019 15:51
Noticed that ACL endpoints return 500 status code for user errors.  This
is confusing and can lead to false monitoring alerts.

Here, I introduce a concept of RPCCoded errors to be returned by RPC
that signal a code in addition to error message.  Codes for now match
HTTP codes to ease reasoning.

```
$ nomad acl bootstrap
Error bootstrapping: Unexpected response code: 500 (ACL bootstrap already done (reset index: 9))

$ nomad acl bootstrap
Error bootstrapping: Unexpected response code: 400 (ACL bootstrap already done (reset index: 9))
```
@@ -25,6 +26,8 @@ const (
ErrUnknownJobPrefix = "Unknown job"
ErrUnknownEvaluationPrefix = "Unknown evaluation"
ErrUnknownDeploymentPrefix = "Unknown deployment"

errRPCCodedErrorPrefix = "RPC_ERROR::"
Copy link
Member

Choose a reason for hiding this comment

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

A quick rg --fixed-strings 'RPC Error: ' yielded no results, so we could use that instead. My concern is that I'd love to start using this pattern more widely, but it could easily leak into CLI or client agent logs if we aren't careful about our checks/conversions.

Suggested change
errRPCCodedErrorPrefix = "RPC_ERROR::"
errRPCCodedErrorPrefix = "RPC Error: "

Not a big deal either way. Users aren't going to get upset from seeing RPC_ERROR:: once or twice if it ever even happens. 😅

@@ -144,3 +147,31 @@ func IsErrUnknownNomadVersion(err error) bool {
func IsErrNodeLacksRpc(err error) bool {
return err != nil && strings.Contains(err.Error(), errNodeLacksRpc)
}

func NewErrRPCCoded(code int, msg string) error {
Copy link
Member

Choose a reason for hiding this comment

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

Comments on exported funcs.

@schmichael
Copy link
Member

Don't forget a changelog entry for the incorrect error code bug fix.

@preetapan preetapan merged commit 6cab787 into master Nov 20, 2019
@preetapan preetapan deleted the b-acl-bootstrap-codes branch November 20, 2019 16:36
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants