Skip to content

Commit

Permalink
Merge pull request #781 from PubMatic-OpenWrap/ci_downmerge_02052024
Browse files Browse the repository at this point in the history
master down merge
  • Loading branch information
pm-nilesh-chate authored May 2, 2024
2 parents ee10c4a + 064731f commit 8d38608
Show file tree
Hide file tree
Showing 53 changed files with 1,145 additions and 317 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ format:
formatcheck:
./scripts/format.sh -f false

mockgen: mockgeninstall mockgendb mockgencache mockgenmetrics
mockgen: mockgeninstall mockgendb mockgencache mockgenmetrics mockgenlogger mockgenpublisherfeature

# export GOPATH=~/go ; GOBIN=~/go/bin; export PATH=$PATH:$GOBIN
mockgeninstall:
Expand Down
2 changes: 1 addition & 1 deletion analytics/pubmatic/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var GetUUID = func() string {

// GetLogAuctionObjectAsURL will form the owlogger-url and http-headers
func GetLogAuctionObjectAsURL(ao analytics.AuctionObject, rCtx *models.RequestCtx, logInfo, forRespExt bool) (string, http.Header) {
if ao.RequestWrapper == nil || ao.RequestWrapper.BidRequest == nil || rCtx == nil || rCtx.PubID == 0 {
if ao.RequestWrapper == nil || ao.RequestWrapper.BidRequest == nil || rCtx == nil || rCtx.PubID == 0 || rCtx.LoggerDisabled {
return "", nil
}

Expand Down
22 changes: 22 additions & 0 deletions analytics/pubmatic/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3368,6 +3368,28 @@ func TestGetLogAuctionObjectAsURL(t *testing.T) {
args args
want want
}{
{
name: "logger_disabled",
args: args{
ao: analytics.AuctionObject{
RequestWrapper: &openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{},
},
Response: &openrtb2.BidResponse{},
},
rCtx: &models.RequestCtx{
Endpoint: models.EndpointV25,
LoggerDisabled: true,
PubID: 5890,
},
logInfo: true,
forRespExt: true,
},
want: want{
logger: "",
header: nil,
},
},
{
name: "do not prepare owlogger if pubid is missing",
args: args{
Expand Down
51 changes: 26 additions & 25 deletions analytics/pubmatic/mhttp/mock/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions analytics/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func (ow HTTPLogger) LogAuctionObject(ao *analytics.AuctionObject) {
return
}

if rCtx.LoggerDisabled {
// logger disabled explicitly for publisher,profile request
return
}

err := RestoreBidResponse(rCtx, *ao)
if err != nil {
glog.Error("Failed to restore bid response for pub:[%d], profile:[%d], version:[%d], err:[%s].", rCtx.PubID, rCtx.ProfileID, rCtx.VersionID, err.Error())
Expand Down
33 changes: 33 additions & 0 deletions analytics/pubmatic/pubmatic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func TestLogAuctionObject(t *testing.T) {
},
},
},

Response: &openrtb2.BidResponse{
ID: "123",
BidID: "bid-id-1",
Expand Down Expand Up @@ -142,6 +143,38 @@ func TestLogAuctionObject(t *testing.T) {
Ext: json.RawMessage(`{"matchedimpression":{"appnexus":50,"pubmatic":50}}`),
},
},
{
name: "logger_disabled",
ao: &analytics.AuctionObject{
HookExecutionOutcome: []hookexecution.StageOutcome{
{
Groups: []hookexecution.GroupOutcome{
{
InvocationResults: []hookexecution.HookOutcome{
{
AnalyticsTags: hookanalytics.Analytics{
Activities: []hookanalytics.Activity{
{
Results: []hookanalytics.Result{
{
Values: map[string]interface{}{
"request-ctx": &models.RequestCtx{
LoggerDisabled: true,
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
}
for _, tt := range tests {
HTTPLogger{}.LogAuctionObject(tt.ao)
Expand Down
20 changes: 11 additions & 9 deletions endpoints/openrtb2/auction_ow.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ func UpdateResponseExtOW(w http.ResponseWriter, bidResponse *openrtb2.BidRespons
pubmatic.RestoreBidResponse(rCtx, ao)
}

owlogger, _ := pubmatic.GetLogAuctionObjectAsURL(ao, rCtx, false, true)
if rCtx.Endpoint == models.EndpointAppLovinMax {
*bidResponse = *orignalMaxBidResponse
}
if len(bidResponse.Ext) == 0 {
bidResponse.Ext = []byte("{}")
}
if updatedExt, err := jsonparser.Set([]byte(bidResponse.Ext), []byte(strconv.Quote(owlogger)), "owlogger"); err == nil {
bidResponse.Ext = updatedExt
if !rCtx.LoggerDisabled {
owlogger, _ := pubmatic.GetLogAuctionObjectAsURL(ao, rCtx, false, true)
if rCtx.Endpoint == models.EndpointAppLovinMax {
*bidResponse = *orignalMaxBidResponse
}
if len(bidResponse.Ext) == 0 {
bidResponse.Ext = []byte("{}")
}
if updatedExt, err := jsonparser.Set([]byte(bidResponse.Ext), []byte(strconv.Quote(owlogger)), "owlogger"); err == nil {
bidResponse.Ext = updatedExt
}
}
} else if rCtx.Endpoint == models.EndpointAppLovinMax {
bidResponse.Ext = nil
Expand Down
10 changes: 7 additions & 3 deletions exchange/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type eventTracking struct {
accountID string
enabledForAccount bool
enabledForRequest bool
enabledVideoEvents bool //TODO: OPENWRAP Video Events Flag
auctionTimestampMs int64
integrationType string
bidderInfos config.BidderInfos
Expand All @@ -31,6 +32,7 @@ func getEventTracking(requestExtPrebid *openrtb_ext.ExtRequestPrebid, ts time.Ti
accountID: account.ID,
enabledForAccount: account.Events.Enabled,
enabledForRequest: requestExtPrebid != nil && requestExtPrebid.Events != nil,
enabledVideoEvents: requestExtPrebid == nil || !requestExtPrebid.ExtOWRequestPrebid.TrackerDisabled,
auctionTimestampMs: ts.UnixNano() / 1e+6,
integrationType: getIntegrationType(requestExtPrebid),
bidderInfos: bidderInfos,
Expand Down Expand Up @@ -79,9 +81,11 @@ func (ev *eventTracking) modifyBidVAST(pbsBid *entities.PbsOrtbBid, bidderName o
}
}

// always inject event trackers without checkign isModifyingVASTXMLAllowed
if newVastXML, injected, _ := events.InjectVideoEventTrackers(trackerURL, vastXML, bid, bidID, bidderName.String(), bidderCoreName.String(), ev.accountID, ev.auctionTimestampMs, req); injected {
bid.AdM = string(newVastXML)
if ev.enabledVideoEvents {
// always inject event trackers without checkign isModifyingVASTXMLAllowed
if newVastXML, injected, _ := events.InjectVideoEventTrackers(trackerURL, vastXML, bid, bidID, bidderName.String(), bidderCoreName.String(), ev.accountID, ev.auctionTimestampMs, req); injected {
bid.AdM = string(newVastXML)
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions exchange/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ func Test_isEventAllowed(t *testing.T) {

func TestModifyBidVAST(t *testing.T) {
type args struct {
bidReq *openrtb2.BidRequest
bid *openrtb2.Bid
enabledVideoEvents bool
bidReq *openrtb2.BidRequest
bid *openrtb2.Bid
}
type want struct {
tags []string
Expand All @@ -211,6 +212,7 @@ func TestModifyBidVAST(t *testing.T) {
{
name: "empty_adm", // expect adm contain vast tag with tracking events and VASTAdTagURI nurl contents
args: args{
enabledVideoEvents: true,
bidReq: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{{ID: "123", Video: &openrtb2.Video{}}},
},
Expand Down Expand Up @@ -242,6 +244,7 @@ func TestModifyBidVAST(t *testing.T) {
{
name: "adm_containing_url", // expect adm contain vast tag with tracking events and VASTAdTagURI adm url (previous value) contents
args: args{
enabledVideoEvents: true,
bidReq: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{{ID: "123", Video: &openrtb2.Video{}}},
},
Expand Down Expand Up @@ -279,6 +282,7 @@ func TestModifyBidVAST(t *testing.T) {
ModifyingVastXmlAllowed: false,
},
},
enabledVideoEvents: tc.args.enabledVideoEvents,
}
ev.modifyBidVAST(&entities.PbsOrtbBid{
Bid: tc.args.bid,
Expand Down
Loading

0 comments on commit 8d38608

Please sign in to comment.