-
Notifications
You must be signed in to change notification settings - Fork 754
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
Add custom JSON req/resp data to the analytics logging… #1145
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ type RequestType string | |
const ( | ||
COOKIE_SYNC RequestType = "/cookie_sync" | ||
AUCTION RequestType = "/openrtb2/auction" | ||
VIDEO RequestType = "/openrtb2/video" | ||
SETUID RequestType = "/set_uid" | ||
AMP RequestType = "/openrtb2/amp" | ||
) | ||
|
@@ -32,6 +33,15 @@ func (f *FileLogger) LogAuctionObject(ao *analytics.AuctionObject) { | |
f.Logger.Flush() | ||
} | ||
|
||
//Writes VideoObject to file | ||
func (f *FileLogger) LogVideoObject(vo *analytics.VideoObject) { | ||
//Code to parse the object and log in a way required | ||
var b bytes.Buffer | ||
b.WriteString(jsonifyVideoObject(vo)) | ||
f.Logger.Debug(b.String()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm probably not understanding the whole context but if
Is this what we want? Don't we want to log to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is intended to log the video object at the debug level, but if there is an error in that process then yes I agree it would be better to log that as an error instead. The point of this PR however is really just to add the custom JSON request and response used by the /video endpoint to the analytics logging, so I'd prefer to leave improvements to the existing testing/logging as a separate issue. (note while this specific function to log the video object is technically new code, I say "existing" here because it's basically just a copy-&-paste of how all the other objects are being logged). |
||
f.Logger.Flush() | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
//Logs SetUIDObject to file | ||
func (f *FileLogger) LogSetUIDObject(so *analytics.SetUIDObject) { | ||
//Code to parse the object and log in a way required | ||
|
@@ -98,6 +108,23 @@ func jsonifyAuctionObject(ao *analytics.AuctionObject) string { | |
} | ||
} | ||
|
||
func jsonifyVideoObject(vo *analytics.VideoObject) string { | ||
type alias analytics.VideoObject | ||
b, err := json.Marshal(&struct { | ||
Type RequestType `json:"type"` | ||
*alias | ||
}{ | ||
Type: VIDEO, | ||
alias: (*alias)(vo), | ||
}) | ||
|
||
if err == nil { | ||
return string(b) | ||
} else { | ||
return fmt.Sprintf("Transactional Logs Error: Video object badly formed %v", err) | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes good point Gus, I added some calls to test the video endpoint logging and jsonify also in the new commit. Regarding checking for nil fields in jsonifyVideoObject I think it will be ok because if a field is nil it will show up in the JSON with a null value, which the person evaluating the log file should intuitively associate with a nil value in Go. Thanks for the feedback. |
||
func jsonifyCookieSync(cso *analytics.CookieSyncObject) string { | ||
type alias analytics.CookieSyncObject | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,15 @@ func TestAuctionObject_ToJson(t *testing.T) { | |
} | ||
} | ||
|
||
func TestVideoObject_ToJson(t *testing.T) { | ||
vo := &analytics.VideoObject{ | ||
Status: http.StatusOK, | ||
} | ||
if voJson := jsonifyVideoObject(vo); strings.Contains(voJson, "Transactional Logs Error") { | ||
t.Fatalf("AuctionObject failed to convert to json") | ||
} | ||
} | ||
|
||
func TestSetUIDObject_ToJson(t *testing.T) { | ||
so := &analytics.SetUIDObject{ | ||
Status: http.StatusOK, | ||
|
@@ -64,6 +73,7 @@ func TestFileLogger_LogObjects(t *testing.T) { | |
defer os.RemoveAll(TEST_DIR) | ||
if fl, err := NewFileLogger(TEST_DIR + "//test"); err == nil { | ||
fl.LogAuctionObject(&analytics.AuctionObject{}) | ||
fl.LogVideoObject(&analytics.VideoObject{}) | ||
fl.LogAmpObject(&analytics.AmpObject{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to have a more comprehensive test do you think it won't be much of a hassle to compare the log file at the end of this test? Maybe the the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comparing log files might be tricky, if logger is including time stamps. you will have to craft some regex's to test the output. Or make your own version of |
||
fl.LogSetUIDObject(&analytics.SetUIDObject{}) | ||
fl.LogCookieSyncObject(&analytics.CookieSyncObject{}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newly added function is not being covered by test cases