[mender-client] Missing request_id in logs after customer device being dismissed/rejected
Activity
Lluis Campos September 19, 2022 at 12:19 PM
Mikael Torp-Holte August 18, 2022 at 11:54 AMEdited
To me it doesnt make sense to have it if request id is absent. There is already a check for serverErrMsg
https://github.com/mendersoftware/mender/pull/1026
in case rest agrees ^
Maciej Tomczuk August 17, 2022 at 7:54 PM
This part of code is responsible for appending request_id to logs in mender client - theoretically we might add it only if header exists:
// APIError is an error type returned after receiving an error message from the
// server. It wraps a regular error with the request_id - and if
// the server returns an error message, this is also returned.
type APIError struct {
error
reqID string
serverErrMsg string
}
func NewAPIError(err error, resp *http.Response) *APIError {
a := APIError{
error: err,
reqID: resp.Header.Get("request_id"),
}
if resp.StatusCode >= 400 && resp.StatusCode < 600 {
a.serverErrMsg = unmarshalErrorMessage(resp.Body)
}
return &a
}
func (a *APIError) Error() string {
err := fmt.Sprintf("(request_id: %s): %s", a.reqID, a.error.Error())
if a.serverErrMsg != "" {
return err + fmt.Sprintf(" server error message: %s", a.serverErrMsg)
}
return err
}
Maciej Tomczuk August 17, 2022 at 7:42 PM
@Mikael Torp-Holte thanks for reviewing this! @Lluis Campos do you think it makes sense to remove `request_id` from mentioned logs?
Mikael Torp-Holte August 17, 2022 at 3:35 PMEdited
@Maciej Tomczuk
As it turns out, if the device is not authenticated then the backend will reply with an empty body:
https://docs.mender.io/api/#device-api-device-inventory-assign-attributes-responses
So technically its not a bug, even though it seems that way.
Either we can cease to append the "request_id" string if the header does not exist (client), or we add the header to responses with respect to this and similar endpoints (backend). (we might even ignore this issue entirely?)
thoughts?
Details
Assignee
Mikael Torp-HolteMikael Torp-HolteReporter
Maciej TomczukMaciej TomczukLabels
Priority
LowDays in progress
0Fix versions
Backlog
yes
Details
Details
Assignee
Reporter
Labels
Priority
Days in progress
Fix versions
Backlog
Zendesk Support
Linked Tickets
Zendesk Support
Linked Tickets
Zendesk Support

What is wrong: request_id is missing in /var/log/syslog after device being dismissed/rejected:
How to reproduce:
Login to HM
Accept new device
Reject/dismiss the device
Inspect /var/log/syslog on device
Device: raspberry pi 3
pi@raspberrypi:~ $ mender --version
3.1.0 runtime: go1.14.7
* After dismissing: level=error msg="(request_id: ): Got unexpected HTTP status when submitting to inventory 401"
* After rejecting: level=warning msg="Failed to refresh inventory: failed to submit inventory data: (request_id: ): Got unexpected HTTP status when submitting to inventory 401"
* level=error msg="Error receiving scheduled update data: (request_id: ): client not authorized"
* level=info msg="Handling error state, current error: transient error: (request_id: ): client not authorized"
* level=warning msg="Failed to refresh inventory: failed to submit inventory data: (request_id: ): Got unexpected HTTP status when submitting to inventory 429"
Expected result: request_id is properly shown in /var/log/syslog after device is rejected/dismissed