Skip to content
Open
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
99 changes: 5 additions & 94 deletions analytics/filesystem/file_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,50 +35,30 @@ func (f *FileLogger) LogAuctionObject(ao *analytics.AuctionObject) {

//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())
f.Logger.Flush()
// do nothing
}

//Logs SetUIDObject to file
func (f *FileLogger) LogSetUIDObject(so *analytics.SetUIDObject) {
//Code to parse the object and log in a way required
var b bytes.Buffer
b.WriteString(jsonifySetUIDObject(so))
f.Logger.Debug(b.String())
f.Logger.Flush()
// do nothing
}

//Logs CookieSyncObject to file
func (f *FileLogger) LogCookieSyncObject(cso *analytics.CookieSyncObject) {
//Code to parse the object and log in a way required
var b bytes.Buffer
b.WriteString(jsonifyCookieSync(cso))
f.Logger.Debug(b.String())
f.Logger.Flush()
// do nothing
}

//Logs AmpObject to file
func (f *FileLogger) LogAmpObject(ao *analytics.AmpObject) {
if ao == nil {
return
}
//Code to parse the object and log in a way required
var b bytes.Buffer
b.WriteString(jsonifyAmpObject(ao))
f.Logger.Debug(b.String())
f.Logger.Flush()
// do nothing
}

//Method to initialize the analytic module
func NewFileLogger(filename string) (analytics.PBSAnalyticsModule, error) {
options := glog.LogOptions{
File: filename,
Flag: glog.LstdFlags,
Flag: glog.LstdNull,
Level: glog.Ldebug,
Mode: glog.R_Day,
}
if logger, err := glog.New(options); err == nil {
return &FileLogger{
Expand Down Expand Up @@ -107,72 +87,3 @@ func jsonifyAuctionObject(ao *analytics.AuctionObject) string {
return fmt.Sprintf("Transactional Logs Error: Auction object badly formed %v", err)
}
}

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)
}
}

func jsonifyCookieSync(cso *analytics.CookieSyncObject) string {
type alias analytics.CookieSyncObject

b, err := json.Marshal(&struct {
Type RequestType `json:"type"`
*alias
}{
Type: COOKIE_SYNC,
alias: (*alias)(cso),
})

if err == nil {
return string(b)
} else {
return fmt.Sprintf("Transactional Logs Error: Cookie sync object badly formed %v", err)
}
}

func jsonifySetUIDObject(so *analytics.SetUIDObject) string {
type alias analytics.SetUIDObject
b, err := json.Marshal(&struct {
Type RequestType `json:"type"`
*alias
}{
Type: SETUID,
alias: (*alias)(so),
})

if err == nil {
return string(b)
} else {
return fmt.Sprintf("Transactional Logs Error: Set UID object badly formed %v", err)
}
}

func jsonifyAmpObject(ao *analytics.AmpObject) string {
type alias analytics.AmpObject
b, err := json.Marshal(&struct {
Type RequestType `json:"type"`
*alias
}{
Type: AMP,
alias: (*alias)(ao),
})

if err == nil {
return string(b)
} else {
return fmt.Sprintf("Transactional Logs Error: Amp object badly formed %v", err)
}
}
44 changes: 0 additions & 44 deletions analytics/filesystem/file_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,11 @@ import (
"strings"
"testing"

"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/analytics"
"github.com/prebid/prebid-server/usersync"
)

const TEST_DIR string = "testFiles"

func TestAmpObject_ToJson(t *testing.T) {
ao := &analytics.AmpObject{
Status: http.StatusOK,
Errors: make([]error, 0),
AuctionResponse: &openrtb.BidResponse{},
AmpTargetingValues: map[string]string{},
}
if aoJson := jsonifyAmpObject(ao); strings.Contains(aoJson, "Transactional Logs Error") {
t.Fatalf("AmpObject failed to convert to json")
}
}

func TestAuctionObject_ToJson(t *testing.T) {
ao := &analytics.AuctionObject{
Status: http.StatusOK,
Expand All @@ -34,36 +20,6 @@ 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,
Bidder: "any-bidder",
UID: "uid string",
}
if soJson := jsonifySetUIDObject(so); strings.Contains(soJson, "Transactional Logs Error") {
t.Fatalf("SetUIDObject failed to convert to json")
}
}

func TestCookieSyncObject_ToJson(t *testing.T) {
cso := &analytics.CookieSyncObject{
Status: http.StatusOK,
BidderStatus: []*usersync.CookieSyncBidders{},
}
if csoJson := jsonifyCookieSync(cso); strings.Contains(csoJson, "Transactional Logs Error") {
t.Fatalf("CookieSyncObject failed to convert to json")
}
}

func TestFileLogger_LogObjects(t *testing.T) {
if _, err := os.Stat(TEST_DIR); os.IsNotExist(err) {
if err = os.MkdirAll(TEST_DIR, 0755); err != nil {
Expand Down