-
Notifications
You must be signed in to change notification settings - Fork 693
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
Beachfront - Currency conversion #2078
Conversation
…it, etc. Gets the structure of that process ready to plug in currency conversion.
…turns are being tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code updates and the test coverage from these updates looks good! I'm going to wait for the review of @guscarreon to see if I missed anything.
adapters/beachfront/beachfront.go
Outdated
@@ -88,8 +88,8 @@ type beachfrontSlot struct { | |||
} | |||
|
|||
type beachfrontSize struct { | |||
W uint64 `json:"w"` | |||
H uint64 `json:"h"` | |||
W int `json:"w"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about why this was updated from uint64 to int?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was getting a weird error from the test. It was somehow getting converted to hex. Very weird. When I changed it to int the error went away. I'm sure it was not the actual problem, but just got around it somehow, but it appears to be something that got actually fixed along the way. I can not reproduce the error. Thanks for pointing it out. I just changed it back, as it should be unsigned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it thanks for updating! I'll look over this again today.
…le while messing with pbs.yaml, so deleted that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me @muncha. Just one more ask: Now that pull request #2071 has been merged, JSON tests with currency conversion are now supported. Can you convert TestRequestWithDifferentBidFloorAttributes
to JSON tests?
Currency conversion rates get read from the request.ext.prebid.currency.rates
field as shown below:
"mockBidRequest": {
"id": "test-request-id",
.
.
"imp": [
.
.
],
"ext": {
"prebid": {
"currency": {
"rates": {
"MXN": {
"USD": 0.05,
"EUR": 0.03
}
"EUR": {
"USD": 1.12
}
.
.
},
"usepbsrates": false
}
}
}
}
@guscarreon FYI - I'm working on switching it to JSON, I'm hitting a panic on the currency conversion and trying to get to the bottom of that. |
Thank's @muncha. Currency tests will panic if the recent currency conversion test functionality recently merged into master is not in place. Maybe updating your local branch will latest master could probably solve it. |
That was the problem. I thought I had that already merged to beachfront's master. I had not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, just have a couple of questions:
var err error | ||
|
||
if imp.BidFloorCur != "" && strings.ToUpper(imp.BidFloorCur) != "USD" { | ||
imp.BidFloor, err = reqInfo.ConvertCurrency(imp.BidFloor, imp.BidFloorCur, "USD") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if imp.BidFloor = 0
and imp.BidFloorCur == "foreignCurrency"
? Should we also check that imp.BidFloor != 0
before making the call to localReqInfo.ConvertCurrency(imp.BidFloor, imp.BidFloorCur, "USD")
?
adapters/beachfront/beachfront.go
Outdated
} | ||
} | ||
|
||
if imp.BidFloor > ext.BidFloor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a possibility that both imp.BidFloor
and ext.BidFloor
come in a non-USD currency? If so, imp.BidFloor
has already been converted from a foreign currency at this point, should we convert ext.BidFloor
if needed?
if floor > minBidFloor { | ||
imp.BidFloorCur = "USD" | ||
} else { | ||
imp.BidFloorCur = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we are positive ext.BidFloor
won't ever come in a foreign currency, maybe we could get rid of this if/else
statement entirely if we slightly modify the if/else
on line 599 above:
598
+ imp.BidFloorCur = "USD"
599 if imp.BidFloor > ext.BidFloor {
600 floor = imp.BidFloor
601 } else if ext.BidFloor > 0 {
602 floor = ext.BidFloor
603 } else {
604 floor = 0
+ imp.BidFloorCur = ""
605 }
606
607 - if floor > minBidFloor {
608 - imp.BidFloorCur = "USD"
609 - } else {
610 - imp.BidFloorCur = ""
611 - floor = 0
612 - }
613 -
614 imp.BidFloor = floor
615 return false, nil
616 }
adapters/beachfront/beachfront.go
…rrency conversion, but it is below the minimum
} | ||
} | ||
|
||
if floor <= minBidFloor { | ||
floor = 0 | ||
if imp.BidFloor < ext.BidFloor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When execution gets here, there's a possibility that imp.BidFloor
has already been converted from a foreign currency to "USD". Are we positive that ext.BidFloor
comes in "USD" and not the same foreign currency imp.BidFloor
was?
For instance: say a given request comes with both imp.BidFloor
and ext.BidFloor
set to "EUR". The comparisson here would be misleading because we could be comparing imp.BidFloor
representing a price in US dollars versus ext.BidFloor
representing Euros. Is this a feasible possibility? Can ext.BidFloor
come in a non "USD" currency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guscarreon
ext.bidfloor is always is USD. So in the case where imp.bidfloor has been converted to USD from EUR, the ext.bidfloor is not converted (it is never converted). Note the comparison at 577. This also assumes that ext.bidfloor is USD, as is minBidFloor (which beachfront may one day decide should be more than $0.01)
If imp.bidfloorcur = INR, imp.bidfloor= 375.23, and ext.bidfloor = 310.21 (erroneously assumed to be in INR) , then ext.bidfloor will be used, as the converted value of imp.bidfloor = 5.00 USD is less than ext.bidfloor = 310.21 USD, which was entered in INR due to user error, and someone's not getting any ads. I verified this with beachfront, and I agree, it's a bit counter intuitive, but it is correct.
I need to update the docs as they still say the converter doesn't work, but this bit is in there as of my previous PR. I'll push that in a couple minutes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying @muncha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! Thanks for being so responsive to feedback!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @muncha thanks for clarifying and addressing our feedback
* 'master' of https://github.com/wwwyyy/prebid-server: (23 commits) Add GPID Reserved Bidder Name (prebid#2107) Marsmedia adapter - param zoneId can get string and int (prebid#2105) Algorix: add Server Region Support (prebid#2096) New Adapter: Bizzclick (prebid#2056) Collect Prometheus Go process metrics (prebid#2101) Added channel support (prebid#2037) Rubicon: update fpd fields resolving (prebid#2091) Beachfront - Currency conversion (prebid#2078) New Adapter: Groupm (Alias Of PubMatic) (prebid#2042) Adform adapter lacked gross/net parameter support (prebid#2084) add iframe sync for openx (prebid#2094) changes to the correct user sync url (prebid#2092) Smaato: Add instl to tests (prebid#2089) Correct MakeRequests() output assertion in adapter JSON tests (prebid#2087) Adview: adapter currency fix. (prebid#2060) New Adapter: Coinzilla (prebid#2074) Syncer Level ExternalURL Override (prebid#2072) 33Across: Enable Support for SRA requests (prebid#2079) Currency conversion on adapter JSON tests (prebid#2071) New Adapter: VideoByte (prebid#2058) ...
This handles currency conversion on imp.bidfloor, corrects and expands on the logic of selecting between imp.bidfloor and ext.bidfloor, and when to apply the minimum. Testing is based on the Rubicon TestOpenRTBRequestWithDifferentBidFloorAttributes() method.