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

UOE-9673: OpenWrap module minor improvements #579

Merged
merged 6 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 8 additions & 1 deletion modules/pubmatic/openwrap/adunitconfig/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ func TestSelectSlot(t *testing.T) {
name: "Matching_Slot_config_when_regex_is_present_and_slotconfig_is_absent",
args: args{
rCtx: models.RequestCtx{
AdUnitConfig: getAdunitConfigWithRx(),
AdUnitConfig: func() *adunitconfig.AdUnitConfig {
auc := getAdunitConfigWithRx()

// Temporary fix to make UT execution consistent.
// TODO: make getRegexMatch()'s loop consistent.
delete(auc.Config, "/15671365/test_adunit1")
return auc
}(),
},
h: 300,
w: 200,
Expand Down
14 changes: 7 additions & 7 deletions modules/pubmatic/openwrap/adunitconfig/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import (
"github.com/prebid/prebid-server/modules/pubmatic/openwrap/models/adunitconfig"
)

func ReplaceDeviceTypeFromAdUnitConfig(rCtx models.RequestCtx, device *openrtb2.Device) {
if device != nil || device.DeviceType != 0 {
func ReplaceDeviceTypeFromAdUnitConfig(rCtx models.RequestCtx, device **openrtb2.Device) {
pm-nilesh-chate marked this conversation as resolved.
Show resolved Hide resolved
if *device == nil {
pm-nilesh-chate marked this conversation as resolved.
Show resolved Hide resolved
*device = &openrtb2.Device{}
}

if (*device).DeviceType != 0 {
return
}

Expand All @@ -28,9 +32,5 @@ func ReplaceDeviceTypeFromAdUnitConfig(rCtx models.RequestCtx, device *openrtb2.
return
}

if device == nil {
device = &openrtb2.Device{}
}

device.DeviceType = adcom1.DeviceType(adUnitCfg.Device.DeviceType)
(*device).DeviceType = adcom1.DeviceType(adUnitCfg.Device.DeviceType)
}
37 changes: 30 additions & 7 deletions modules/pubmatic/openwrap/beforevalidationhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"strconv"

"github.com/buger/jsonparser"
"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/hooks/hookstage"
"github.com/prebid/prebid-server/modules/pubmatic/openwrap/adapters"
Expand Down Expand Up @@ -142,12 +143,15 @@ func (m OpenWrap) handleBeforeValidationHook(
IncludeWinners: boolutil.BoolPtr(true),
}

isAdPodRequest := false
disabledSlots := 0
serviceSideBidderPresent := false

aliasgvlids := make(map[string]uint16)
for i := 0; i < len(payload.BidRequest.Imp); i++ {
slotType := "banner"
var adpodExt *models.AdPod
var isAdPodImpression bool
imp := payload.BidRequest.Imp[i]

if imp.TagID == "" {
Expand All @@ -158,6 +162,8 @@ func (m OpenWrap) handleBeforeValidationHook(
}

if imp.Video != nil {
slotType = "video"

//add stats for video instl impressions
if imp.Instl == 1 {
m.metricEngine.RecordVideoInstlImpsStats(rCtx.PubIDStr, rCtx.ProfileIDStr)
Expand All @@ -166,6 +172,16 @@ func (m OpenWrap) handleBeforeValidationHook(
// provide custom macros for video event trackers
requestExt.Prebid.Macros = getVASTEventMacros(rCtx)
}

if rCtx.IsCTVRequest && imp.Video.Ext != nil {
if _, _, _, err := jsonparser.Get(imp.Video.Ext, "adpod"); err == nil {
isAdPodImpression = true
if !isAdPodRequest {
isAdPodRequest = true
rCtx.MetricsEngine.RecordCTVReqCountWithAdPod(rCtx.PubIDStr, rCtx.ProfileIDStr)
}
}
}
}

impExt := &models.ImpExtension{}
Expand Down Expand Up @@ -210,11 +226,6 @@ func (m OpenWrap) handleBeforeValidationHook(
continue
}

slotType := "banner"
if imp.Video != nil {
slotType = "video"
}

bidderMeta := make(map[string]models.PartnerData)
nonMapped := make(map[string]struct{})
for _, partnerConfig := range rCtx.PartnerConfigMap {
Expand Down Expand Up @@ -246,11 +257,12 @@ func (m OpenWrap) handleBeforeValidationHook(
var isRegex bool
var slot, kgpv string
var bidderParams json.RawMessage
var matchedSlotKeysVAST []string
switch prebidBidderCode {
case string(openrtb_ext.BidderPubmatic), models.BidderPubMaticSecondaryAlias:
slot, kgpv, isRegex, bidderParams, err = bidderparams.PreparePubMaticParamsV25(rCtx, m.cache, *payload.BidRequest, imp, *impExt, partnerID)
case models.BidderVASTBidder:
slot, bidderParams, err = bidderparams.PrepareVASTBidderParams(rCtx, m.cache, *payload.BidRequest, imp, *impExt, partnerID, adpodExt)
slot, bidderParams, matchedSlotKeysVAST, err = bidderparams.PrepareVASTBidderParams(rCtx, m.cache, *payload.BidRequest, imp, *impExt, partnerID, adpodExt)
default:
slot, kgpv, isRegex, bidderParams, err = bidderparams.PrepareAdapterParamsV25(rCtx, m.cache, *payload.BidRequest, imp, *impExt, partnerID)
}
Expand All @@ -274,6 +286,10 @@ func (m OpenWrap) handleBeforeValidationHook(
IsRegex: isRegex, // regex pattern
}

for _, bidder := range matchedSlotKeysVAST {
bidderMeta[bidder].VASTTagFlags[bidder] = false
}

if alias, ok := partnerConfig[models.IsAlias]; ok && alias == "1" {
if prebidPartnerName, ok := partnerConfig[models.PREBID_PARTNER_NAME]; ok {
rCtx.Aliases[bidderCode] = adapters.ResolveOWBidder(prebidPartnerName)
Expand Down Expand Up @@ -316,19 +332,26 @@ func (m OpenWrap) handleBeforeValidationHook(
// cache the details for further processing
if _, ok := rCtx.ImpBidCtx[imp.ID]; !ok {
rCtx.ImpBidCtx[imp.ID] = models.ImpCtx{
ImpID: imp.ID,
TagID: imp.TagID,
Div: div,
IsRewardInventory: reward,
Type: slotType,
Banner: imp.Banner != nil,
Video: imp.Video,
Native: imp.Native,
IncomingSlots: incomingSlots,
Bidders: make(map[string]models.PartnerData),
BidCtx: make(map[string]models.BidCtx),
NewExt: json.RawMessage(newImpExt),
IsAdPodRequest: isAdPodRequest,
}
}

if isAdPodImpression {
bidderMeta[string(openrtb_ext.BidderOWPrebidCTV)] = models.PartnerData{}
}

impCtx := rCtx.ImpBidCtx[imp.ID]
impCtx.Bidders = bidderMeta
impCtx.NonMapped = nonMapped
Expand Down Expand Up @@ -448,7 +471,7 @@ func (m *OpenWrap) applyProfileChanges(rctx models.RequestCtx, bidRequest *openr
}

adunitconfig.ReplaceAppObjectFromAdUnitConfig(rctx, bidRequest.App)
adunitconfig.ReplaceDeviceTypeFromAdUnitConfig(rctx, bidRequest.Device)
adunitconfig.ReplaceDeviceTypeFromAdUnitConfig(rctx, &bidRequest.Device)

bidRequest.Device.IP = rctx.IP
bidRequest.Device.Language = getValidLanguage(bidRequest.Device.Language)
Expand Down
20 changes: 6 additions & 14 deletions modules/pubmatic/openwrap/bidderparams/vast.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,26 @@ import (
"github.com/prebid/prebid-server/modules/pubmatic/openwrap/models"
)

func PrepareVASTBidderParams(rctx models.RequestCtx, cache cache.Cache, bidRequest openrtb2.BidRequest, imp openrtb2.Imp, impExt models.ImpExtension, partnerID int, adpodExt *models.AdPod) (string, json.RawMessage, error) {
func PrepareVASTBidderParams(rctx models.RequestCtx, cache cache.Cache, bidRequest openrtb2.BidRequest, imp openrtb2.Imp, impExt models.ImpExtension, partnerID int, adpodExt *models.AdPod) (string, json.RawMessage, []string, error) {
if imp.Video == nil {
return "", nil, nil
return "", nil, nil, nil
}

slots, slotMap, _, _ := getSlotMeta(rctx, cache, bidRequest, imp, impExt, partnerID)
if len(slots) == 0 {
return "", nil, nil
return "", nil, nil, nil
}

pubVASTTags := cache.GetPublisherVASTTagsFromCache(rctx.PubID)
if len(pubVASTTags) == 0 {
return "", nil, nil
return "", nil, nil, nil
}

matchedSlotKeys, err := getVASTBidderSlotKeys(&imp, slots[0], slotMap, pubVASTTags, adpodExt)
if len(matchedSlotKeys) == 0 {
return "", nil, err
return "", nil, nil, err
}

// NYC_TODO:
//setting flagmap
// bidderWrapper := &BidderWrapper{VASTagFlags: make(map[string]bool)}
// for _, key := range matchedSlotKeys {
// bidderWrapper.VASTagFlags[key] = false
// }
// impWrapper.Bidder[bidderCode] = bidderWrapper

bidParams := adapters.PrepareVASTBidderParamJSON(&bidRequest, &imp, pubVASTTags, matchedSlotKeys, slotMap, adpodExt)

/*
Expand All @@ -50,7 +42,7 @@ func PrepareVASTBidderParams(rctx models.RequestCtx, cache cache.Cache, bidReque
//slotMap:map[/15671365/[email protected]@101:map[param1:6005 param2:test param3:example]]
//Ext:{"tags":[{"tagid":"101","url":"sample_url_1","dur":15,"price":"15","params":{"param1":"6005","param2":"test","param3":"example"}}]}
*/
return slots[0], bidParams, nil
return slots[0], bidParams, matchedSlotKeys, nil
}

// getVASTBidderSlotKeys returns all slot keys which are matching to vast tag slot key
Expand Down
18 changes: 9 additions & 9 deletions modules/pubmatic/openwrap/cache/gocache/adunit_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func Test_cache_populateCacheWithAdunitConfig(t *testing.T) {
type fields struct {
Map sync.Map
cache *gocache.Cache
cfg config.Cache
cfg config.DBCache
db database.Database
}
type args struct {
Expand All @@ -177,7 +177,7 @@ func Test_cache_populateCacheWithAdunitConfig(t *testing.T) {
fields: fields{
cache: gocache.New(10, 10),
db: mockDatabase,
cfg: config.Cache{
cfg: config.DBCache{
CacheDefaultExpiry: 1000,
},
},
Expand All @@ -200,7 +200,7 @@ func Test_cache_populateCacheWithAdunitConfig(t *testing.T) {
fields: fields{
cache: gocache.New(10, 10),
db: mockDatabase,
cfg: config.Cache{
cfg: config.DBCache{
CacheDefaultExpiry: 1000,
},
},
Expand All @@ -223,7 +223,7 @@ func Test_cache_populateCacheWithAdunitConfig(t *testing.T) {
fields: fields{
cache: gocache.New(10, 10),
db: mockDatabase,
cfg: config.Cache{
cfg: config.DBCache{
CacheDefaultExpiry: 1000,
},
},
Expand Down Expand Up @@ -277,7 +277,7 @@ func Test_cache_GetAdunitConfigFromCache(t *testing.T) {
type fields struct {
Map sync.Map
cache *gocache.Cache
cfg config.Cache
cfg config.DBCache
db database.Database
}
type args struct {
Expand All @@ -300,7 +300,7 @@ func Test_cache_GetAdunitConfigFromCache(t *testing.T) {
name: "test_request",
fields: fields{
db: mockDatabase,
cfg: config.Cache{
cfg: config.DBCache{
CacheDefaultExpiry: 1000,
},
},
Expand All @@ -321,7 +321,7 @@ func Test_cache_GetAdunitConfigFromCache(t *testing.T) {
name: "successfully_get_value_from_cache",
fields: fields{
db: mockDatabase,
cfg: config.Cache{
cfg: config.DBCache{
CacheDefaultExpiry: 1000,
},
},
Expand All @@ -345,7 +345,7 @@ func Test_cache_GetAdunitConfigFromCache(t *testing.T) {
name: "got_empty_adunitconfig_from_cache",
fields: fields{
db: mockDatabase,
cfg: config.Cache{
cfg: config.DBCache{
CacheDefaultExpiry: 1000,
},
},
Expand All @@ -370,7 +370,7 @@ func Test_cache_GetAdunitConfigFromCache(t *testing.T) {
fields: fields{
cache: gocache.New(100, 100),
db: mockDatabase,
cfg: config.Cache{
cfg: config.DBCache{
CacheDefaultExpiry: 1000,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestGetFSCDisabledPublishers(t *testing.T) {
type fields struct {
Map sync.Map
cache *gocache.Cache
cfg config.Cache
cfg config.DBCache
db database.Database
}
tests := []struct {
Expand All @@ -49,7 +49,7 @@ func TestGetFSCDisabledPublishers(t *testing.T) {
fields: fields{
cache: gocache.New(100, 100),
db: mockDatabase,
cfg: config.Cache{
cfg: config.DBCache{
CacheDefaultExpiry: 1000,
},
},
Expand All @@ -65,7 +65,7 @@ func TestGetFSCDisabledPublishers(t *testing.T) {
fields: fields{
cache: gocache.New(100, 100),
db: mockDatabase,
cfg: config.Cache{
cfg: config.DBCache{
CacheDefaultExpiry: 1000,
},
},
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestGetFSCThresholdPerDSP(t *testing.T) {
type fields struct {
Map sync.Map
cache *gocache.Cache
cfg config.Cache
cfg config.DBCache
db database.Database
}
tests := []struct {
Expand All @@ -129,7 +129,7 @@ func TestGetFSCThresholdPerDSP(t *testing.T) {
fields: fields{
cache: gocache.New(100, 100),
db: mockDatabase,
cfg: config.Cache{
cfg: config.DBCache{
CacheDefaultExpiry: 1000,
},
},
Expand All @@ -145,7 +145,7 @@ func TestGetFSCThresholdPerDSP(t *testing.T) {
fields: fields{
cache: gocache.New(100, 100),
db: mockDatabase,
cfg: config.Cache{
cfg: config.DBCache{
CacheDefaultExpiry: 1000,
},
},
Expand Down
4 changes: 2 additions & 2 deletions modules/pubmatic/openwrap/cache/gocache/gocache.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ func key(format string, v ...interface{}) string {
type cache struct {
sync.Map
cache *gocache.Cache
cfg config.Cache
cfg config.DBCache
db database.Database
metricEngine metrics.MetricsEngine
}

var c *cache
var cOnce sync.Once

func New(goCache *gocache.Cache, database database.Database, cfg config.Cache, metricEngine metrics.MetricsEngine) *cache {
func New(goCache *gocache.Cache, database database.Database, cfg config.DBCache, metricEngine metrics.MetricsEngine) *cache {
cOnce.Do(
func() {
c = &cache{
Expand Down
Loading
Loading