Skip to content

Commit

Permalink
Merge pull request #741 from PubMatic-OpenWrap/ci
Browse files Browse the repository at this point in the history
Openwrap_Release_4th_April_2024
  • Loading branch information
pm-viral-vala authored Apr 3, 2024
2 parents a370e4e + 86a02b5 commit d9d3c9a
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 118 deletions.
119 changes: 60 additions & 59 deletions modules/pubmatic/openwrap/models/constants.go
Original file line number Diff line number Diff line change
@@ -1,65 +1,66 @@
package models

const (
DEFAULT_PUB_ID = 34576 // Default PubID to get generic data like regex for browsers etc
PARTNER_ID = "partnerId"
ADAPTER_ID = "adapterId"
PARTNER_ACCOUNT_NAME = "partnerName"
ADAPTER_NAME = "adapterName"
PREBID_PARTNER_NAME = "prebidPartnerName"
BidderCode = "bidderCode"
IsAlias = "isAlias"
PROTOCOL = "protocol"
SERVER_SIDE_FLAG = "serverSideEnabled"
DisplayVersionID = "displayVersionId"
KEY_PUBLISHER_ID = "publisherId"
KEY_PROFILE_ID = "profileId"
KEY_SLOT_NAME = "slotName"
LEVEL = "level"
KEY_GEN_PATTERN = "kgp"
TIMEOUT = "timeout"
AdserverKey = "adserver"
MopubAdserver = "MoPub"
CustomAdserver = "CUSTOM"
PriceGranularityKey = "priceGranularity"
VideoAdDurationKey = "videoAdDuration"
VideoAdDurationMatchingKey = "videoAdDurationMatching"
REVSHARE = "rev_share"
THROTTLE = "throttle"
REFRESH_INTERVAL = "refreshInterval"
CreativeType = "crtype"
GDPR_ENABLED = "gdpr"
PLATFORM_KEY = "platform"
SendAllBidsKey = "sendAllBids"
VastUnwrapperEnableKey = "enableVastUnwrapper"
SSTimeoutKey = "ssTimeout"
PWC = "awc"
MAX_SLOT_COUNT = 5000
SITE_CACHE_KEY = "site"
TAG_CACHE_KEY = "adtag"
GA_ID_CACHE_KEY = "gaid"
FLOOR_CACHE_KEY = "floor"
PUBMATIC = "PubMatic"
PUBMATIC_TIMEOUT = "PubmaticTimeout"
PUBMATIC_PROTOCOL = "/gads"
PUBMATIC_LEVEL = "multi"
PUBMATIC_SS_FLAG = "1"
PUBMATIC_PARTNER_ID_STRING = "1"
PUBMATIC_ADAPTER_ID_STRING = "1"
VersionLevelConfigID = -1
ERROR_CODE = "ErrorCode"
ERROR_STRING = "Error"
PUBMATIC_PARTNER_ID = 1
PUBMATIC_ADAPTER_ID = 1
DEFAULT_STRING = ""
DEFAULT_INT = 0
DEFAULT_FLOAT = 0.00
BID_PRECISION = 2
Debug = "debug"
WrapperLoggerDebug = "owLoggerDebug"
KEY_OW_SLOT_NAME = "owSlotName"
VENDORID = "vendorId"
BidderPubMatic = "pubmatic"
DEFAULT_PUB_ID = 34576 // Default PubID to get generic data like regex for browsers etc
PARTNER_ID = "partnerId"
ADAPTER_ID = "adapterId"
PARTNER_ACCOUNT_NAME = "partnerName"
ADAPTER_NAME = "adapterName"
PREBID_PARTNER_NAME = "prebidPartnerName"
BidderCode = "bidderCode"
IsAlias = "isAlias"
PROTOCOL = "protocol"
SERVER_SIDE_FLAG = "serverSideEnabled"
DisplayVersionID = "displayVersionId"
KEY_PUBLISHER_ID = "publisherId"
KEY_PROFILE_ID = "profileId"
KEY_SLOT_NAME = "slotName"
LEVEL = "level"
KEY_GEN_PATTERN = "kgp"
TIMEOUT = "timeout"
AdserverKey = "adserver"
MopubAdserver = "MoPub"
CustomAdserver = "CUSTOM"
PriceGranularityKey = "priceGranularity"
VideoAdDurationKey = "videoAdDuration"
VideoAdDurationMatchingKey = "videoAdDurationMatching"
REVSHARE = "rev_share"
THROTTLE = "throttle"
REFRESH_INTERVAL = "refreshInterval"
CreativeType = "crtype"
GDPR_ENABLED = "gdpr"
PLATFORM_KEY = "platform"
SendAllBidsKey = "sendAllBids"
VastUnwrapperEnableKey = "enableVastUnwrapper"
VastUnwrapTrafficPercentKey = "vastUnwrapTrafficPercent"
SSTimeoutKey = "ssTimeout"
PWC = "awc"
MAX_SLOT_COUNT = 5000
SITE_CACHE_KEY = "site"
TAG_CACHE_KEY = "adtag"
GA_ID_CACHE_KEY = "gaid"
FLOOR_CACHE_KEY = "floor"
PUBMATIC = "PubMatic"
PUBMATIC_TIMEOUT = "PubmaticTimeout"
PUBMATIC_PROTOCOL = "/gads"
PUBMATIC_LEVEL = "multi"
PUBMATIC_SS_FLAG = "1"
PUBMATIC_PARTNER_ID_STRING = "1"
PUBMATIC_ADAPTER_ID_STRING = "1"
VersionLevelConfigID = -1
ERROR_CODE = "ErrorCode"
ERROR_STRING = "Error"
PUBMATIC_PARTNER_ID = 1
PUBMATIC_ADAPTER_ID = 1
DEFAULT_STRING = ""
DEFAULT_INT = 0
DEFAULT_FLOAT = 0.00
BID_PRECISION = 2
Debug = "debug"
WrapperLoggerDebug = "owLoggerDebug"
KEY_OW_SLOT_NAME = "owSlotName"
VENDORID = "vendorId"
BidderPubMatic = "pubmatic"
//ADSERVER_URL used by S2S to redirect the OW bids if owredirect parameter is not found in video/json
ADSERVER_URL = "adServerUrl"

Expand Down
14 changes: 12 additions & 2 deletions modules/pubmatic/openwrap/openwrap_sshb.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package openwrap

import (
"strconv"

"github.com/prebid/openrtb/v19/openrtb2"
cache "github.com/prebid/prebid-server/modules/pubmatic/openwrap/cache"
"github.com/prebid/prebid-server/modules/pubmatic/openwrap/config"
Expand Down Expand Up @@ -44,7 +46,7 @@ func (ow *OpenWrap) SetMetricEngine(m metrics.MetricsEngine) {
ow.metricEngine = m
}

// GetVastUnwrapEnabled function return vastunwrap flag from the database
// GetVastUnwrapEnabled return whether to enable vastunwrap or not
func GetVastUnwrapEnabled(rctx vastmodels.RequestCtx) bool {
rCtx := models.RequestCtx{
Endpoint: rctx.Endpoint,
Expand All @@ -57,5 +59,13 @@ func GetVastUnwrapEnabled(rctx vastmodels.RequestCtx) bool {
return false
}
rCtx.PartnerConfigMap = partnerConfigMap
return models.GetVersionLevelPropertyFromPartnerConfig(rCtx.PartnerConfigMap, models.VastUnwrapperEnableKey) == VastUnwrapperEnableValue
unwrapEnabled := models.GetVersionLevelPropertyFromPartnerConfig(rCtx.PartnerConfigMap, models.VastUnwrapperEnableKey)
if unwrapEnabled == VastUnwrapperEnableValue {
trafficPercentage, err := strconv.Atoi(models.GetVersionLevelPropertyFromPartnerConfig(rCtx.PartnerConfigMap, models.VastUnwrapTrafficPercentKey))
if err == nil {
return GetRandomNumberIn1To100() <= trafficPercentage

}
}
return false
}
123 changes: 123 additions & 0 deletions modules/pubmatic/openwrap/openwrap_sshb_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package openwrap

import (
"errors"
"testing"

"github.com/golang/mock/gomock"
"github.com/magiconair/properties/assert"
mock_cache "github.com/prebid/prebid-server/modules/pubmatic/openwrap/cache/mock"
"github.com/prebid/prebid-server/modules/pubmatic/openwrap/models"
vastmodels "github.com/prebid/prebid-server/modules/pubmatic/vastunwrap/models"
)

func TestGetVastUnwrapEnabled(t *testing.T) {
type args struct {
rctx vastmodels.RequestCtx
}

ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockCache := mock_cache.NewMockCache(ctrl)

tests := []struct {
name string
args args
setup func()
randomNumber int
want bool
}{
{
name: "vastunwrap is enabled and trafficpercent is greater than random number",
args: args{rctx: vastmodels.RequestCtx{
PubID: 5890,
ProfileID: 123,
DisplayID: 1,
}},
setup: func() {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
-1: {
models.VastUnwrapperEnableKey: "1",
models.VastUnwrapTrafficPercentKey: "90",
},
}, nil)
},
randomNumber: 80,
want: true,
},
{
name: "vastunwrap is enabled and trafficpercent is less than random number",
args: args{rctx: vastmodels.RequestCtx{
PubID: 5890,
ProfileID: 123,
DisplayID: 1,
}},
setup: func() {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
-1: {
models.VastUnwrapperEnableKey: "1",
models.VastUnwrapTrafficPercentKey: "90",
},
}, nil)
},
randomNumber: 91,
want: false,
},
{
name: "vastunwrap is dissabled and trafficpercent is less than random number",
args: args{rctx: vastmodels.RequestCtx{
PubID: 5890,
ProfileID: 123,
DisplayID: 1,
}},
setup: func() {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
-1: {
models.VastUnwrapperEnableKey: "0",
},
}, nil)
},
randomNumber: 91,
want: false,
},
{
name: "partnerconfigmap not found",
args: args{rctx: vastmodels.RequestCtx{
PubID: 5890,
ProfileID: 123,
DisplayID: 1,
}},
setup: func() {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
},
randomNumber: 91,
want: false,
},
{
name: "error while fetching partnerconfigmap ",
args: args{rctx: vastmodels.RequestCtx{
PubID: 5890,
ProfileID: 123,
DisplayID: 1,
}},
setup: func() {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("some error"))
},
randomNumber: 91,
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.setup()
GetRandomNumberIn1To100 = func() int {
return tt.randomNumber
}
ow = &OpenWrap{
cache: mockCache,
}
got := GetVastUnwrapEnabled(tt.args.rctx)
assert.Equal(t, got, tt.want)
})
}
}
5 changes: 0 additions & 5 deletions modules/pubmatic/vastunwrap/entryhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package vastunwrap
import (
"context"
"fmt"
"math/rand"
"runtime/debug"

"github.com/golang/glog"
Expand All @@ -13,10 +12,6 @@ import (
"github.com/prebid/prebid-server/modules/pubmatic/vastunwrap/models"
)

var getRandomNumber = func() int {
return rand.Intn(100)
}

// supportedEndpoints holds the list of endpoints which supports VAST-unwrap feature
var supportedEndpoints = map[string]struct{}{
ow_models.EndpointVAST: {},
Expand Down
44 changes: 23 additions & 21 deletions modules/pubmatic/vastunwrap/hook_raw_bidder_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"

"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/modules/pubmatic/openwrap"
"github.com/prebid/prebid-server/modules/pubmatic/vastunwrap/models"

"github.com/prebid/prebid-server/hooks/hookstage"
Expand All @@ -25,32 +26,14 @@ func (m VastUnwrapModule) handleRawBidderResponseHook(
if !vastRequestContext.Redirect {
pubId, _ := strconv.Atoi(miCtx.AccountID)
vastRequestContext.PubID = pubId
vastUnwrapEnabled = getRandomNumber() < m.TrafficPercentage && m.getVastUnwrapEnable(vastRequestContext)
vastUnwrapEnabled = m.getVastUnwrapEnabled(vastRequestContext)
result.DebugMessages = append(result.DebugMessages,
fmt.Sprintf("found request without sshb=1 in handleRawBidderResponseHook() for pubid:[%d]", vastRequestContext.PubID))
}

vastRequestContext.VastUnwrapEnabled = vastUnwrapEnabled
if !vastUnwrapEnabled {
vastRequestContext.VastUnwrapStatsEnabled = getRandomNumber() < m.StatTrafficPercentage
}

if !vastRequestContext.VastUnwrapEnabled && !vastRequestContext.VastUnwrapStatsEnabled {
result.DebugMessages = append(result.DebugMessages,
fmt.Sprintf("error: vast unwrap flag is not enabled in handleRawBidderResponseHook() for pubid:[%d]", vastRequestContext.PubID))
return result, nil
}

// Below code collects stats only
if vastRequestContext.VastUnwrapStatsEnabled {
for _, bid := range payload.Bids {
if string(bid.BidType) == MediaTypeVideo {
go func(bid *adapters.TypedBid) {
m.doUnwrapandUpdateBid(vastRequestContext.VastUnwrapStatsEnabled, bid, vastRequestContext.UA, vastRequestContext.IP, unwrapURL, miCtx.AccountID, payload.Bidder)
}(bid)
}
}
} else {
if vastRequestContext.VastUnwrapEnabled {
// Do Unwrap and Update Adm
wg := new(sync.WaitGroup)
for _, bid := range payload.Bids {
if string(bid.BidType) == MediaTypeVideo {
Expand All @@ -65,6 +48,25 @@ func (m VastUnwrapModule) handleRawBidderResponseHook(
changeSet := hookstage.ChangeSet[hookstage.RawBidderResponsePayload]{}
changeSet.RawBidderResponse().Bids().Update(payload.Bids)
result.ChangeSet = changeSet
} else {
vastRequestContext.VastUnwrapStatsEnabled = openwrap.GetRandomNumberIn1To100() <= m.StatTrafficPercentage
if vastRequestContext.VastUnwrapStatsEnabled {
// Do Unwrap and Collect stats only
for _, bid := range payload.Bids {
if string(bid.BidType) == MediaTypeVideo {
go func(bid *adapters.TypedBid) {
m.doUnwrapandUpdateBid(vastRequestContext.VastUnwrapStatsEnabled, bid, vastRequestContext.UA, vastRequestContext.IP, unwrapURL, miCtx.AccountID, payload.Bidder)
}(bid)
}
}
}
}

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

return result, nil
}
Loading

0 comments on commit d9d3c9a

Please sign in to comment.