-
Notifications
You must be signed in to change notification settings - Fork 758
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
New Adapter: AdUp Tech #4076
base: master
Are you sure you want to change the base?
New Adapter: AdUp Tech #4076
Conversation
} | ||
|
||
func getBidType(markupType openrtb2.MarkupType) (openrtb_ext.BidType, error) { | ||
switch markupType { |
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.
Consider this as a suggestion. The current implementation follows an anti-pattern, assumes that if there is a multi-format request, the media type defaults to openrtb_ext.BidTypeBanner. Prebid server expects the media type to be explicitly set in the adapter response. Therefore, we strongly recommend implementing a pattern where the adapter server sets the MType field in the response to accurately determine the media type for the impression.
} | ||
|
||
func getBidType(markupType openrtb2.MarkupType) (openrtb_ext.BidType, error) { | ||
switch markupType { |
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.
Consider this as a suggestion. The current implementation follows an anti-pattern, assumes that if there is a multi-format request, the media type defaults to openrtb_ext.BidTypeNative. Prebid server expects the media type to be explicitly set in the adapter response. Therefore, we strongly recommend implementing a pattern where the adapter server sets the MType field in the response to accurately determine the media type for the impression.
Code coverage summaryNote:
aduptechRefer here for heat map coverage report
|
74112fe
to
8e94b4b
Compare
} | ||
|
||
func getBidType(markupType openrtb2.MarkupType) (openrtb_ext.BidType, error) { | ||
switch markupType { |
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.
Consider this as a suggestion. The current implementation follows an anti-pattern, assumes that if there is a multi-format request, the media type defaults to openrtb_ext.BidTypeBanner. Prebid server expects the media type to be explicitly set in the adapter response. Therefore, we strongly recommend implementing a pattern where the adapter server sets the MType field in the response to accurately determine the media type for the impression.
} | ||
|
||
func getBidType(markupType openrtb2.MarkupType) (openrtb_ext.BidType, error) { | ||
switch markupType { |
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.
Consider this as a suggestion. The current implementation follows an anti-pattern, assumes that if there is a multi-format request, the media type defaults to openrtb_ext.BidTypeNative. Prebid server expects the media type to be explicitly set in the adapter response. Therefore, we strongly recommend implementing a pattern where the adapter server sets the MType field in the response to accurately determine the media type for the impression.
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 should be changed here? I assume this check is wrong, because we do exactly what the comment suggests.
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 suggestion (x3?) is not very helpful
Code coverage summaryNote:
aduptechRefer here for heat map coverage report
|
@scr-oath can you please review? |
@pm-isha-bharti can you please review? |
adapters/aduptech/aduptech.go
Outdated
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) { | ||
bidder := &adapter{ | ||
endpoint: config.Endpoint, | ||
target_currency: "EUR", |
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.
question: Can this go into ExtraAdapterInfo
(either directly or as json that's parsed or inspected maybe with gjson.Get
) rather than being hard coded?
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.
Changed to use ExtraAdapterInfo.
adapters/aduptech/aduptech.go
Outdated
|
||
convertedValue, err := a.convertCurrency(imp.BidFloor, imp.BidFloorCur, reqInfo) | ||
if err != nil { | ||
return nil, err |
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.
suggestion: This return doesn't seem right - as it should be []error - perhaps, if convertCurrency returns a []error, it should be named errs
rather than err
which suggests a single error
as the type.
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.
convertCurrency
doesn't have to return []error. Refactored to just return a single error.
adapters/aduptech/aduptech.go
Outdated
} | ||
|
||
requestData := &adapters.RequestData{ | ||
Method: "POST", |
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.
Method: "POST", | |
Method: http.MethodPost, |
|
||
// try again by first converting to USD | ||
// then convert to target_currency | ||
convertedValue, err = reqInfo.ConvertCurrency(value, cur, "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.
observation we should have constants or an enum of valid currencies… you can ignore for this PR but just making the note; filed #4134
adapters/aduptech/aduptech.go
Outdated
if responseData.StatusCode == http.StatusNoContent { | ||
return nil, nil | ||
} | ||
|
||
if responseData.StatusCode == http.StatusBadRequest { | ||
err := &errortypes.BadInput{ | ||
Message: "Unexpected status code: 400. Run with request.debug = 1 for more info.", | ||
} | ||
return nil, []error{err} | ||
} | ||
|
||
if responseData.StatusCode != http.StatusOK { | ||
err := &errortypes.BadServerResponse{ | ||
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info.", responseData.StatusCode), | ||
} | ||
return nil, []error{err} | ||
} |
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.
question: would a switch on the statusCode (with empty for ok and default clause for this everything-else case) be more readable?
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.
Refactored into a switch
adapters/aduptech/aduptech.go
Outdated
for _, seatBid := range response.SeatBid { | ||
for i, bid := range seatBid.Bid { | ||
bidType, err := getBidType(bid.MType) | ||
if err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
|
||
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ | ||
Bid: &seatBid.Bid[i], | ||
BidType: bidType, | ||
}) | ||
} | ||
} |
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.
suggestion: I don't like making copies of the seatbid and bid in a loop
for _, seatBid := range response.SeatBid { | |
for i, bid := range seatBid.Bid { | |
bidType, err := getBidType(bid.MType) | |
if err != nil { | |
errs = append(errs, err) | |
continue | |
} | |
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ | |
Bid: &seatBid.Bid[i], | |
BidType: bidType, | |
}) | |
} | |
} | |
for i := range response.SeatBid { | |
seatBid = &response.SeatBid[i] | |
for j := range seatBid.Bid { | |
bid := &seatBid.Bid[j] | |
bidType, err := getBidType(bid.MType) | |
if err != nil { | |
errs = append(errs, err) | |
continue | |
} | |
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ | |
Bid: bid, | |
BidType: bidType, | |
}) | |
} | |
} |
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.
Used your suggestion
} | ||
|
||
func getBidType(markupType openrtb2.MarkupType) (openrtb_ext.BidType, error) { | ||
switch markupType { |
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 suggestion (x3?) is not very helpful
adapters/aduptech/aduptech_test.go
Outdated
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} |
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 buildErr != nil { | |
t.Fatalf("Builder returned unexpected error %v", buildErr) | |
} | |
if buildErr != nil { | |
assert.NoError(t, buildErr, "Builder returned unexpected error") | |
} |
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.
Ah, good to know. This is our first time working in Go.
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.
suggestion: Change assert to require
For what it's worth, I realize you were calling fatal before so I realize you need the require.NoError - assertions from the assert module continue but the test fails whereas those from require halt immediately. This is kind of like google's gtest with its two variants for each assertion so when you can continue you report more/all things that fail but when you can't, you don't.
adapters/aduptech/params_test.go
Outdated
if err := validator.Validate(openrtb_ext.BidderAdUpTech, json.RawMessage(invalidParam)); err == nil { | ||
t.Errorf("Schema allowed unexpected params: %s", invalidParam) | ||
} |
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 err := validator.Validate(openrtb_ext.BidderAdUpTech, json.RawMessage(invalidParam)); err == nil { | |
t.Errorf("Schema allowed unexpected params: %s", invalidParam) | |
} | |
assert.NoErrorf(t, validator.Validate(openrtb_ext.BidderAdUpTech, json.RawMessage(invalidParam)), "Schema allowed unexpected params: %s", invalidParam) |
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.
using assert.Errorf
here, but otherwise used the suggestion.
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 didn't mean to approve before… I thought I had ticked request changes…
8e94b4b
to
2ad858d
Compare
} | ||
|
||
func getBidType(markupType openrtb2.MarkupType) (openrtb_ext.BidType, error) { | ||
switch markupType { |
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.
Consider this as a suggestion. The current implementation follows an anti-pattern, assumes that if there is a multi-format request, the media type defaults to openrtb_ext.BidTypeBanner. Prebid server expects the media type to be explicitly set in the adapter response. Therefore, we strongly recommend implementing a pattern where the adapter server sets the MType field in the response to accurately determine the media type for the impression.
} | ||
|
||
func getBidType(markupType openrtb2.MarkupType) (openrtb_ext.BidType, error) { | ||
switch markupType { |
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.
Consider this as a suggestion. The current implementation follows an anti-pattern, assumes that if there is a multi-format request, the media type defaults to openrtb_ext.BidTypeNative. Prebid server expects the media type to be explicitly set in the adapter response. Therefore, we strongly recommend implementing a pattern where the adapter server sets the MType field in the response to accurately determine the media type for the impression.
Code coverage summaryNote:
aduptechRefer here for heat map coverage report
|
- banner | ||
- native | ||
userSync: | ||
redirect: |
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.
@danygielow The usersync URL returned by the /cookie_sync
for aduptech
is currently throwing 404. Can you please check if the URLs added for userSync are correct?
func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
switch responseData.StatusCode { | ||
case http.StatusNoContent: | ||
return nil, nil |
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.
Please add a supplemental JSON test where your mock response returns a 204 status code.
|
||
var response openrtb2.BidResponse | ||
if err := jsonutil.Unmarshal(responseData.Body, &response); err != nil { | ||
return nil, []error{err} |
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.
Please add a supplemental JSON test where your mock response returns a bid response that fails to unmarshal successfully. This can be achieved by setting one of the fields to an incorrect data type.
switch responseData.StatusCode { | ||
case http.StatusNoContent: | ||
return nil, nil | ||
case http.StatusBadRequest: |
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.
Please add a supplemental JSON test where your mock response returns a 400 status code.
func (a *adapter) convertCurrency(value float64, cur string, reqInfo *adapters.ExtraRequestInfo) (float64, error) { | ||
convertedValue, err := reqInfo.ConvertCurrency(value, cur, a.extraInfo.TargetCurrency) | ||
|
||
if err != nil { |
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.
Please add supplemental JSONs for currency conversion failures
bidder, buildErr := Builder(openrtb_ext.BidderAdUpTech, config.Adapter{ | ||
Endpoint: "https://example.com/rtb/bid", ExtraAdapterInfo: "{\"target_currency\": \"EUR\"}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) | ||
|
||
assert.NoError(t, buildErr, "Builder returned unexpected error") |
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.
assert.NoError(t, buildErr, "Builder returned unexpected error") | |
require.NoError(t, buildErr, "Builder returned unexpected error") |
package aduptech | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" |
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.
"github.com/stretchr/testify/assert" | |
"github.com/stretchr/testify/assert" | |
"github.com/stretchr/testify/require" |
} | ||
|
||
for _, validParam := range validParams { | ||
assert.NoErrorf(t, validator.Validate(openrtb_ext.BidderAdUpTech, json.RawMessage(validParam)), "Schema rejected Aduptech params: %s", validParam) |
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.
FWIW, assert seems correct here as you want all failing assertions reported
Hi @danygielow, @derfryday, now that the review process has begun, can you please push new commits when making changes instead of rebasing and force pushing? It will save reviewers a lot of time when performing delta reviews. All of the commits will be squashed when we merge. Thanks! |
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) { | ||
var extraInfo ExtraInfo | ||
if err := jsonutil.Unmarshal([]byte(config.ExtraAdapterInfo), &extraInfo); err != nil { | ||
return nil, fmt.Errorf("invalid extra info: %v", err) |
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.
suggestion: Use %w
instead - see https://pkg.go.dev/fmt#Errorf
return nil, fmt.Errorf("invalid extra info: %v", err) | |
return nil, fmt.Errorf("invalid extra info: %w", err) |
return nil, []error{err} | ||
} | ||
|
||
imp.BidFloorCur = a.extraInfo.TargetCurrency |
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.
bug?: There seems like a bug in here somewhere… the convertCurrency has a path that can handle errors and, instead, convert to "USD" - how is that choice made here if you always set the BidFloorCur to a.extraInfo.TargetCurrency - should you pass in a pointer to the extraInfo and set the chosen currency in the convertCurrency
method maybe? or return the choice back and set to that? Style is your choice, but I think that's an unhandled case and might deserve some unit tests to prove it works as intended.
|
||
if err != nil { | ||
var convErr currency.ConversionNotFoundError | ||
if errors.As(err, &convErr) { |
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.
nitpick/suggestion: In go, there's a pattern that you try to take the "terminal" case first - return/break/panic/exit so that you don't need an else clause - it saves "cognitive overload" because you can just reason that everything after is the "happy path" (not having your brain full with remembering what the condition was when you get to the else way down the screen or having to scroll back up to understand it) - and also saves precious indentation 😄
(so make this !errors.As and pull the else clause into the block and remove the curly braces {}
(keeping and unindenting this code))
Publisher string `json:"publisher"` | ||
Placement string `json:"placement"` | ||
Query string `json:"query"` | ||
AdTest string `json:"adtest"` |
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.
Can we use bidrequest.test
instead of introducing a separate parameter, considering it is a standard ORTB field already used by Prebid?
Hello,
We as AdUp Technology want to add our own Prebid Server Adapter.
We already have a PrebidJS Adapter.
Docs: prebid/prebid.github.io#5728