From 0cc2ed04f59ccbf364b30c845139f839155eae22 Mon Sep 17 00:00:00 2001 From: Praveen raj Mani Date: Wed, 20 May 2020 07:04:02 +0530 Subject: [PATCH] humanize `timeToFirstByte` and `timeToResponse` upto nanoseconds (#9641) --- cmd/logger/audit.go | 8 ++++++-- docs/logging/README.md | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/logger/audit.go b/cmd/logger/audit.go index d3539b8b6..a319a9652 100644 --- a/cmd/logger/audit.go +++ b/cmd/logger/audit.go @@ -22,6 +22,7 @@ import ( "io" "net/http" "net/url" + "strconv" "time" "github.com/gorilla/mux" @@ -166,8 +167,11 @@ func AuditLog(w http.ResponseWriter, r *http.Request, api string, reqClaims map[ entry.API.Object = object entry.API.Status = http.StatusText(statusCode) entry.API.StatusCode = statusCode - entry.API.TimeToFirstByte = timeToFirstByte.String() - entry.API.TimeToResponse = timeToResponse.String() + entry.API.TimeToResponse = strconv.FormatInt(timeToResponse.Nanoseconds(), 10) + "ns" + // ttfb will be recorded only for GET requests, Ignore such cases where ttfb will be empty. + if timeToFirstByte != 0 { + entry.API.TimeToFirstByte = strconv.FormatInt(timeToFirstByte.Nanoseconds(), 10) + "ns" + } // Send audit logs only to http targets. for _, t := range AuditTargets { diff --git a/docs/logging/README.md b/docs/logging/README.md index 6e97140ec..85d42bf51 100644 --- a/docs/logging/README.md +++ b/docs/logging/README.md @@ -57,6 +57,9 @@ minio server /mnt/data ``` Setting this environment variable automatically enables audit logging to the HTTP target. The audit logging is in JSON format as described below. + +NOTE: `timeToFirstByte` and `timeToResponse` will be expressed in Nanoseconds. + ```json { "version": "1", @@ -68,8 +71,8 @@ Setting this environment variable automatically enables audit logging to the HTT "object": "hosts", "status": "OK", "statusCode": 200, - "timeToFirstByte": "0s", - "timeToResponse": "2.143308ms" + "timeToFirstByte": "366333ns", + "timeToResponse": "16438202ns" }, "remotehost": "127.0.0.1", "requestID": "15BA4A72C0C70AFC",