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

Errors: Update errutil to be compatible with k8s errors #87605

Merged
merged 13 commits into from May 20, 2024
Merged

Conversation

ryantxu
Copy link
Member

@ryantxu ryantxu commented May 10, 2024

This PR updates our existing errutil package so that the errors render properly when returned in an apiserver.

To support this behavior, we made three changes:

  1. implement Status() method that returns a metav1.Status{} object
  2. Replace our "reason" strings with the k8s versions. This change actually effects existing behavior, but I think better than continuing to support multiple flavors of each error.

TODO? (but not this PR) The k8s docs suggest that the error details can be anything, however it is not clear how to implement that. This PR just shoves the values into the causes arrary 🤷🏻

@grafana-delivery-bot grafana-delivery-bot bot added this to the 11.1.x milestone May 10, 2024
// StatusNotFound means that the server does not have any
// corresponding document to return to the request.
// HTTP status code 404.
StatusNotFound CoreStatus = "Not found"
StatusNotFound CoreStatus = CoreStatus(metav1.StatusReasonNotFound)
Copy link
Member Author

Choose a reason for hiding this comment

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

^^ this is a real change in the response. The k8s reason strings are capital camel case sentences, and our existing reasons have spaces.

It seems better to just use the k8s flavors 🤷🏻

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 I'm not sure about this - This package is used for user-facing errors; the whole point is that messages returned here should be human readable. I don't think we should be exposing these k8s implementation details to end users.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ya -- torn on this also. If the train was not heading towards apiserver for everything I would agree. BUT given that the goal is to remove everythign from /api -- should we just get our UI elements ready to add spaces to camel case reasons?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I tend to agree that switching to the "standard" error text format makes sense, and that we are going to need to figure out how to present the error messages in a friendly format on the frontend (including i18n) so passing "user readable" strings through from the backend makes less sense to me than having standard strings and a frontend switch case to turn them into human-readable strings.

@ryantxu ryantxu changed the title Draft: Make errutil more k8s friendly Errors: Update errutil to be compatible with k8s errors May 15, 2024
@ryantxu ryantxu added no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes labels May 15, 2024
@@ -105,14 +104,14 @@ func (r *queryREST) Connect(ctx context.Context, name string, opts runtime.Objec
Message: "datasource not found",
}}
}
responder.Error(convertToK8sError(err))
responder.Error(err)
Copy link
Member Author

Choose a reason for hiding this comment

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

🎉 the errors are now returned properly -- rather than getting returned as 500, it is now 400

@ryantxu ryantxu marked this pull request as ready for review May 15, 2024 09:09
@ryantxu ryantxu requested review from a team as code owners May 15, 2024 09:09
@ryantxu ryantxu merged commit 6d10797 into main May 20, 2024
12 checks passed
@ryantxu ryantxu deleted the errutil-k8s branch May 20, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/backend no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants