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

OTT-1807: discard emptyVAST and invalidVAST bids detected by VAST unwrap module #874

Merged
merged 12 commits into from
Sep 2, 2024
Merged
1 change: 0 additions & 1 deletion modules/pubmatic/openwrap/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ type PixelView struct {

type FeatureToggle struct {
VASTUnwrapPercent int
VASTUnwrapStatsPercent int
AnalyticsThrottlingPercentage string
}

Expand Down
95 changes: 63 additions & 32 deletions modules/pubmatic/openwrap/hook_raw_bidder_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ package openwrap

import (
"fmt"
"sync"

"github.com/prebid/prebid-server/v2/adapters"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/nbr"
"github.com/prebid/prebid-server/v2/openrtb_ext"

"github.com/prebid/prebid-server/v2/hooks/hookstage"
)

type bidInfo struct {
bid *adapters.TypedBid
unwrapStatus string
}

func (m OpenWrap) handleRawBidderResponseHook(
miCtx hookstage.ModuleInvocationContext,
payload hookstage.RawBidderResponsePayload,
Expand All @@ -20,41 +26,66 @@ func (m OpenWrap) handleRawBidderResponseHook(
return result, nil
}

if vastRequestContext.VastUnwrapEnabled {
// Do Unwrap and Update Adm
wg := new(sync.WaitGroup)
for _, bid := range payload.Bids {
if string(bid.BidType) == models.MediaTypeVideo {
wg.Add(1)
go func(bid *adapters.TypedBid) {
defer wg.Done()
m.unwrap.Unwrap(miCtx.AccountID, payload.Bidder, bid, vastRequestContext.UA, vastRequestContext.IP, vastRequestContext.VastUnwrapStatsEnabled)
}(bid)
}
}
wg.Wait()
changeSet := hookstage.ChangeSet[hookstage.RawBidderResponsePayload]{}
changeSet.RawBidderResponse().Bids().Update(payload.Bids)
result.ChangeSet = changeSet
} else {
vastRequestContext.VastUnwrapStatsEnabled = GetRandomNumberIn1To100() <= m.cfg.Features.VASTUnwrapStatsPercent
if vastRequestContext.VastUnwrapStatsEnabled {
// Do Unwrap and Collect stats only
for _, bid := range payload.Bids {
if string(bid.BidType) == models.MediaTypeVideo {
go func(bid *adapters.TypedBid) {
m.unwrap.Unwrap(miCtx.AccountID, payload.Bidder, bid, vastRequestContext.UA, vastRequestContext.IP, vastRequestContext.VastUnwrapStatsEnabled)
}(bid)
}
}
if !vastRequestContext.VastUnwrapEnabled {
return result, nil
}

seatNonBid := openrtb_ext.NonBidCollection{}
unwrappedBids := make([]*adapters.TypedBid, 0, len(payload.Bids))
unwrappedBidsChan := make(chan bidInfo, len(payload.Bids))
pm-nikhil-vaidya marked this conversation as resolved.
Show resolved Hide resolved
unwrappedBidsCnt := 0

// send bids for unwrap
for _, bid := range payload.Bids {
if notEligibleForUnwrap(bid) {
ashishshinde-pubm marked this conversation as resolved.
Show resolved Hide resolved
continue
}
unwrappedBidsCnt++
go func(bid adapters.TypedBid) {
unwrapStatus := m.unwrap.Unwrap(&bid, miCtx.AccountID, payload.Bidder, vastRequestContext.UA, vastRequestContext.IP)
unwrappedBidsChan <- bidInfo{&bid, unwrapStatus}
}(*bid)
pm-nikhil-vaidya marked this conversation as resolved.
Show resolved Hide resolved
}

if vastRequestContext.VastUnwrapEnabled || vastRequestContext.VastUnwrapStatsEnabled {
result.DebugMessages = append(result.DebugMessages,
fmt.Sprintf("For pubid:[%d] VastUnwrapEnabled: [%v] VastUnwrapStatsEnabled:[%v] ",
vastRequestContext.PubID, vastRequestContext.VastUnwrapEnabled, vastRequestContext.VastUnwrapStatsEnabled))
// collect bids after unwrap
for i := 0; i < unwrappedBidsCnt; i++ {
unwrappedBid := <-unwrappedBidsChan
if rejectBid(unwrappedBid.unwrapStatus) {
pm-nikhil-vaidya marked this conversation as resolved.
Show resolved Hide resolved
seatNonBid.AddBid(
openrtb_ext.NewNonBid(openrtb_ext.NonBidParams{
Bid: unwrappedBid.bid.Bid,
NonBidReason: int(nbr.LossBidLostInVastUnwrap),
DealPriority: unwrappedBid.bid.DealPriority,
BidMeta: unwrappedBid.bid.BidMeta,
BidType: unwrappedBid.bid.BidType,
BidVideo: unwrappedBid.bid.BidVideo,
OriginalBidCPM: unwrappedBid.bid.Bid.Price,
// TODO - need to set correct values for price, originalBidCur considering response-currency and bidAdjustment values
}), payload.Bidder,
)
} else {
unwrappedBids = append(unwrappedBids, unwrappedBid.bid)
}
}

changeSet := hookstage.ChangeSet[hookstage.RawBidderResponsePayload]{}
changeSet.RawBidderResponse().Bids().Update(unwrappedBids)
result.ChangeSet = changeSet
result.SeatNonBid = seatNonBid
result.DebugMessages = append(result.DebugMessages,
fmt.Sprintf("For pubid:[%d] VastUnwrapEnabled: [%v]", vastRequestContext.PubID, vastRequestContext.VastUnwrapEnabled))

return result, nil
}

func notEligibleForUnwrap(bid *adapters.TypedBid) bool {
return bid == nil || bid.Bid == nil || bid.Bid.AdM == "" || bid.BidType != openrtb_ext.BidTypeVideo
}

func rejectBid(unwrapStatus string) bool {
switch unwrapStatus {
case models.UnwrapEmptyVASTStatus, models.UnwrapInvalidVASTStatus:
return true
}
return false
}
Loading
Loading