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

stop logging errors for api error responses #8

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

lieut-data
Copy link
Member

Summary

From a cursory glance, when a real error occurs, we already log something at the application layer, so there's no reason to echo every api error response as an error log too. Errors should be actionable, but these logs were not, e.g.:

access denied to templates

or:

category ID specified in input does not exist for user

This PR duplicates mattermost-community/focalboard#5022.

Ticket Link

Fixes: https://mattermost.atlassian.net/browse/MM-59325

From a cursory glance, when a real error occurs, we already log
something at the application layer, so there's no reason to echo every
api error response as an error log too. Errors should be actionable, but
these logs were not, e.g.:

> access denied to templates

or:

> category ID specified in input does not exist for user
@marianunez
Copy link
Member

From a cursory glance, when a real error occurs, we already log something at the application layer,

@lieut-data can you point to where this is happening? For the two examples provided, I don't see where the error is logged in the application layer. Worried that we may be missing seeing actual errors in the log with changing for all that call errorResponse

server/api/api.go Outdated Show resolved Hide resolved
Co-authored-by: Maria A Nunez <[email protected]>
@lieut-data
Copy link
Member Author

@lieut-data can you point to where this is happening? For the two examples provided, I don't see where the error is logged in the application layer. Worried that we may be missing seeing actual errors in the log with changing for all that call errorResponse

Oops, I didn't meant to frame it as such, @marianunez: the two examples are "non-actionable" errors, and indeed there are no additional error logs expected from the application layer. With this change, we'll still log a warning when an API returns a failure code to the client, but the default position is to assume these aren't actionable (i.e. permission issues).

There are examples of actionable errors in the app layer, e.g.:

func (a *App) initialize(skipTemplateInit bool) {
if !skipTemplateInit {
if err := a.InitTemplates(); err != nil {
a.logger.Error(`InitializeTemplates failed`, mlog.Err(err))
}
}
}

but I note they are not consistent. There are certainly opportunities for greater consistency here.

@marianunez
Copy link
Member

the two examples are "non-actionable" errors, and indeed there are no additional error logs expected from the application layer. With this change, we'll still log a warning when an API returns a failure code to the client, but the default position is to assume these aren't actionable (i.e. permission issues).

I see, makes sense. Thanks for clarifying

@@ -178,7 +178,6 @@ func (a *API) userIsGuest(userID string) (bool, error) {
// Response helpers

func (a *API) errorResponse(w http.ResponseWriter, r *http.Request, err error) {
a.logger.Error(err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

This explains the double log entries for each error

Copy link
Contributor

@Rajat-Dabade Rajat-Dabade left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@lieut-data lieut-data merged commit d6a516a into main Jul 15, 2024
6 checks passed
@lieut-data lieut-data deleted the downgrade-api-error-logs-to-warn branch July 15, 2024 13:41
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.

3 participants