-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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/v2: add path and method to API v2 logs #2261
api/v2: add path and method to API v2 logs #2261
Conversation
@@ -124,8 +124,6 @@ func NewAPI( | |||
openAPI.SilenceGetSilencesHandler = silence_ops.GetSilencesHandlerFunc(api.getSilencesHandler) | |||
openAPI.SilencePostSilencesHandler = silence_ops.PostSilencesHandlerFunc(api.postSilencesHandler) | |||
|
|||
openAPI.Logger = func(s string, i ...interface{}) { level.Error(api.logger).Log(i...) } |
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.
After reading through the openapi code, it seems that it isn't used anywhere because we're not using *github.com/prometheus/alertmanager/api/v2/restapi.Server
directly.
In any case the code here didn't work as expected, it should have been level.Error(api.logger).Log("msg", fmt.Sprintf(s, i...))
.
api/v2/api.go
Outdated
@@ -216,18 +214,20 @@ func (api *API) getAlertsHandler(params alert_ops.GetAlertsParams) middleware.Re | |||
// are no alerts present | |||
res = open_api_models.GettableAlerts{} | |||
ctx = params.HTTPRequest.Context() | |||
|
|||
logger = log.With(api.logger, "handler", "alerts", "methods", "GET") |
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.
do we have to hardcode those info?
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.
You could probably extract some of them from params.HTTPRequest
.
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 the feedback! I've updated the code.
When an API v2 handler logged a message, the log wouldn't include the path and method. Since different handlers perform the same validations (e.g. matchers for alerts and silences), it isn't easy to know which handler was invoked (though the logged filename + line number provides a hint). Signed-off-by: Simon Pasquier <[email protected]>
10e926f
to
2b845ab
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.
For what my review is worth this looks good to me.
In prometheus/prometheus log |
Signed-off-by: Simon Pasquier <[email protected]>
When an API v2 handler logged a message, the log wouldn't include the
path and method. Since different handlers perform the same
validations (e.g. matchers for alerts and silences), it isn't easy to
know which handler was invoked (though the logged filename + line number provides a hint).