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

Unruly r1 consolidated adapter #1997

Merged

Conversation

opeledtremor
Copy link
Contributor

This is a consolidated adapter between the Unruly adapter and the RhythmOne Adapter.
Now the unruly adapter use the new endpoint and has the same support as the RhythmOne Adapter with the relevant params.

* remove S2S param
* remove usersync since we do this on our server side now
* change the siteid type to be int instead of string
@guscarreon
Copy link
Contributor

Please resolve merge conflicts on file usersync/usersyncers/syncer.go

# Conflicts:
#	usersync/usersyncers/syncer.go
@opeledtremor
Copy link
Contributor Author

I believe I resolved the conflicts.

Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments below

@@ -1,6 +1,5 @@
package openrtb_ext

type ExtImpUnruly struct {
UUID string `json:"uuid"`
SiteID string `json:"siteid"`
SiteID int `json:"siteid"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is updated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

adapters/unruly/params_test.go Show resolved Hide resolved
@@ -13,136 +13,136 @@ import (
)

type UnrulyAdapter struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please rename to simply adapter? If not, could we avoid capitalization? There's no need to export this particular strucrture.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

for i := 0; i < numRequests; i++ {
imp := req.Imp[i]
var bidderExt adapters.ExtImpBidder
err := json.Unmarshal(imp.Ext, &bidderExt)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we contract the Unmarshal call error checks in lines 59-60 and 68-69?

58      var bidderExt adapters.ExtImpBidder
59 -    err := json.Unmarshal(imp.Ext, &bidderExt)
60 -    if err != nil {
   +    if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
61          err = &errortypes.BadInput{
62              Message: fmt.Sprintf("ext data not provided in imp id=%s. Abort all Request", imp.ID),
63          }
64          errors = append(errors, err)
65          return nil, "", errors
66      }
adapters/unruly/unruly.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

var errs []error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that the errs array doesn't get populated in the rest of the function. Is it still needed? Should we return an empty error array in line 132 instead?

132 -   return bidResponse, errs
    +   return bidResponse, []error{}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed both this to return the errors from the changes from the next comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

mediaType = openrtb_ext.BidTypeBanner
} else if imp.Video != nil {
mediaType = openrtb_ext.BidTypeVideo
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we code a bit more defensively and return an error in case a given impId doesn't match with any of the imp.IDs in the array or if a given imp comes with both a imp.Banner == nil and imp.Video == nil? Maybe the error that getMediaTypeForImp returns could end up in MakeBids' unused errs array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, I hope this is what you meant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did. Thank you

@mansinahar
Copy link
Contributor

@opeledtremor Just a friendly ping about the comments above.

}
var unrulyExt openrtb_ext.ExtImpUnruly
//err = json.Unmarshal(bidderExt.Bidder, &unrulyExt)
//if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these commented lines are a left-over

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

}

var errs []error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks pretty good. I have two last minor nitpicks and after those get resolved, I think I'll be ready to approve.

for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
bidType, err := getMediaTypeForImpWithId(sb.Bid[i].ImpID, internalRequest.Imp)
var bla, err = getMediaTypeForImp(sb.Bid[i].ImpID, internalRequest.Imp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Can we rename bla to bidType or something more descriptive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 76 to 80
unrulyExtCopy, err := json.Marshal(&unrulyExt)
if err != nil {
errors = append(errors, err)
return nil, "", errors
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want a copy of the unrulyExt as JSON, why marshal what was just unmarshaled? At this point, you've verified unrulyExt is valid since it was successfully unmarshaled and it was not mutated so couldn't you just make a copy of bidderExt.Bidder instead and avoid the additional marshal call? Or are you leaning on the marshal call here to remove data other than siteid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we are leaning on the marshal call here to remove data other than siteid

Comment on lines 91 to 93
if uri == "" {
uri = fmt.Sprintf("%s", a.endPoint)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this should be outside of the for loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed since we removed the uri according to the next comment

if err != nil {
return nil, []error{err}
var uri string
request, uri, errs = a.preProcess(request, errs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you could simplify the preProcess method by eliminating the url return value and just looking at a.endpoint here by changing line 38 in this function from to if a.endpoint != "" and then changing line 44 to Uri: a.endpoint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 153 to 154
} else {
errs = append(errs, fmt.Errorf("impId doesn't match with any of the imp.ID"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this else statement could execute multiple times and if imp.ID == impId is never true, the error slice will contain this same error once for every imp in the original request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it to be only 1 error with all the non matching imps

return imp, nil
}
func getMediaTypeForImp(impId string, imps []openrtb2.Imp) (openrtb_ext.BidType, []error) {
var errs []error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function never returns errs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return openrtb_ext.BidTypeVideo, nil
}
func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if response.StatusCode == http.StatusNoContent {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for when the status code is 204.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return "", &errortypes.BadInput{
Message: fmt.Sprintf("Failed to find impression \"%s\" ", impID),

if response.StatusCode == http.StatusBadRequest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for when the status code is 400.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return &errortypes.BadServerResponse{
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info", response.StatusCode),
}
return nil, []error{&errortypes.BadServerResponse{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test with another error code so that the BadServerResponse is returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added another BadServerResponse for the 401 response

Copy link
Contributor

@bsardo bsardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good; I have just a few more comments on getMediaTypeForImp.

} else {
errs = append(errs, fmt.Errorf("bid responses mediaType didn't match supported mediaTypes"))
}
return mediaType, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be return mediaType, errs so the "didn't match supported mediaTypes" error is returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

func (a *UnrulyAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if err := CheckResponse(response); err != nil {
return nil, []error{err}
if len(noMatchingImps) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that you always return if the imp is found, I don't think you need this conditional check as it appears the only way you would reach this part of the function is if the bid response imp ID was not found in the bid request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood you correctly it's done (removed the condition)

if err := CheckResponse(response); err != nil {
return nil, []error{err}
if len(noMatchingImps) > 0 {
errs = append(errs, fmt.Errorf("the following imps id's %v didn't match impId %s", noMatchingImps, impId))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this error should be a little more generic and not include a variable name like impId in it. How about something like: "Bid response imp ID %s not found in bid request containing imps %v\n"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@guscarreon guscarreon merged commit f81b8dd into prebid:master Oct 4, 2021
jizeyopera pushed a commit to operaads/prebid-server that referenced this pull request Oct 13, 2021
jorgeluisrocha pushed a commit to jwplayer/prebid-server that referenced this pull request Sep 28, 2022
shunj-nb pushed a commit to ParticleMedia/prebid-server that referenced this pull request Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants