-
Notifications
You must be signed in to change notification settings - Fork 761
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
[synacormedia] Add synacormedia adapter #1029
Conversation
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
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.
Appart from the comments made for adapters/synacormedia/synacormedia.go
, can we increase code coverage to 95% or so?
╰─➤ go test -coverprofile=c.out
PASS
coverage: 87.8% of statements
ok github.com/prebid/prebid-server/adapters/synacormedia 0.023s
╭─gcarreongutierrez@Guss-MacBook-Pro.local ~/go/src/github.com/prebid/prebid-server/adapters/synacormedia ‹PR1029*›
╰─➤ go tool cover -func=c.out
github.com/prebid/prebid-server/adapters/synacormedia/synacormedia.go:29: NewSynacorMediaBidder 50.0%
github.com/prebid/prebid-server/adapters/synacormedia/synacormedia.go:39: MakeRequests 100.0%
github.com/prebid/prebid-server/adapters/synacormedia/synacormedia.go:52: makeRequest 87.5%
github.com/prebid/prebid-server/adapters/synacormedia/synacormedia.go:116: buildEndpointURL 100.0%
github.com/prebid/prebid-server/adapters/synacormedia/synacormedia.go:120: getExtImpObj 85.7%
github.com/prebid/prebid-server/adapters/synacormedia/synacormedia.go:139: MakeBids 100.0%
github.com/prebid/prebid-server/adapters/synacormedia/synacormedia.go:173: getMediaTypeForImp 85.7%
github.com/prebid/prebid-server/adapters/synacormedia/usersync.go:10: NewSynacorMediaSyncer 100.0%
total: (statements) 87.8%
} | ||
} | ||
return mediaType | ||
} |
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.
Function getMediaTypeForImp(impId string, imps []openrtb.Imp)
might return openrtb_ext.BidTypeBanner
even if imp.Banner == nil
and imp.Video == nil
. Other adapters overcome this issue by filtering out non-Banner and non-Video types somewhere inside MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo)
. I believe either filtering out non-Banner and non-Video imps, or modifying this function to return an error or something so we don't append this bid to the bidResponse
array in MakeBids
may solve this issue.
173 func getMediaTypeForImp(impId string, imps []openrtb.Imp) openrtb_ext.BidType {
174 mediaType := openrtb_ext.BidTypeBanner
175 for _, imp := range imps {
176 if imp.ID == impId {
177 if imp.Banner == nil && imp.Video != nil {
178 mediaType = openrtb_ext.BidTypeVideo
179 }
180 return mediaType //<- may return openrtb_ext.BidTypeBanner on an imp with imp.Banner==nil && imp.Video==nil element
181 }
182 }
183 return mediaType //<- may return openrtb_ext.BidTypeBanner even if imp wasn't found in the imp list
184 }
synacormedia.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.
Added filter.
// filter out non banner and non video imps
var validRequestImps []openrtb.Imp
for _, imp := range internalRequest.Imp {
if imp.Banner != nil || imp.Video != nil {
validRequestImps = append(validRequestImps, 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.
I don't think this for loop is exactly filtering out non banner and non video imps because if getMediaTypeForImp(sb.Bid[i].ImpID, validRequestImps)
doesn't find a match in validRequestImps
it will still assign the value openrtb_ext.BidTypeBanner
to something that probably isn't. Do you think a better approach is this?
138 func (a *SynacorMediaAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
139 const errorMessage string = "Unexpected status code: %d. Run with request.debug = 1 for more info"
140 switch {
141 case response.StatusCode == http.StatusNoContent:
142 return nil, nil
143 case response.StatusCode == http.StatusBadRequest:
144 return nil, []error{&errortypes.BadInput{
145 Message: fmt.Sprintf(errorMessage, response.StatusCode),
146 }}
147 case response.StatusCode != http.StatusOK:
148 return nil, []error{&errortypes.BadServerResponse{
149 Message: fmt.Sprintf(errorMessage, response.StatusCode),
150 }}
151 }
152
153 var bidResp openrtb.BidResponse
154
155 if err := json.Unmarshal(response.Body, &bidResp); err != nil {
156 return nil, []error{err}
157 }
158
159 bidResponse := adapters.NewBidderResponseWithBidsCapacity(1)
160
161 - // filter out non banner and non video imps
162 - var validRequestImps []openrtb.Imp
163 - for _, imp := range internalRequest.Imp {
164 - if imp.Banner != nil || imp.Video != nil {
165 - validRequestImps = append(validRequestImps, imp)
166 - }
167 - }
168 -
169 for _, sb := range bidResp.SeatBid {
170 for i := range sb.Bid {
+ mediaType = getMediaTypeForImp(sb.Bid[i].ImpID, validRequestImps)
+ if mediaType != openrtb_ext.BidTypeBanner && mediaType != openrtb_ext.BidTypeVideo {
+ continue
+ }
171 bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
172 Bid: &sb.Bid[i],
173 - BidType: getMediaTypeForImp(sb.Bid[i].ImpID, validRequestImps),
173 BidType: mediaType,
174 })
175 }
176 }
177 return bidResponse, nil
178 }
179
180 func getMediaTypeForImp(impId string, imps []openrtb.Imp) openrtb_ext.BidType {
181 mediaType := openrtb_ext.BidTypeBanner
182 for _, imp := range imps {
183 if imp.ID == impId {
184 - if imp.Banner == nil && imp.Video != nil {
185 - mediaType = openrtb_ext.BidTypeVideo
+ if imp.Banner != nil {
+ break
+ }
+ if imp.Video != nil {
+ mediaType = openrtb_ext.BidTypeVideo
+ break
+ }
+ if imp.Native != nil {
+ mediaType = openrtb_ext.BidTypeNative
+ break
+ }
+ if imp.Audio != nil {
+ mediaType = openrtb_ext.BidTypeAudio
+ break
186 }
187 - return mediaType
188 }
189 }
190 return mediaType
191 }
adapters/synacormedia/synacormedia.go
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
please don't close, currently in progress |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
still not stale |
…ormedia-updates * commit '36bd18f75c15a1c3d13315ec9c6f083e13792e57': CAP-1467 - updates for github comments
|
||
for _, imp := range request.Imp { | ||
_, err := getExtImpObj(&imp) | ||
validImp, err := getExtImpObj(&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.
Why does getExtImp(&imp)
get executed twice in a row?
} | ||
} | ||
return mediaType | ||
} |
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 don't think this for loop is exactly filtering out non banner and non video imps because if getMediaTypeForImp(sb.Bid[i].ImpID, validRequestImps)
doesn't find a match in validRequestImps
it will still assign the value openrtb_ext.BidTypeBanner
to something that probably isn't. Do you think a better approach is this?
138 func (a *SynacorMediaAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
139 const errorMessage string = "Unexpected status code: %d. Run with request.debug = 1 for more info"
140 switch {
141 case response.StatusCode == http.StatusNoContent:
142 return nil, nil
143 case response.StatusCode == http.StatusBadRequest:
144 return nil, []error{&errortypes.BadInput{
145 Message: fmt.Sprintf(errorMessage, response.StatusCode),
146 }}
147 case response.StatusCode != http.StatusOK:
148 return nil, []error{&errortypes.BadServerResponse{
149 Message: fmt.Sprintf(errorMessage, response.StatusCode),
150 }}
151 }
152
153 var bidResp openrtb.BidResponse
154
155 if err := json.Unmarshal(response.Body, &bidResp); err != nil {
156 return nil, []error{err}
157 }
158
159 bidResponse := adapters.NewBidderResponseWithBidsCapacity(1)
160
161 - // filter out non banner and non video imps
162 - var validRequestImps []openrtb.Imp
163 - for _, imp := range internalRequest.Imp {
164 - if imp.Banner != nil || imp.Video != nil {
165 - validRequestImps = append(validRequestImps, imp)
166 - }
167 - }
168 -
169 for _, sb := range bidResp.SeatBid {
170 for i := range sb.Bid {
+ mediaType = getMediaTypeForImp(sb.Bid[i].ImpID, validRequestImps)
+ if mediaType != openrtb_ext.BidTypeBanner && mediaType != openrtb_ext.BidTypeVideo {
+ continue
+ }
171 bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
172 Bid: &sb.Bid[i],
173 - BidType: getMediaTypeForImp(sb.Bid[i].ImpID, validRequestImps),
173 BidType: mediaType,
174 })
175 }
176 }
177 return bidResponse, nil
178 }
179
180 func getMediaTypeForImp(impId string, imps []openrtb.Imp) openrtb_ext.BidType {
181 mediaType := openrtb_ext.BidTypeBanner
182 for _, imp := range imps {
183 if imp.ID == impId {
184 - if imp.Banner == nil && imp.Video != nil {
185 - mediaType = openrtb_ext.BidTypeVideo
+ if imp.Banner != nil {
+ break
+ }
+ if imp.Video != nil {
+ mediaType = openrtb_ext.BidTypeVideo
+ break
+ }
+ if imp.Native != nil {
+ mediaType = openrtb_ext.BidTypeNative
+ break
+ }
+ if imp.Audio != nil {
+ mediaType = openrtb_ext.BidTypeAudio
+ break
186 }
187 - return mediaType
188 }
189 }
190 return mediaType
191 }
adapters/synacormedia/synacormedia.go
… synacormedia-updates * commit 'b26ddff10d5a9808cb0af47f5bc486de3bf86ca6': CAP-1467 - additional updates for github review
…prebid-server into synacormedia-updates
// filter out non banner and non video imps | ||
var validRequestImps []openrtb.Imp | ||
for _, imp := range internalRequest.Imp { | ||
if imp.Banner != nil || imp.Video != nil { | ||
validRequestImps = append(validRequestImps, 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.
Lines 160 to 166 are no longer needed with the additions made to the for loop that follows. Lines 170 to 173 are already filtering out non banner
and non video
bids.
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
@@ -648,6 +649,7 @@ func SetupViper(v *viper.Viper, filename string) { | |||
v.SetDefault("adapters.rtbhouse.endpoint", "http://prebidserver-s2s-ams.creativecdn.com/bidder/prebidserver/bids") | |||
v.SetDefault("adapters.somoaudience.endpoint", "http://publisher-east.mobileadtrading.com/rtb/bid") | |||
v.SetDefault("adapters.sovrn.endpoint", "http://ap.lijit.com/rtb/bid?src=prebid_server") | |||
v.SetDefault("adapters.synacormedia.endpoint", "http://{{.Host}}.technoratimedia.com/openrtb/bids/{{.Host}}") |
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.
Do we expect .technoratimedia.com
after the host value parses? Or did we mean http://{{.Host}}/openrtb/bids/{{.Host}}
?
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 .technoratimedia.com is correct
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.
ok
Can we add a couple of test cases to get to 93~95% coverage?
|
… synacormedia-updates * commit 'ceffd229b57c69a03b6cc13917ece7db08ccebd1': CAP-1467 - additional github comments
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. Thank you for your patience
* CAP-1394 - move synacormedia adapter to correct repo * CAP-1467 - updates for github comments * CAP-1467 - additional updates for github review * CAP-1467 - additional github comments
* CAP-1394 - move synacormedia adapter to correct repo * CAP-1467 - updates for github comments * CAP-1467 - additional updates for github review * CAP-1467 - additional github comments
* CAP-1394 - move synacormedia adapter to correct repo * CAP-1467 - updates for github comments * CAP-1467 - additional updates for github review * CAP-1467 - additional github comments
* CAP-1394 - move synacormedia adapter to correct repo * CAP-1467 - updates for github comments * CAP-1467 - additional updates for github review * CAP-1467 - additional github comments
No description provided.