Skip to content

Commit

Permalink
Merge pull request #661 from PubMatic-OpenWrap/ci
Browse files Browse the repository at this point in the history
Release OpenWrap_Q4-5-Dec-2023
  • Loading branch information
pm-nilesh-chate authored Dec 1, 2023
2 parents d7b44a0 + 95dc444 commit 887f705
Show file tree
Hide file tree
Showing 24 changed files with 456 additions and 147 deletions.
2 changes: 2 additions & 0 deletions analytics/pubmatic/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ func (wlog *WloggerRecord) logIntegrationType(endpoint string) {
wlog.IntegrationType = models.TypeInline
case models.EndpointORTB:
wlog.IntegrationType = models.TypeS2S
case models.EndpointWebS2S:
wlog.IntegrationType = models.TypeWebS2S
}
}

Expand Down
5 changes: 5 additions & 0 deletions analytics/pubmatic/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ func TestLogIntegrationType(t *testing.T) {
endpoint: "invalid",
integrationType: "",
},
{
name: "ows2s",
endpoint: models.EndpointWebS2S,
integrationType: models.TypeWebS2S,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions endpoints/events/vtrack_ow.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func InjectVideoEventTrackers(trackerURL, vastXML string, bid *openrtb2.Bid, pre
doc := etree.NewDocument()
err := doc.ReadFromString(vastXML)
if nil != err {
err = fmt.Errorf("Error parsing VAST XML. '%v'", err.Error())
glog.Errorf(err.Error())
err = fmt.Errorf("account:[%s] bidder:[%s] err:[vast_xml_parsing_failed:%s] vast:[%s] ", accountID, requestingBidder, err.Error(), vastXML)
glog.Error(err.Error())
return []byte(vastXML), false, err // false indicates events trackers are not injected
}

Expand Down
2 changes: 1 addition & 1 deletion exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (e *exchange) HoldAuction(ctx context.Context, r *AuctionRequest, debugLog
for _, seatBid := range adapterBids {
for _, pbsBid := range seatBid.Bids {
pbsBid.GeneratedBidID, err = e.bidIDGenerator.New()
glog.Infof("Original BidID = %s Generated BidID = %s", pbsBid.Bid.ID, pbsBid.GeneratedBidID)
glog.V(3).Infof("Original BidID = %s Generated BidID = %s", pbsBid.Bid.ID, pbsBid.GeneratedBidID)
if err != nil {
errs = append(errs, errors.New("Error generating bid.ext.prebid.bidid"))
}
Expand Down
2 changes: 1 addition & 1 deletion exchange/exchange_ow.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func recordAdaptorDuplicateBidIDs(metricsEngine metrics.MetricsEngine, adapterBi
if collisions, ok := bidIDColisionMap[thisBid.Bid.ID]; ok {
bidIDCollisionFound = true
bidIDColisionMap[thisBid.Bid.ID]++
glog.Warningf("Bid.id %v :: %v collision(s) [imp.id = %v] for bidder '%v'", thisBid.Bid.ID, collisions, thisBid.Bid.ImpID, string(bidder))
glog.V(3).Infof("Bid.id %v :: %v collision(s) [imp.id = %v] for bidder '%v'", thisBid.Bid.ID, collisions, thisBid.Bid.ImpID, string(bidder))
metricsEngine.RecordAdapterDuplicateBidID(string(bidder), 1)
} else {
bidIDColisionMap[thisBid.Bid.ID] = 1
Expand Down
20 changes: 15 additions & 5 deletions modules/pubmatic/openwrap/auctionresponsehook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,19 @@ func (m OpenWrap) handleAuctionResponseHook(

// absence of rctx at this hook means the first hook failed!. Do nothing
if len(moduleCtx.ModuleContext) == 0 {
result.DebugMessages = append(result.DebugMessages, "error: module-ctx not found in handleBeforeValidationHook()")
result.DebugMessages = append(result.DebugMessages, "error: module-ctx not found in handleAuctionResponseHook()")
return result, nil
}
rctx, ok := moduleCtx.ModuleContext["rctx"].(models.RequestCtx)
if !ok {
result.DebugMessages = append(result.DebugMessages, "error: request-ctx not found in handleBeforeValidationHook()")
result.DebugMessages = append(result.DebugMessages, "error: request-ctx not found in handleAuctionResponseHook()")
return result, nil
}

//SSHB request should not execute module
if rctx.Sshb == "1" || rctx.Endpoint == models.EndpointHybrid {
return result, nil
}
if rctx.Endpoint == models.EndpointOWS2S {
return result, nil
}

defer func() {
moduleCtx.ModuleContext["rctx"] = rctx
Expand Down Expand Up @@ -283,6 +280,19 @@ func (m OpenWrap) handleAuctionResponseHook(
result.DebugMessages = append(result.DebugMessages, string(rCtxBytes))
}

if rctx.Endpoint == models.EndpointWebS2S {
result.ChangeSet.AddMutation(func(ap hookstage.AuctionResponsePayload) (hookstage.AuctionResponsePayload, error) {
rctx := moduleCtx.ModuleContext["rctx"].(models.RequestCtx)
var err error
ap.BidResponse, err = tracker.InjectTrackers(rctx, ap.BidResponse)
if err == nil {
resetBidIdtoOriginal(ap.BidResponse)
}
return ap, err
}, hookstage.MutationUpdate, "response-body-with-webs2s-format")
return result, nil
}

result.ChangeSet.AddMutation(func(ap hookstage.AuctionResponsePayload) (hookstage.AuctionResponsePayload, error) {
rctx := moduleCtx.ModuleContext["rctx"].(models.RequestCtx)
var err error
Expand Down
155 changes: 155 additions & 0 deletions modules/pubmatic/openwrap/auctionresponsehook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/openrtb/v19/openrtb3"
"github.com/prebid/prebid-server/hooks/hookstage"
mock_cache "github.com/prebid/prebid-server/modules/pubmatic/openwrap/cache/mock"
mock_metrics "github.com/prebid/prebid-server/modules/pubmatic/openwrap/metrics/mock"
"github.com/prebid/prebid-server/modules/pubmatic/openwrap/models"
"github.com/prebid/prebid-server/modules/pubmatic/openwrap/tbf"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -1134,3 +1136,156 @@ func TestResetBidIdtoOriginal(t *testing.T) {
})
}
}

func TestAuctionResponseHookForEndpointWebS2S(t *testing.T) {
ctrl := gomock.NewController(t)
mockCache := mock_cache.NewMockCache(ctrl)
tbf.Init(1, mockCache)
defer func() {
ctrl.Finish()
tbf.StopTBFReloaderService()
}()

type args struct {
ctx context.Context
moduleCtx hookstage.ModuleInvocationContext
payload hookstage.AuctionResponsePayload
}

type want struct {
bidResponse *openrtb2.BidResponse
err error
}

tests := []struct {
name string
args args
want want
getMetricsEngine func() *mock_metrics.MockMetricsEngine
}{
{
name: "inject_tracker_in_respose_for_WebS2S_endpoint",
args: args{
ctx: nil,
moduleCtx: hookstage.ModuleInvocationContext{
ModuleContext: hookstage.ModuleContext{
"rctx": models.RequestCtx{
Endpoint: models.EndpointWebS2S,
Trackers: map[string]models.OWTracker{
"bid1": {
BidType: models.Video,
},
},
},
},
},
payload: hookstage.AuctionResponsePayload{
BidResponse: &openrtb2.BidResponse{
SeatBid: []openrtb2.SeatBid{
{
Bid: []openrtb2.Bid{
{
ID: "12345",
AdM: `<VAST version="3.0"><Ad><Wrapper></Wrapper></Ad></VAST>`,
},
},
},
},
},
},
},
want: want{
bidResponse: &openrtb2.BidResponse{
SeatBid: []openrtb2.SeatBid{
{
Bid: []openrtb2.Bid{
{
ID: "12345",
AdM: "<VAST version=\"3.0\"><Ad><Wrapper></Wrapper></Ad></VAST><div style=\"position:absolute;left:0px;top:0px;visibility:hidden;\"><img src=\"https:?adv=&af=banner&aps=0&au=&bc=&bidid=12345&di=-1&eg=0&en=0&ft=0&iid=&kgpv=&orig=&origbidid=12345&pdvid=0&pid=0&plt=0&pn=&psz=0x0&pubid=0&purl=&sl=1&slot=&ss=1&tgid=0&tst=0\"></div>"},
},
},
},
},
err: nil,
},
getMetricsEngine: func() *mock_metrics.MockMetricsEngine {
mockEngine := mock_metrics.NewMockMetricsEngine(ctrl)
mockEngine.EXPECT().RecordPlatformPublisherPartnerResponseStats(gomock.Any(), gomock.Any(), gomock.Any())
mockEngine.EXPECT().RecordNobidErrPrebidServerResponse(gomock.Any())
mockEngine.EXPECT().RecordPublisherResponseTimeStats(gomock.Any(), gomock.Any())
return mockEngine
},
},
{
name: "inject_tracker_in_respose_and_reset_bidID_to_orignal_for_WebS2S_endpoint",
args: args{
ctx: nil,
moduleCtx: hookstage.ModuleInvocationContext{
ModuleContext: hookstage.ModuleContext{
"rctx": models.RequestCtx{
Endpoint: models.EndpointWebS2S,
Trackers: map[string]models.OWTracker{
"bid1": {
BidType: models.Video,
},
},
},
},
},
payload: hookstage.AuctionResponsePayload{
BidResponse: &openrtb2.BidResponse{
SeatBid: []openrtb2.SeatBid{
{
Bid: []openrtb2.Bid{
{
ID: "12345:: 123422222225",
AdM: `<VAST version="3.0"><Ad><Wrapper></Wrapper></Ad></VAST>`,
},
},
},
},
},
},
},
want: want{
bidResponse: &openrtb2.BidResponse{
SeatBid: []openrtb2.SeatBid{
{
Bid: []openrtb2.Bid{
{
ID: "12345",
AdM: "<VAST version=\"3.0\"><Ad><Wrapper></Wrapper></Ad></VAST><div style=\"position:absolute;left:0px;top:0px;visibility:hidden;\"><img src=\"https:?adv=&af=banner&aps=0&au=&bc=&bidid=12345&di=-1&eg=0&en=0&ft=0&iid=&kgpv=&orig=&origbidid=12345&pdvid=0&pid=0&plt=0&pn=&psz=0x0&pubid=0&purl=&sl=1&slot=&ss=1&tgid=0&tst=0\"></div>"},
},
},
},
},
err: nil,
},
getMetricsEngine: func() *mock_metrics.MockMetricsEngine {
mockEngine := mock_metrics.NewMockMetricsEngine(ctrl)
mockEngine.EXPECT().RecordPlatformPublisherPartnerResponseStats(gomock.Any(), gomock.Any(), gomock.Any())
mockEngine.EXPECT().RecordNobidErrPrebidServerResponse(gomock.Any())
mockEngine.EXPECT().RecordPublisherResponseTimeStats(gomock.Any(), gomock.Any())
return mockEngine
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := OpenWrap{
metricEngine: tt.getMetricsEngine(),
cache: mockCache,
}
mockCache.EXPECT().GetTBFTrafficForPublishers().Return(map[int]map[int]int{1: {2: 3}}, nil).AnyTimes()
hookResult, err := o.handleAuctionResponseHook(tt.args.ctx, tt.args.moduleCtx, tt.args.payload)
assert.Equal(t, tt.want.err, err, tt.name)
mutations := hookResult.ChangeSet.Mutations()
assert.NotEmpty(t, mutations, tt.name)
for _, mut := range mutations {
result, err := mut.Apply(tt.args.payload)
assert.Nil(t, err, tt.name)
assert.Equal(t, tt.want.bidResponse, result.BidResponse, tt.name)
}
})
}
}
9 changes: 7 additions & 2 deletions modules/pubmatic/openwrap/beforevalidationhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (m OpenWrap) handleBeforeValidationHook(
return result, err
}
}
if rCtx.Endpoint == models.EndpointOWS2S {
if rCtx.Endpoint == models.EndpointWebS2S {
imp.TagID = getTagID(imp, impExt)
}
if imp.TagID == "" {
Expand Down Expand Up @@ -258,7 +258,8 @@ func (m OpenWrap) handleBeforeValidationHook(
bannerAdUnitCtx = adunitconfig.UpdateBannerObjectWithAdunitConfig(rCtx, imp, div)
}

if !isSlotEnabled(videoAdUnitCtx, bannerAdUnitCtx) {
// ignore adunit config status for native as it is not supported for native
if (!isSlotEnabled(videoAdUnitCtx, bannerAdUnitCtx)) && imp.Native == nil {
disabledSlots++

rCtx.ImpBidCtx[imp.ID] = models.ImpCtx{ // for wrapper logger sz
Expand Down Expand Up @@ -910,6 +911,10 @@ func (m OpenWrap) setTimeout(rCtx models.RequestCtx, req *openrtb2.BidRequest) i
// if ssauction flag is not set and platform is dislay, then by default send all bids
// if ssauction flag is not set and platform is in-app, then check if profile setting sendAllBids is set to 1
func isSendAllBids(rctx models.RequestCtx) bool {
//for webs2s endpoint SendAllBids is always true
if rctx.Endpoint == models.EndpointWebS2S {
return true
}
//if ssauction is set to 0 in the request
if rctx.SSAuction == 0 {
return true
Expand Down
Loading

0 comments on commit 887f705

Please sign in to comment.