Skip to content

Commit

Permalink
humanize timeToFirstByte and timeToResponse upto nanoseconds (min…
Browse files Browse the repository at this point in the history
  • Loading branch information
Praveenrajmani authored May 20, 2020
1 parent b11adfa commit 0cc2ed0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions cmd/logger/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"net/http"
"net/url"
"strconv"
"time"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions docs/logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 0cc2ed0

Please sign in to comment.