Skip to content

Commit

Permalink
Fix: Set bid meta adaptercode to adapter name (#3661)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsardo committed May 9, 2024
1 parent 6cef5f9 commit 2c39db7
Show file tree
Hide file tree
Showing 68 changed files with 261 additions and 193 deletions.
6 changes: 5 additions & 1 deletion endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ func TestJsonSampleRequests(t *testing.T) {
"invalid-native",
},
{
"Makes sure we handle (default) aliased bidders properly",
"Makes sure we handle aliased bidders properly",
"aliased",
},
{
"Makes sure we handle alternate bidder codes properly",
"alternate-bidder-code",
},
{
"Asserts we return 500s on requests referencing accounts with malformed configs.",
"account-malformed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@
{
"id": "appnexus-bid",
"impid": "my-imp-id",
"price": 0
"price": 0,
"ext": {
"origbidcpm": 0,
"origbidcur": "USD",
"prebid": {
"meta": {
"adaptercode": "appnexus"
},
"type": "banner"
}
}
}
],
"seat": "alias1"
Expand Down
62 changes: 62 additions & 0 deletions endpoints/openrtb2/sample-requests/aliased/hard-alias.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"description": "Imp extension references valid bidder alias of adf defined in the adform bidder infos config yaml file.",
"config": {
"mockBidders": [
{
"bidderName": "adform",
"currency": "USD",
"price": 2
}
]
},
"mockBidRequest": {
"id": "some-request-id",
"site": {
"page": "test.somepage.com"
},
"imp": [
{
"id": "my-imp-id",
"video": {
"mimes": [
"video/mp4"
]
},
"ext": {
"adform": {
"mid": "123"
}
}
}
]
},
"expectedBidResponse": {
"id":"some-request-id",
"bidid":"test bid id",
"cur": "USD",
"nbr":0,
"seatbid": [
{
"bid": [
{
"id": "adform-bid",
"impid": "my-imp-id",
"price": 2,
"ext": {
"origbidcpm": 2,
"origbidcur": "USD",
"prebid": {
"meta": {
"adaptercode": "adform"
},
"type": "banner"
}
}
}
],
"seat": "adform"
}
]
},
"expectedReturnCode": 200
}
61 changes: 61 additions & 0 deletions endpoints/openrtb2/sample-requests/aliased/request-alias.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"description": "Imp extension references valid bidder alias of appnexus defined in the request ext.prebid.aliases field.",
"mockBidRequest": {
"id": "some-request-id",
"site": {
"page": "test.somepage.com"
},
"imp": [
{
"id": "my-imp-id",
"video": {
"mimes": [
"video/mp4"
]
},
"ext": {
"alias1": {
"placementId": 12883451
}
}
}
],
"ext": {
"prebid": {
"aliases": {
"alias1": "appnexus"
}
}
}
},
"expectedBidResponse": {
"id":"some-request-id",
"bidid":"test bid id",
"cur": "USD",
"nbr":0,
"seatbid": [
{
"bid": [
{
"id": "appnexus-bid",
"impid": "my-imp-id",
"price": 0,
"ext": {
"origbidcpm": 0,
"origbidcur": "USD",
"prebid": {
"meta": {
"adaptercode": "appnexus"
},
"type": "banner"
}
}
}
],
"seat": "alias1"
}
]
},
"expectedReturnCode": 200
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"description": "Imp extension doesn't come with valid bidder name but does come with valid bidder alias as defined in the mockAliases list.",
"config": {
"mockBidders": [
{
"bidderName": "appnexus",
"currency": "USD",
"price": 2,
"seat": "groupm"
}
]
},
"mockBidRequest": {
"id": "some-request-id",
"site": {
"page": "test.somepage.com",
"publisher": {
"id": "alternate_bidder_code_acct"
}
},
"imp": [
{
"id": "my-imp-id",
"video": {
"mimes": [
"video/mp4"
]
},
"ext": {
"appnexus": {
"placementId": 12883451
}
}
}
]
},
"expectedBidResponse": {
"id":"some-request-id",
"bidid":"test bid id",
"cur": "USD",
"nbr":0,
"seatbid": [
{
"bid": [
{
"id": "appnexus-bid",
"impid": "my-imp-id",
"price": 2,
"ext": {
"origbidcpm": 2,
"origbidcur": "USD",
"prebid": {
"meta": {
"adaptercode": "appnexus"
},
"type": "banner"
}
}
}
],
"seat": "groupm"
}
]
},
"expectedReturnCode": 200
}

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@
{
"id": "appnexus-bid",
"impid": "some-impression-id",
"price": 0
"price": 0,
"ext": {
"origbidcpm": 0,
"origbidcur": "USD",
"prebid": {
"meta": {
"adaptercode": "appnexus"
},
"type": "banner"
}
}
}
],
"seat": "appnexus"
Expand Down
34 changes: 30 additions & 4 deletions endpoints/openrtb2/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ type mockBidderHandler struct {
Currency string `json:"currency"`
Price float64 `json:"price"`
DealID string `json:"dealid"`
Seat string `json:"seat"`
}

