Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content length to synclog #27

Merged
merged 4 commits into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0-dev
0.1.1b-dev
15 changes: 9 additions & 6 deletions httphandler/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,31 @@ type SyncLogMessageData struct {
Path string `json:"path"`
SuccessHost string `json:"successhost"`
UserAgent string `json:"useragent"`
ErrorMsg string `json:"error"`
ReqID string `json:"reqID"`
Time string `json:"ts"`
// ContentLength if negative means no content length header provided
ContentLength int64 `json:"content-length"`
ErrorMsg string `json:"error"`
ReqID string `json:"reqID"`
Time string `json:"ts"`
}

// String produces data in csv format with fields in following order:
// Method, Host, Path, UserAgent, StatusCode, Duration, RespErr)
func (slmd SyncLogMessageData) String() string {
return fmt.Sprintf("%q, %q, %q, %q, %q, %q",
return fmt.Sprintf("%q, %q, %q, %q, %q, %d, %q",
slmd.Method,
slmd.FailedHost,
slmd.Path,
slmd.SuccessHost,
slmd.UserAgent,
slmd.ContentLength,
slmd.ErrorMsg)
}

// NewSyncLogMessageData creates new SyncLogMessageData
func NewSyncLogMessageData(method, failedHost, path, successHost, userAgent,
reqID, errorMsg string) *SyncLogMessageData {
reqID, errorMsg string, contentLength int64) *SyncLogMessageData {
ts := time.Now().Format(time.RFC3339Nano)
return &SyncLogMessageData{
method, failedHost, path, successHost, userAgent,
errorMsg, reqID, ts}
contentLength, errorMsg, reqID, ts}
}
11 changes: 10 additions & 1 deletion httphandler/response_merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"io"
"io/ioutil"
"strconv"

"github.com/allegro/akubra/config"
"github.com/allegro/akubra/log"
Expand Down Expand Up @@ -36,6 +37,13 @@ func (rd *responseMerger) synclog(r, successfulTup *transport.ReqResErrTuple) {
if r.Err != nil {
errorMsg = r.Err.Error()
}

contentLengthStr := successfulTup.Res.Header.Get("Content-Length")
contentLength, err := strconv.ParseInt(contentLengthStr, 10, 64)
if err != nil {
contentLength = -1
}

reqID := r.Req.Context().Value(log.ContextreqIDKey).(string)
syncLogMsg := NewSyncLogMessageData(
r.Req.Method,
Expand All @@ -44,7 +52,8 @@ func (rd *responseMerger) synclog(r, successfulTup *transport.ReqResErrTuple) {
successfulTup.Req.Host,
r.Req.Header.Get("User-Agent"),
reqID,
errorMsg)
errorMsg,
contentLength)
logMsg, err := json.Marshal(syncLogMsg)
if err != nil {
return
Expand Down