From 1ce196ed35492684666d4512f82fcd5f6c3e24b0 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Wed, 22 Feb 2017 12:22:19 +0100 Subject: [PATCH] handle read timeout simplification in metrics --- metrics.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/metrics.go b/metrics.go index 5a44115..eca983e 100644 --- a/metrics.go +++ b/metrics.go @@ -1,6 +1,7 @@ package tusd import ( + "net" "sync" "sync/atomic" ) @@ -86,8 +87,18 @@ type simpleHTTPError struct { } func simplifiedHTTPError(err HTTPError) simpleHTTPError { + var msg string + // Errors for read timeouts contain too much information which is not + // necessary for us and makes grouping for the metrics harder. The error + // message looks like: read tcp 127.0.0.1:1080->127.0.0.1:53673: i/o timeout + // Therefore, we use a common error message for all of them. + if netErr, ok := err.(net.Error); ok && netErr.Timeout() { + msg = "read tcp: i/o timeout" + } else { + msg = err.Error() + } return simpleHTTPError{ - Msg: err.Error(), + Msg: msg, Code: err.StatusCode(), } }