func (b mockBidderHandler) bid(w http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -999,6 +1000,7 @@ func (b mockBidderHandler) bid(w http.ResponseWriter, req *http.Request) {
type mockAdapter struct {
mockServerURL string
Server config.Server
seat string
}

func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
Expand Down Expand Up @@ -1064,6 +1066,9 @@ func (a mockAdapter) MakeBids(request *openrtb2.BidRequest, requestData *adapter
Bid: &seatBid.Bid[i],
BidType: openrtb_ext.BidTypeBanner,
}
if len(a.seat) > 0 {
b.Seat = openrtb_ext.BidderName(a.seat)
}
rv.Bids = append(rv.Bids, b)
}
}
Expand Down Expand Up @@ -1091,6 +1096,24 @@ func getBidderInfos(disabledAdapters []string, biddersNames []openrtb_ext.Bidder
return biddersInfos
}

func enableBidders(bidderInfos config.BidderInfos) {
for name, bidderInfo := range bidderInfos {
if bidderInfo.Disabled {
bidderInfo.Disabled = false
bidderInfos[name] = bidderInfo
}
}
}

func disableBidders(disabledAdapters []string, bidderInfos config.BidderInfos) {
for _, disabledAdapter := range disabledAdapters {
if bidderInfo, ok := bidderInfos[disabledAdapter]; ok {
bidderInfo.Disabled = true
bidderInfos[disabledAdapter] = bidderInfo
}
}
}

func newBidderInfo(isDisabled bool) config.BidderInfo {
return config.BidderInfo{
Disabled: isDisabled,
Expand Down Expand Up @@ -1179,7 +1202,7 @@ func buildTestExchange(testCfg *testConfigValues, adapterMap map[openrtb_ext.Bid
}
for _, mockBidder := range testCfg.MockBidders {
bidServer := httptest.NewServer(http.HandlerFunc(mockBidder.bid))
bidderAdapter := mockAdapter{mockServerURL: bidServer.URL}
bidderAdapter := mockAdapter{mockServerURL: bidServer.URL, seat: mockBidder.Seat}
bidderName := openrtb_ext.BidderName(mockBidder.BidderName)

adapterMap[bidderName] = exchange.AdaptBidder(bidderAdapter, bidServer.Client(), &config.Configuration{}, &metricsConfig.NilMetricsEngine{}, bidderName, nil, "")
Expand Down Expand Up @@ -1231,7 +1254,9 @@ func buildTestEndpoint(test testCase, cfg *config.Configuration) (httprouter.Han
paramValidator = mockBidderParamValidator{}
}

bidderInfos := getBidderInfos(test.Config.DisabledAdapters, openrtb_ext.CoreBidderNames())
bidderInfos, _ := config.LoadBidderInfoFromDisk("../../static/bidder-info")
enableBidders(bidderInfos)
disableBidders(test.Config.DisabledAdapters, bidderInfos)
bidderMap := exchange.GetActiveBidders(bidderInfos)
disabledBidders := exchange.GetDisabledBidderWarningMessages(bidderInfos)
met := &metricsConfig.NilMetricsEngine{}
Expand Down Expand Up @@ -1267,8 +1292,9 @@ func buildTestEndpoint(test testCase, cfg *config.Configuration) (httprouter.Han

accountFetcher := &mockAccountFetcher{
data: map[string]json.RawMessage{
"malformed_acct": json.RawMessage(`{"disabled":"invalid type"}`),
"disabled_acct": json.RawMessage(`{"disabled":true}`),
"malformed_acct": json.RawMessage(`{"disabled":"invalid type"}`),
"disabled_acct": json.RawMessage(`{"disabled":true}`),
"alternate_bidder_code_acct": json.RawMessage(`{"disabled":false,"alternatebiddercodes":{"enabled":true,"bidders":{"appnexus":{"enabled":true,"allowedbiddercodes":["groupm"]}}}}`),
},
}

Expand Down
1 change: 1 addition & 0 deletions exchange/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ func (bidder *bidderAdapter) requestBid(ctx context.Context, bidderRequest Bidde
DealPriority: bidResponse.Bids[i].DealPriority,
OriginalBidCPM: originalBidCpm,
OriginalBidCur: bidResponse.Currency,
AdapterCode: bidderRequest.BidderCoreName,
})
seatBidMap[bidderName].Currency = currencyAfterAdjustments
}
Expand Down
1 change: 1 addition & 0 deletions exchange/entities/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ type PbsOrtbBid struct {
OriginalBidCPM float64
OriginalBidCur string
TargetBidderCode string
AdapterCode openrtb_ext.BidderName
}
2 changes: 1 addition & 1 deletion exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ func (e *exchange) makeBid(bids []*entities.PbsOrtbBid, auc *auction, returnCrea
}
}

if bidExtJSON, err := makeBidExtJSON(bid.Bid.Ext, bidExtPrebid, impExtInfoMap, bid.Bid.ImpID, bid.OriginalBidCPM, bid.OriginalBidCur, adapter); err != nil {
if bidExtJSON, err := makeBidExtJSON(bid.Bid.Ext, bidExtPrebid, impExtInfoMap, bid.Bid.ImpID, bid.OriginalBidCPM, bid.OriginalBidCur, bid.AdapterCode); err != nil {
errs = append(errs, err)
} else {
result = append(result, *bid.Bid)
Expand Down

0 comments on commit 2c39db7

Please sign in to comment.