-
Notifications
You must be signed in to change notification settings - Fork 832
New Adapter: MadSense #4169
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: MadSense #4169
Conversation
Code coverage summaryNote:
madsenseRefer here for heat map coverage report
|
@pm-jaydeep-mohite can you please review? |
@@ -0,0 +1,12 @@ | |||
endpoint: "https://ads.madsense.io/pbs" |
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.
Endpoint is reachable
curl -i --location --request POST https://ads.madsense.io/pbs
HTTP/2 200
content-length: 0
return openrtb_ext.BidTypeBanner, nil | ||
case openrtb2.MarkupVideo: | ||
return openrtb_ext.BidTypeVideo, nil | ||
default: |
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.
UT can be added to cover default case
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.
added UT for default case
adapters/madsense/madsense.go
Outdated
bidErrors = append(bidErrors, err) | ||
continue | ||
} | ||
|
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: Remove blank line
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.
removed
adapters/madsense/utils.go
Outdated
"fmt" | ||
"github.com/prebid/openrtb/v20/openrtb2" | ||
"github.com/prebid/prebid-server/v3/adapters" | ||
"github.com/prebid/prebid-server/v3/errortypes" | ||
"github.com/prebid/prebid-server/v3/openrtb_ext" | ||
"github.com/prebid/prebid-server/v3/util/jsonutil" | ||
"net/http" |
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 be re-ordered as
`
"fmt"
"net/http"
"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v3/adapters"
"github.com/prebid/prebid-server/v3/errortypes"
"github.com/prebid/prebid-server/v3/openrtb_ext"
"github.com/prebid/prebid-server/v3/util/jsonutil"
`
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.
re-ordered
Code coverage summaryNote:
madsenseRefer here for heat map coverage report
|
@pm-jaydeep-mohite I addressed all comments, could you please review again? |
adapters/madsense/madsensetest/supplemental/bad-request-example.json
Outdated
Show resolved
Hide resolved
Code coverage summaryNote:
madsenseRefer here for heat map coverage report
|
adapters/madsense/madsense.go
Outdated
} | ||
|
||
request.Imp = imps | ||
body, err := json.Marshal(request) |
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 use jsonutil for marshaling
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.
Done!
Code coverage summaryNote:
madsenseRefer here for heat map coverage report
|
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.
@madsenseops this is close. Please see my three earlier comments that are still unresolved.
adapters/madsense/madsense.go
Outdated
if request.Test == 1 { | ||
ext.CompanyId = "test" | ||
} |
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 see my earlier comment.
adapters/madsense/utils.go
Outdated
return nil, &errortypes.BadInput{ | ||
Message: fmt.Sprintf("Error while decoding extImpBidder, err: %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.
Please add a supplemental test to cover this case.
adapters/madsense/utils.go
Outdated
return nil, &errortypes.BadInput{ | ||
Message: fmt.Sprintf("Error while decoding impExt, err: %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.
Please add a supplemental test to cover this case.
Code coverage summaryNote:
madsenseRefer here for heat map coverage report
|
adapters/madsense/madsense.go
Outdated
for _, bannerImp := range bannerImps { | ||
appendReq([]openrtb2.Imp{bannerImp}) | ||
} |
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: if merely appending, perhaps you wanted to just take sub-slice?
for _, bannerImp := range bannerImps { | |
appendReq([]openrtb2.Imp{bannerImp}) | |
} | |
for i := range bannerImps { | |
appendReq(bannerImps[i : i+1]) | |
} |
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.
done, moved to the loop before
adapters/madsense/madsense.go
Outdated
} | ||
|
||
var videoImps, bannerImps []openrtb2.Imp | ||
for _, imp := range request.Imp { |
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.
Here as well, you appear to make a copy of the slice, perhaps you can use a reference to avoid the copy?
for _, imp := range request.Imp { | |
for i := range request.Imp { | |
imp := &request.Imp[i] |
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.
done
adapters/madsense/madsense.go
Outdated
for _, seatBid := range resp.SeatBid { | ||
for i := range seatBid.Bid { | ||
bid := &seatBid.Bid[i] |
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: Avoid copy of the seatbid as well
for _, seatBid := range resp.SeatBid { | |
for i := range seatBid.Bid { | |
bid := &seatBid.Bid[i] | |
for i := range resp.SeatBid { | |
seatBid := &resp.SeatBid[i] | |
for j := range seatBid.Bid { | |
bid := &seatBid.Bid[j] |
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.
done
adapters/madsense/utils.go
Outdated
headers.Add("Content-Type", "application/json;charset=utf-8") | ||
headers.Add("Accept", "application/json") | ||
headers.Add("X-Openrtb-Version", "2.6") |
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: Was "Add" intentional? Isn't Set
the right method to use?
headers.Add("Content-Type", "application/json;charset=utf-8") | |
headers.Add("Accept", "application/json") | |
headers.Add("X-Openrtb-Version", "2.6") | |
headers.Set("Content-Type", "application/json;charset=utf-8") | |
headers.Set("Accept", "application/json") | |
headers.Set("X-Openrtb-Version", "2.6") |
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 Set
adapters/madsense/utils.go
Outdated
|
||
if request.Device != nil { | ||
if len(request.Device.UA) > 0 { | ||
headers.Add("User-Agent", request.Device.UA) |
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.
headers.Add("User-Agent", request.Device.UA) | |
headers.Set("User-Agent", request.Device.UA) |
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
adapters/madsense/utils.go
Outdated
} | ||
|
||
if len(request.Device.IP) > 0 { | ||
headers.Add("X-Forwarded-For", request.Device.IP) |
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.
headers.Add("X-Forwarded-For", request.Device.IP) | |
headers.Set("X-Forwarded-For", request.Device.IP) |
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
adapters/madsense/utils.go
Outdated
} | ||
|
||
if len(request.Device.IPv6) > 0 { | ||
headers.Add("X-Forwarded-For", request.Device.IPv6) |
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.
headers.Add("X-Forwarded-For", request.Device.IPv6) | |
headers.Set("X-Forwarded-For", request.Device.IPv6) |
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
adapters/madsense/utils.go
Outdated
} | ||
|
||
if len(request.Device.IPv6) > 0 { | ||
headers.Add("X-Forwarded-For", request.Device.IPv6) |
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: do we need to preserve existing values of X-Forwarded-For? It's usually a CSV list of ip-addresses seen - this behavior puts the last hop only and wouldn't actually be correct, if behind edge servers or the like which add a terminating hop
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
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 access the existing values? If so, how?
adapters/madsense/utils.go
Outdated
|
||
if request.Site != nil { | ||
if request.Site.Domain != "" { | ||
headers.Add("Origin", request.Site.Domain) |
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.
headers.Add("Origin", request.Site.Domain) | |
headers.Set("Origin", request.Site.Domain) |
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
Code coverage summaryNote:
madsenseRefer here for heat map coverage report
|
adapters/madsense/utils.go
Outdated
|
||
if err := jsonutil.Unmarshal(imp.Ext, &bidderExt); err != nil { | ||
return nil, &errortypes.BadInput{ | ||
Message: fmt.Sprintf("Error while decoding extImpBidder, err: %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.
I think your error messages are backwards. This one should read "Error while decoding extImp, err: %v"
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.
Thank you, changed
adapters/madsense/utils.go
Outdated
err := jsonutil.Unmarshal(bidderExt.Bidder, &ext) | ||
if err != nil { | ||
return nil, &errortypes.BadInput{ | ||
Message: fmt.Sprintf("Error while decoding impExt, err: %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.
I think your error messages are backwards. This one should read "Error while decoding extImpBidder, err: %v"
.
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.
Thank you, changed
Code coverage summaryNote:
madsenseRefer here for heat map coverage report
|
Code coverage summaryNote:
madsenseRefer here for heat map coverage report
|
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 - just one nitpick on the test to use testify assertions/requirements; I'll approve the next one 😉
adapters/madsense/madsense_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.
suggestion: Prefer the testify assertions/requirements
if buildErr != nil { | |
t.Fatalf("Builder returned unexpected error %v", buildErr) | |
} | |
require.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.
Thank you, changed in this and params test
Code coverage summaryNote:
madsenseRefer here for heat map coverage report
|
doc - prebid/prebid.github.io#5824