8000 fix(engine): log http error as info if status < 500 (#5018) · ovh/cds@790def0 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 790def0

Browse files
authored
fix(engine): log http error as info if status < 500 (#5018)
* fix(engine): log http error as info if status < 500 * feat: add clean uri in router log fields
1 parent 7f318c2 commit 790def0

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

engine/api/router.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,13 @@ func (r *Router) Handle(uri string, scope HandlerScope, handlers ...*service.Han
378378
latency := end.Sub(start)
379379

380380
log.InfoWithFields(ctx, logrus.Fields{
381-
"method": req.Method,
382-
"latency": latency,
383-
"status": responseWriter.statusCode,
384-
"deprecated": rc.IsDeprecated,
381+
"method": req.Method,
382+
"latency": latency.Milliseconds(),
383+
"latency_human": latency,
384+
"status": responseWriter.statusCode,
385+
"route": cleanURL,
386+
"request_uri": req.RequestURI,
387+
"deprecated": rc.IsDeprecated,
385388
}, "[%d] | %s | END | %s [%s]", responseWriter.statusCode, req.Method, req.URL, rc.Name)
386389

387390
observability.RecordFloat64(ctx, ServerLatency, float64(latency)/float64(time.Millisecond))

engine/service/http.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,13 @@ func WriteError(ctx context.Context, w http.ResponseWriter, r *http.Request, err
111111
httpErr := sdk.ExtractHTTPError(err, al)
112112
isErrWithStack := sdk.IsErrorWithStack(err)
113113

114-
fields := logrus.Fields{
115-
"method": r.Method,
116-
"request_uri": r.RequestURI,
117-
"status": httpErr.Status,
118-
}
114+
fields := logrus.Fields{}
119115
if isErrWithStack {
120116
fields["stack_trace"] = fmt.Sprintf("%+v", err)
121117
}
122118

123-
// ErrAlreadyTaken and ErrWorkerModelAlreadyBooked are not useful to log in warning
124-
if sdk.ErrorIs(httpErr, sdk.ErrAlreadyTaken) ||
125-
sdk.ErrorIs(httpErr, sdk.ErrWorkerModelAlreadyBooked) ||
126-
sdk.ErrorIs(httpErr, sdk.ErrJobAlreadyBooked) || r.URL.Path == "/user/logged" {
127-
log.WarningWithFields(ctx, fields, "%s", err)
119+
if httpErr.Status < 500 {
120+
log.InfoWithFields(ctx, fields, "%s", err)
128121
} else {
129122
log.ErrorWithFields(ctx, fields, "%s", err)
130123
}

0 commit comments

Comments
 (0)
0