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-1168: support for traffic shaping based on country code #794

Merged
merged 41 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0235e1e
OTT-1450: add support of Netacuity geoDB for ip-to-geo lookup (#663)
ashishshinde-pubm Dec 18, 2023
de0c4d8
Merge branch 'ci' of github.com:PubMatic-OpenWrap/prebid-server into …
ashishshinde-pubm Dec 27, 2023
1361bda
OTT-1449: Traffic Shapping Framework (#671)
Pubmatic-Dhruv-Sonone Dec 27, 2023
cf2c4f5
OTT-908: Add support to get country from IP address (#679)
Ankit-Pinge Jan 5, 2024
efc892d
OTT-1450: Introduce ignoreNetacuity build flag in validate.sh (#682)
ashishshinde-pubm Jan 18, 2024
0050587
Merge branch 'ci' of https://github.com/PubMatic-OpenWrap/prebid-serv…
Ankit-Pinge Feb 5, 2024
8ebc941
UT fix
Ankit-Pinge Feb 5, 2024
53cf3a2
Merge branch 'ci' of github.com:PubMatic-OpenWrap/prebid-server into …
ashishshinde-pubm Feb 26, 2024
aea8143
OTT-1448: Log seatnonbid rejected due to filtered bidders (#699)
Ankit-Pinge Feb 27, 2024
07f21f5
Merge branch 'ci' of https://github.com/PubMatic-OpenWrap/prebid-serv…
ashishshinde-pubm May 14, 2024
58aab0b
fix merge issues
ashishshinde-pubm May 15, 2024
7596c4d
Fix adapterCode issue
ashishshinde-pubm May 15, 2024
0eb1199
revert gitignore
ashishshinde-pubm May 15, 2024
72a7004
add seatnonbids in responseExt for CTV endpoints
ashishshinde-pubm May 15, 2024
1840dd6
Merge branch 'OTT-1168' of https://github.com/PubMatic-OpenWrap/prebi…
ashishshinde-pubm May 15, 2024
d5fa061
address nitpicks
ashishshinde-pubm May 15, 2024
dcbf0b2
fix debug.adpod missing in CTV request
ashishshinde-pubm May 16, 2024
c05b6ad
fix randomly failing UT
ashishshinde-pubm May 16, 2024
0e61eed
remove traffic shaping changes
pm-nilesh-chate May 17, 2024
9653177
remove used files
pm-nilesh-chate May 17, 2024
19deb0a
traffic shaping changes
pm-nilesh-chate May 17, 2024
5904dcf
Merge branch 'ci' of github.com:PubMatic-OpenWrap/prebid-server into …
ashishshinde-pubm May 17, 2024
abb1941
remove unwanted files
ashishshinde-pubm May 17, 2024
a4efe3d
remove unwanted files
ashishshinde-pubm May 17, 2024
685b5e0
Merge branch 'OTT-1168-traffic-shaping' of github.com:PubMatic-OpenWr…
ashishshinde-pubm May 17, 2024
a0b457b
Traffic Shaping Refactor
Pubmatic-Dhruv-Sonone May 20, 2024
229e0d6
OTT-1168: Traffic shaping refactor
Pubmatic-Dhruv-Sonone May 22, 2024
3561a96
Updating Adunit config
Pubmatic-Dhruv-Sonone May 22, 2024
221204a
Adding UTs
Pubmatic-Dhruv-Sonone May 22, 2024
2e9bd99
Merging latest ci
Pubmatic-Dhruv-Sonone May 22, 2024
9ba901e
Removed unused constant
Pubmatic-Dhruv-Sonone May 22, 2024
87dcd4f
Removing geodb from request context
Pubmatic-Dhruv-Sonone May 22, 2024
32b58f7
Reverting adunit changes
Pubmatic-Dhruv-Sonone May 22, 2024
e52b46f
do not start service if fail to load geodb
ashishshinde-pubm May 22, 2024
937e406
Merge branch 'OTT-1168-traffic-shaping' of github.com:PubMatic-OpenWr…
ashishshinde-pubm May 22, 2024
b88a455
Pulling latest code .
Pubmatic-Dhruv-Sonone May 24, 2024
6c8a22b
Fixing Init Reloader UT
Pubmatic-Dhruv-Sonone May 24, 2024
5809c8f
Fixing adunit unmarshalling issue
Pubmatic-Dhruv-Sonone May 27, 2024
56331b3
Ignoring bidderFilter in partnerConfig for appnexus params
Pubmatic-Dhruv-Sonone May 27, 2024
4a412e2
Removing redundant function params
Pubmatic-Dhruv-Sonone Jun 4, 2024
16db843
Adding Dummy Instance of Netacuity
Pubmatic-Dhruv-Sonone Jun 4, 2024
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ mockgenmetrics:
mkdir -p modules/pubmatic/openwrap/metrics/mock
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/metrics MetricsEngine > modules/pubmatic/openwrap/metrics/mock/mock.go

mockgengeodb:
mkdir -p modules/pubmatic/openwrap/geodb/mock
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/geodb Geography > modules/pubmatic/openwrap/geodb/mock/mock.go

mockgenlogger:
mkdir -p analytics/pubmatic/mhttp/mock
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/analytics/pubmatic/mhttp HttpCallInterface,MultiHttpContextInterface > analytics/pubmatic/mhttp/mock/mock.go
Expand Down
12 changes: 12 additions & 0 deletions analytics/pubmatic/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/prebid/prebid-server/v2/hooks/hookexecution"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/customdimensions"
"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/modules/pubmatic/openwrap/utils"
"github.com/prebid/prebid-server/v2/openrtb_ext"
uuid "github.com/satori/go.uuid"
Expand All @@ -30,6 +31,11 @@ var GetUUID = func() string {
return uuid.NewV4().String()
}

var blockListedNBR = map[openrtb3.NoBidReason]struct{}{
nbr.RequestBlockedPartnerThrottle: {},
nbr.RequestBlockedPartnerFiltered: {},
}

// 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 || rCtx.LoggerDisabled {
Expand Down Expand Up @@ -395,6 +401,12 @@ func getPartnerRecordsByImp(ao analytics.AuctionObject, rCtx *models.RequestCtx)
nbr = bidExt.Nbr // valid-bids + default-bids + dropped-bids
}

if nbr != nil {
if _, ok := blockListedNBR[*nbr]; ok {
continue
}
}

pr := PartnerRecord{
PartnerID: partnerID, // prebid biddercode
BidderCode: seat, // pubmatic biddercode: pubmatic2
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ require (
)

require (
git.pubmatic.com/PubMatic/go-netacuity-client v0.0.0-20240104092757-5d6f15e25fe3
git.pubmatic.com/vastunwrap v0.0.0-00010101000000-000000000000
github.com/diegoholiveira/jsonlogic/v3 v3.5.3
github.com/go-sql-driver/mysql v1.7.1
github.com/golang/mock v1.6.0
github.com/modern-go/reflect2 v1.0.2
Expand All @@ -57,6 +59,7 @@ require (

require (
git.pubmatic.com/PubMatic/go-common v0.0.0-20240313090142-97ff3d63b7c3 // indirect
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df // indirect
github.com/beevik/etree/110 v0.0.0-00010101000000-000000000000 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand All @@ -82,7 +85,6 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
Expand Down
7 changes: 6 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.pubmatic.com/PubMatic/go-common v0.0.0-20240313090142-97ff3d63b7c3 h1:Ea8zwi1eeX4kqvi9RyyXrizIIRcstM0XBwf8U7NHrno=
git.pubmatic.com/PubMatic/go-common v0.0.0-20240313090142-97ff3d63b7c3/go.mod h1:c/I6IcDn4Mtq4mmw8wGJN3v0o10nIMX7VTuQnsalUw0=
git.pubmatic.com/PubMatic/go-netacuity-client v0.0.0-20240104092757-5d6f15e25fe3 h1:zQUpPJOjTBGu2fIydrfRWphH7EWLlBE/Qgn64BSoccI=
git.pubmatic.com/PubMatic/go-netacuity-client v0.0.0-20240104092757-5d6f15e25fe3/go.mod h1:w733mqJnHt0hLR9mIFMzyDR0D94qzc7mFHsuE0tFQho=
git.pubmatic.com/PubMatic/vastunwrap v0.0.0-20240319050712-0b288cbb5a5d h1:BgLUpJQ9Z89eDGz//voK74G/8FgjgVg2PWVbjgCJ4+A=
git.pubmatic.com/PubMatic/vastunwrap v0.0.0-20240319050712-0b288cbb5a5d/go.mod h1:kcoJf7k+xug8X8fLWmsiKhPnYP+k7RZkfUoUo5QF+KA=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand Down Expand Up @@ -83,6 +85,8 @@ github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgI
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/aws/aws-sdk-go v1.36.29/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df h1:GSoSVRLoBaFpOOds6QyY1L8AX7uoY+Ln3BHc22W40X0=
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df/go.mod h1:hiVxq5OP2bUGBRNS3Z/bt/reCLFNbdcST6gISi1fiOM=
github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
Expand Down Expand Up @@ -127,6 +131,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/diegoholiveira/jsonlogic/v3 v3.5.3 h1:CPyZQ3fOgiIDZ1yWzPGUpyht5tYTOnRoN913c0mkXZw=
github.com/diegoholiveira/jsonlogic/v3 v3.5.3/go.mod h1:3nnfWovrlZq2rTpucrJ2KMIS8TMf6IoFneofmeqk/qk=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -508,7 +514,6 @@ github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FB
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI=
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
23 changes: 22 additions & 1 deletion modules/pubmatic/openwrap/beforevalidationhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (m OpenWrap) handleBeforeValidationHook(
rCtx.Platform = getPlatformFromRequest(payload.BidRequest)
rCtx.UA = getUserAgent(payload.BidRequest, rCtx.UA)
rCtx.IP = getIP(payload.BidRequest, rCtx.IP)
rCtx.Country = getCountry(payload.BidRequest)
rCtx.DeviceCtx.Platform = getDevicePlatform(rCtx, payload.BidRequest)
populateDeviceContext(&rCtx.DeviceCtx, payload.BidRequest.Device)

Expand Down Expand Up @@ -163,7 +164,11 @@ func (m OpenWrap) handleBeforeValidationHook(
//TMax should be updated after ABTest processing
rCtx.TMax = m.setTimeout(rCtx, payload.BidRequest)

var allPartnersThrottledFlag bool
var (
allPartnersThrottledFlag bool
allPartnersFilteredFlag bool
)

rCtx.AdapterThrottleMap, allPartnersThrottledFlag = GetAdapterThrottleMap(rCtx.PartnerConfigMap)

if allPartnersThrottledFlag {
Expand All @@ -173,6 +178,17 @@ func (m OpenWrap) handleBeforeValidationHook(
return result, err
}

rCtx.AdapterFilteredMap, allPartnersFilteredFlag = m.getFilteredBidders(rCtx, payload.BidRequest)

result.SeatNonBid = getSeatNonBid(rCtx.AdapterFilteredMap, payload)

if allPartnersFilteredFlag {
result.NbrCode = int(nbr.AllPartnersFiltered)
result.Errors = append(result.Errors, "All partners filtered")
rCtx.ImpBidCtx = getDefaultImpBidCtx(*payload.BidRequest) // for wrapper logger sz
return result, err
}

priceGranularity, err := computePriceGranularity(rCtx)
if err != nil {
result.NbrCode = int(nbr.InvalidPriceGranularityConfig)
Expand Down Expand Up @@ -328,6 +344,11 @@ func (m OpenWrap) handleBeforeValidationHook(
//
rCtx.PrebidBidderCode[prebidBidderCode] = bidderCode

if _, ok := rCtx.AdapterFilteredMap[bidderCode]; ok {
result.Warnings = append(result.Warnings, "Dropping adapter due to bidder filtering: "+bidderCode)
continue
}

if _, ok := rCtx.AdapterThrottleMap[bidderCode]; ok {
result.Warnings = append(result.Warnings, "Dropping throttled adapter from auction: "+bidderCode)
continue
Expand Down
109 changes: 108 additions & 1 deletion modules/pubmatic/openwrap/beforevalidationhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var rctx = models.RequestCtx{
ProfileIDStr: "1234",
Endpoint: models.EndpointV25,
SeatNonBids: make(map[string][]openrtb_ext.NonBid),
Country: "IND",
}

func getTestBidRequest(isSite bool) *openrtb2.BidRequest {
Expand Down Expand Up @@ -2445,6 +2446,113 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
},
wantErr: false,
},
{
name: "Some_partners_filtered",
args: args{
ctx: context.Background(),
moduleCtx: hookstage.ModuleInvocationContext{
ModuleContext: hookstage.ModuleContext{
"rctx": rctx,
},
},
bidrequest: json.RawMessage(`{"device":{"geo":{"country":"IN"}},"id":"123-456-789","imp":[{"id":"123","banner":{"format":[{"w":728,"h":90},{"w":300,"h":250}],"w":700,"h":900},"video":{"mimes":["video/mp4","video/mpeg"],"w":640,"h":480},"tagid":"","ext":{"wrapper":{"div":"div"},"bidder":{"pubmatic":{"keywords":[{"key":"pmzoneid","value":["val1","val2"]}]}},"prebid":{}}}],"site":{"domain":"test.com","page":"www.test.com","publisher":{"id":"5890"}},"device":{"ua":"Mozilla/5.0(X11;Linuxx86_64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/52.0.2743.82Safari/537.36","ip":"123.145.167.10"},"user":{"id":"119208432","buyeruid":"1rwe432","yob":1980,"gender":"F","geo":{"country":"US","region":"CA","metro":"90001","city":"Alamo"}},"wseat":["Wseat_0","Wseat_1"],"bseat":["Bseat_0","Bseat_1"],"cur":["cur_0","cur_1"],"wlang":["Wlang_0","Wlang_1"],"bcat":["bcat_0","bcat_1"],"badv":["badv_0","badv_1"],"bapp":["bapp_0","bapp_1"],"source":{"ext":{"omidpn":"MyIntegrationPartner","omidpv":"7.1"}},"ext":{"prebid":{},"wrapper":{"test":123,"profileid":123,"versionid":1,"wiid":"test_display_wiid"}}}`),
},
fields: fields{
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PARTNER_ID: "2",
models.PREBID_PARTNER_NAME: "appnexus",
models.BidderCode: "appnexus",
models.SERVER_SIDE_FLAG: "1",
models.KEY_GEN_PATTERN: "_AU_@_W_x_H_",
models.TIMEOUT: "200",
models.THROTTLE: "100",
models.BidderFilters: `{ "in": [{ "var": "country"}, ["USA"]]}`,
},
3: {
models.PARTNER_ID: "3",
models.PREBID_PARTNER_NAME: "pubmatic",
models.BidderCode: "pubmatic",
models.SERVER_SIDE_FLAG: "1",
models.KEY_GEN_PATTERN: "_AU_@_W_x_H_",
models.TIMEOUT: "200",
models.THROTTLE: "100",
},
-1: {
models.DisplayVersionID: "1",
models.PLATFORM_KEY: models.PLATFORM_APP,
},
}, nil)
mockCache.EXPECT().GetAdunitConfigFromCache(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&adunitconfig.AdUnitConfig{})

//prometheus metrics
mockEngine.EXPECT().RecordPublisherProfileRequests("5890", "1234")
mockEngine.EXPECT().RecordBadRequests(rctx.Endpoint, getPubmaticErrorCode(nbr.InvalidImpressionTagID))
mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("5890", int(nbr.InvalidImpressionTagID))
mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform)
mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false)
mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false)
},
want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{
Reject: true,
NbrCode: int(nbr.InvalidImpressionTagID),
Errors: []string{"tagid missing for imp: 123"},
SeatNonBid: getNonBids(map[string][]openrtb_ext.NonBidParams{"appnexus": {{Bid: &openrtb2.Bid{ImpID: "123"}, NonBidReason: int(nbr.RequestBlockedPartnerFiltered)}}}),
},
wantErr: true,
},
{
name: "All_partners_filtered",
args: args{
ctx: context.Background(),
moduleCtx: hookstage.ModuleInvocationContext{
ModuleContext: hookstage.ModuleContext{
"rctx": rctx,
},
},
bidrequest: json.RawMessage(`{"device":{"geo":{"country":"in"}},"id":"123-456-789","imp":[{"id":"123","banner":{"format":[{"w":728,"h":90},{"w":300,"h":250}],"w":700,"h":900},"video":{"mimes":["video/mp4","video/mpeg"],"w":640,"h":480},"tagid":"","ext":{"wrapper":{"div":"div"},"bidder":{"pubmatic":{"keywords":[{"key":"pmzoneid","value":["val1","val2"]}]}},"prebid":{}}}],"site":{"domain":"test.com","page":"www.test.com","publisher":{"id":"5890"}},"device":{"ua":"Mozilla/5.0(X11;Linuxx86_64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/52.0.2743.82Safari/537.36","ip":"123.145.167.10"},"user":{"id":"119208432","buyeruid":"1rwe432","yob":1980,"gender":"F","geo":{"country":"US","region":"CA","metro":"90001","city":"Alamo"}},"wseat":["Wseat_0","Wseat_1"],"bseat":["Bseat_0","Bseat_1"],"cur":["cur_0","cur_1"],"wlang":["Wlang_0","Wlang_1"],"bcat":["bcat_0","bcat_1"],"badv":["badv_0","badv_1"],"bapp":["bapp_0","bapp_1"],"source":{"ext":{"omidpn":"MyIntegrationPartner","omidpv":"7.1"}},"ext":{"prebid":{},"wrapper":{"test":123,"profileid":123,"versionid":1,"wiid":"test_display_wiid"}}}`),
},
fields: fields{
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PARTNER_ID: "2",
models.PREBID_PARTNER_NAME: "appnexus",
models.BidderCode: "appnexus",
models.SERVER_SIDE_FLAG: "1",
models.KEY_GEN_PATTERN: "_AU_@_W_x_H_",
models.TIMEOUT: "200",
models.THROTTLE: "100",
models.BidderFilters: `{ "in": [{ "var": "country"}, ["USA"]]}`,
},
-1: {
models.DisplayVersionID: "1",
models.PLATFORM_KEY: models.PLATFORM_APP,
},
}, nil)
//prometheus metrics
mockEngine.EXPECT().RecordPublisherProfileRequests("5890", "1234")
mockEngine.EXPECT().RecordBadRequests(rctx.Endpoint, getPubmaticErrorCode(nbr.AllPartnersFiltered))
mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("5890", int(nbr.AllPartnersFiltered))
mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform)
mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false)
mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false)
},
want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{
Reject: true,
NbrCode: int(nbr.AllPartnersFiltered),
Errors: []string{"All partners filtered"},
SeatNonBid: getNonBids(map[string][]openrtb_ext.NonBidParams{"appnexus": {{Bid: &openrtb2.Bid{ImpID: "123"}, NonBidReason: int(nbr.RequestBlockedPartnerFiltered)}}}),
},
wantErr: false,
},
{
name: "TagID_not_present_in_imp",
args: args{
Expand Down Expand Up @@ -4032,7 +4140,6 @@ func TestImpBidCtx_handleBeforeValidationHook(t *testing.T) {
},
}, nil)
mockCache.EXPECT().GetAdunitConfigFromCache(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&adunitconfig.AdUnitConfig{})

//prometheus metrics
mockEngine.EXPECT().RecordPublisherProfileRequests("5890", "1234")
mockEngine.EXPECT().RecordBadRequests(rctx.Endpoint, getPubmaticErrorCode(nbr.InternalError))
Expand Down
1 change: 1 addition & 0 deletions modules/pubmatic/openwrap/bidderparams/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var ignoreKeys = map[string]bool{
models.BidderCode: true,
models.IsAlias: true,
models.VENDORID: true,
models.BidderFilters: true,
}

func getSlotMeta(rctx models.RequestCtx, cache cache.Cache, bidRequest openrtb2.BidRequest, imp openrtb2.Imp, impExt models.ImpExtension, partnerID int) ([]string, map[string]models.SlotMapping, models.SlotMappingInfo, [][2]int64) {
Expand Down
13 changes: 11 additions & 2 deletions modules/pubmatic/openwrap/cache/gocache/adunit_config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gocache

import (
"encoding/json"
"fmt"
"strings"
"sync"
Expand All @@ -25,6 +26,14 @@ var testAdunitConfig = &adunitconfig.AdUnitConfig{
Regex: true,
Config: map[string]*adunitconfig.AdConfig{
"default": {
BidderFilter: &adunitconfig.BidderFilter{
Pubmatic-Dhruv-Sonone marked this conversation as resolved.
Show resolved Hide resolved
Filters: []adunitconfig.Filter{
{
Bidders: []string{"bidderA"},
BiddingConditions: json.RawMessage(`{ "in": [{ "var": "country"}, ["IND"]]}`),
},
},
},
Floors: &openrtb_ext.PriceFloorRules{
FloorMin: 15,
Data: &openrtb_ext.PriceFloorData{
Expand Down Expand Up @@ -144,7 +153,7 @@ var testAdunitConfig = &adunitconfig.AdUnitConfig{
},
}

func Test_cache_populateCacheWithAdunitConfig(t *testing.T) {
func TestCachePopulateCacheWithAdunitConfig(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockDatabase := mock_database.NewMockDatabase(ctrl)
Expand Down Expand Up @@ -268,7 +277,7 @@ func Test_cache_populateCacheWithAdunitConfig(t *testing.T) {
}
}

func Test_cache_GetAdunitConfigFromCache(t *testing.T) {
func TestCacheGetAdunitConfigFromCache(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockDatabase := mock_database.NewMockDatabase(ctrl)
Expand Down
35 changes: 35 additions & 0 deletions modules/pubmatic/openwrap/cache/gocache/partner_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,41 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI
return err
}

c.updatePartnerConfigWithBidderFilters(partnerConfigMap, pubID, profileID, displayVersion)
c.cache.Set(cacheKey, partnerConfigMap, getSeconds(c.cfg.CacheDefaultExpiry))
return
}

func (c *cache) updatePartnerConfigWithBidderFilters(partnerConfigs map[int]map[string]string, pubID, profileID, displayVersion int) {

cacheKey := key(PubAdunitConfig, pubID, profileID, displayVersion)
obj, ok := c.cache.Get(cacheKey)
if !ok {
return
}

adUnitCfg, ok := obj.(*adunitconfig.AdUnitConfig)
if !ok || adUnitCfg == nil {
return
}

bidderfilter := map[string]string{}
defaultAdUnitConfig := adUnitCfg.Config["default"]
if defaultAdUnitConfig.BidderFilter != nil {
for _, filter := range defaultAdUnitConfig.BidderFilter.Filters {
for _, bidder := range filter.Bidders {
bidderfilter[bidder] = string(filter.BiddingConditions)
}
}
}

if len(bidderfilter) == 0 {
return
}

for id, cfg := range partnerConfigs {
if biddingCodition, ok := bidderfilter[cfg[models.BidderCode]]; ok {
partnerConfigs[id][models.BidderFilters] = biddingCodition
}
}
}
Loading
Loading