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

Cache validation fix #911

Merged
merged 6 commits into from
Jun 5, 2019
Merged

Conversation

VeronikaSolovei9
Copy link
Contributor

if no bids returned - don't throw cache error, just return empty result

if no bids returned - don't throw cache error, just return empty result
jmaynardxandr
jmaynardxandr previously approved these changes May 21, 2019
@VeronikaSolovei9 VeronikaSolovei9 changed the title Cache validation fix [WIP] Cache validation fix May 21, 2019
- optimization: do not run auction logic if no bids returned
@VeronikaSolovei9 VeronikaSolovei9 changed the title [WIP] Cache validation fix Cache validation fix May 22, 2019
@VeronikaSolovei9
Copy link
Contributor Author

@hhhjort @mansinahar @josephveach @guscarreon Guys, can you please review this PR? Thank you.

hhhjort
hhhjort previously approved these changes May 23, 2019
Copy link
Collaborator

@hhhjort hhhjort left a comment

Choose a reason for hiding this comment

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

LGTM

mansinahar
mansinahar previously approved these changes May 29, 2019
Copy link
Contributor

@mansinahar mansinahar left a comment

Choose a reason for hiding this comment

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

Would be great if we could move that error check I suggested but other than that LGTM! Thanks @Kalypsonika!

if anyBidsReturned {
bidCategory, adapterBids, err := applyCategoryMapping(ctx, requestExt, adapterBids, *categoriesFetcher, targData)
auc := newAuction(adapterBids, len(bidRequest.Imp))
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.

Shouldn't this err be checked before the previous line: auc := newAuction(adapterBids, len(bidRequest.Imp))? I understand that this PR isn't the one introducing this change and it was like that before but this seems like a small change that would be good to have because we're calling newAuction unnecessarily in case of an err from applyCategoryMapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally makes sense. Done.

@mansinahar
Copy link
Contributor

Sorry, I missed this earlier but also, it would be great if we could add/modify some tests to verify this is working as expected.

@VeronikaSolovei9 VeronikaSolovei9 dismissed stale reviews from mansinahar and hhhjort via 043be36 May 29, 2019 23:41
if len(adPods) == 0 {
//check if there are any bids in response.
//if there are no bids - empty response should be returned, no cache errors
if len(adPods) == 0 && anyBidsReturned {
//means there is a global cache error, we need to reject all bids
err := errors.New("caching failed for all bids")
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

@Kalypsonika this is very, very minor but, just for the sake of saving memory in the heap and trying to declare as less local variables as possible, can we get rid of lines 406 and 419 and change the return statement in line 421?

	return &openrtb_ext.BidResponseVideo{AdPods:adPods}, nil

What do you think?

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!

if seatBid != nil && len(seatBid.bids) > 0 {
anyBidsReturned = true
break
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can save a bit of processing time if we remove the for statement in line 143 and make the getAllBids() method to return the anyBidsReturned value. Since the adapterBids map gets already traversed inside getAllBids(), we could save some processing time by not going through the rather large adapterBids map again and make our solution a bit less verbose.
In other words, go from this:

141 adapterBids, adapterExtra := e.getAllBids(auctionCtx, cleanRequests, aliases, bidAdjustmentFactors, blabels, conversions)
142 anyBidsReturned := false
143 for _, seatBid := range adapterBids {
144 	if seatBid != nil && len(seatBid.bids) > 0 {
145 		anyBidsReturned = true
146 		break
147 	}
148 }
149 if anyBidsReturned {

To something like this:

141 adapterBids, adapterExtra, anyBidsReturned := e.getAllBids(auctionCtx, cleanRequests, aliases, bidAdjustmentFactors, blabels, conversions)
142 if anyBidsReturned {

Inside of getAllBids() we can probably populate the boolean value in the last if statement:
Go from:

183 func (e *exchange) getAllBids(ctx context.Context, cleanRequests map[openrtb_ext.BidderName]*openrtb.BidRequest, aliases map[string]string, bidAdjustments map[string]float64, blabels map[openrtb_ext.BidderName]*pbsmetrics.AdapterLabels, conversions currencies.Conversions) (map[openrtb_ext.BidderName]*pbsOrtbSeatBid, map[openrtb_ext.BidderName]*seatResponseExtra) {
184     // Set up pointers to the bid results
185     adapterBids := make(map[openrtb_ext.BidderName]*pbsOrtbSeatBid, len(cleanRequests))
186     adapterExtra := make(map[openrtb_ext.BidderName]*seatResponseExtra, len(cleanRequests))
187     chBids := make(chan *bidResponseWrapper, len(cleanRequests))
188
189     for bidderName, req := range cleanRequests {
190         // Here we actually call the adapters and collect the bids.
191 +-- 45 lines: coreBidder := resolveBidder(string(bidderName), aliases)--------------------------------------------
236     }
237     // Wait for the bidders to do their thing
238     for i := 0; i < len(cleanRequests); i++ {
239         brw := <-chBids
240         adapterBids[brw.bidder] = brw.adapterBids
241         adapterExtra[brw.bidder] = brw.adapterExtra
242     }
243
244     return adapterBids, adapterExtra
245 }

To something like:

176 func (e *exchange) getAllBids(ctx context.Context, cleanRequests map[openrtb_ext.BidderName]*openrtb.BidRequest, aliases map[string]string, bidAdjustments map[string]float64, blabels map[openrtb_ext.BidderName]*pbsmetrics.AdapterLabels, conversions currencies.Conversions) (map[openrtb_ext.BidderName]*pbsOrtbSeatBid, map[openrtb_ext.BidderName]*seatResponseExtra, bool) {
177     // Set up pointers to the bid results
178     adapterBids := make(map[openrtb_ext.BidderName]*pbsOrtbSeatBid, len(cleanRequests))
179     adapterExtra := make(map[openrtb_ext.BidderName]*seatResponseExtra, len(cleanRequests))
180     bidsFound := false  // NEW
181     chBids := make(chan *bidResponseWrapper, len(cleanRequests))
182
183     for bidderName, req := range cleanRequests {
184         // Here we actually call the adapters and collect the bids.
185 +-- 45 lines: coreBidder := resolveBidder(string(bidderName), aliases)---------------------------------
230     }
231     // Wait for the bidders to do their thing
232     for range cleanRequests {
233         //for i := 0; i < len(cleanRequests); i++ {
234         brw := <-chBids
235         adapterBids[brw.bidder] = brw.adapterBids
236         if adapterBids[brw.bidder] != nil && len(adapterBids[brw.bidder].bids) > 0 { // NEW
237             bidsFound = true        // NEW
238         }                           // NEW
239         adapterExtra[brw.bidder] = brw.adapterExtra
240     }
241
242     return adapterBids, adapterExtra, bidsFound
243 }

What do you think? Please let me know if you agree with any of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's a good idea! Refactored.

@VeronikaSolovei9
Copy link
Contributor Author

@mansinahar regarding unit tests. "Exchange" changes don't change a behavior of HoldAuction logic, this is just a minor optimization, and case with no bids returned is already covered by existing unit tests.
For Video endpoint I added simple unit test to check there is no error and empty response returned if there are no bids. All other cases are already covered.
Thank you!

@@ -478,6 +478,16 @@ func TestVideoBuildVideoResponsePodErrors(t *testing.T) {
assert.Equal(t, int64(333), bidRespVideo.AdPods[2].PodId, "AdPods should contain error element at index 2")
}

func TestVideoBuildVideoResponseNoBids(t *testing.T) {
openRtbBidResp := openrtb.BidResponse{}
podErrors := make([]PodError, 0, 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to initialize podErrors with a capacity of 2 here?

Also, a minor suggestion (not a hard request): the next two lines can be potentially combined into: openRtbBidResp.SeatBid = make([]openrtb.SeatBid, 0) since seatBids is not used anywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was copy and paste, sorry. Fixed.

@mansinahar
Copy link
Contributor

@Kalypsonika I see. Makes sense. Thanks!

guscarreon
guscarreon previously approved these changes Jun 3, 2019
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, good job

@hhhjort hhhjort merged commit 58f98fa into prebid:master Jun 5, 2019
mgloystein added a commit to spotx/prebid-server that referenced this pull request Jun 14, 2019
* Use the correct labels for cache performance metric (prebid#904)

* PubMatic Adslot validation (prebid#886)

* testing a few changes to validate adslot, more to follow

* Changed AdSlot to optional parameter, modified validation and test cases for the same

* removed imp id from adslot validation error msgs

* assign banner size

* remove TrimSpace where it is not needed as recommended in the review

* Implementation of Categories Http fetcher (prebid#882)

* Implementation of Categories Http fetcher

-Added code to fetch data using http
-Added previously loaded categories to run http request just at the first time

* Moved common Category struct to stored_request

* Added comments

* Minor refactoring

* Minor refactoring

-Added verification if category exist in map

* Minor refactoring

* Minor refactoring

-strings.Replace changed to strings.TrimSuffix

* Improved error handling on Beachfront adapter (prebid#873)

* Removed a redundant error message that was causing some confusion.

* trying to turn '[]' into null and 200 inti 404

* not a goot path

* looking at the status codes

* I think I have covers all these bases.

* checking for empty array response a failing sanely

* removed an attempt to pointlessly reset the status code.

* corrected and added test cases

* Fix Rubicon bidder for multi-format impression processing (prebid#902)

* Replace Dockerfile Alpine linux with Ubuntu (prebid#885)

* Ubuntu dockerfile works, includes backups and out file

* Ubuntu Dockerfile creates image successfully and prebid-server was tested with a sample request. Seems to work fine

* Ubuntu 18.04 now builds, validates.sh, and curls sample request successfully

* Removed sed command

* [fix] broken Go 1.9 compatibility (prebid#910)

This CL addresses Go 1.9 compatibility issue along with adding back Go
1.9 to travis testing setup to prevent such bugs.

Issue: prebid#895

* Fixed "invalid BidType: " error for lifestreet adapter (prebid#893)

* Fixed "invalid BidType: " error for lifestreet adapter

* After run gofmt

* Used standard bid.ext type to get bid.ext.prebid.type

* [Currency support] Activate multi-currencies support (prebid#894)

This CL is the last piece to activate currency conversion support in
PBS. It activates currency support per default.

Currency rates will be fetched once per hour (PrebidJS file is updated
once a day).

Issue: prebid#280

* ImproveDigital adapter: (prebid#887)

- Add support for video
 - Add support for mobile/app
 - Add support for multibid responses
 - Extend optional parameters

* Add a PI exemption environment variable to PBS (prebid#916)

* Refactored to official name of config item

* Changes suggested by Mansi Nahar

* [Sharethrough] Add new Sharethrough Adapter (prebid#903)

* wip

* wip

* wip

* exploration for sharethrough prebid-server

* WIP: updating sharethrough adapter to latest prebid version

Co-authored-by: Chris Nguyen <cnguyen@sharethrough.com>

* WIP: adding butler params to the request

#164291358

Co-authored-by: Josh Becker <jbecker@sharethrough.com>

* Manage bid sizes

[#164291358]

Co-authored-by: Josh Becker <jbecker@sharethrough.com>

* Manage GDPR

[#164291358]

Co-authored-by: Josh Becker <jbecker@sharethrough.com>

* Populate prebid-server version if provided

[#164291358]

Co-authored-by: Josh Becker <jbecker@sharethrough.com>

* Refactor gdpr data extraction from request

[#164291358]

Co-authored-by: Eddy Pechuzal <epechuzal@sharethrough.com>

* Add instant play capability

[#164291358]

Co-authored-by: Eddy Pechuzal <epechuzal@sharethrough.com>

* Split in multiple files

[#164291358]

Co-authored-by: Eddy Pechuzal <epechuzal@sharethrough.com>

* Add s2s-win beacon
todo? replace server name by server id?

[#164291358]

Co-authored-by: Eddy Pechuzal <epechuzal@sharethrough.com>

* Removing `server` param in s2s-win beacon (will be added in imp req)

[#164291358]

* Clean up code + enable syncer (prebid#4)

[#165257793]

* Proper error handling (prebid#6)

* Proper error handling

[#165745574]

* Address review (baby clean up) + catch error that was missed

[#165745574]

* Implement Unit Tests (prebid#7)

* Proper error handling

[#165745574]

* Address review (baby clean up) + catch error that was missed

[#165745574]

* Implement unit tests for utils

[#165891351]

* Add UT for utils + butler

[#165891351]

Co-authored-by: Michael Duran <mduran@sharethrough.com>

* Attempt for testing Bidder interface function implementations

[#165891351]

Co-authored-by: Michael Duran <mduran@sharethrough.com>

* Finalizing Unit tests

[#165891351]

Co-authored-by: Chris Nguyen <cnguyen@sharethrough.com>
Co-authored-by: Josh Becker <jbecker@sharethrough.com>

* Fixing sharethrough.yaml capabilities

[#165891351]

Co-authored-by: Josh Becker <jbecker@sharethrough.com>

* Send supplyId to imp req instead of hbSource (prebid#5)

[#165477915]

* Finalize PR (prebid#8)

[#164911891]

Co-authored-by: Josh Becker <jbecker@sharethrough.com>

* Remove test setting

* Add Sharethrough in syncer_test

* Update deserializing of third party partners

* Refactor/optimize UserAgent parsing (prebid#9)

following josephveach's review in prebid#903

* Addressing June 3rd review from prebid#903

Optimizations, clean up suggested by @mansinahar

* Addressing June 4th review from prebid#903 (prebid#10)

* Addressing June 4th review from prebid#903

Clean up canAutoPlayVideo + hardcode bhVersion to unknown for now...

* Removing hbVersion butler param since it's not accessible

* Fix adMarkup error handling

* [Mgid] Add new Mgid Adapter (prebid#907)

* new mgid adapter

* increase coverage

* remove extra imports

* Cache validation fix (prebid#911)

* Cache validation fix

if no bids returned - don't throw cache error, just return empty result

* Cache validation fix

- optimization: do not run auction logic if no bids returned

* Cache validation fix: minor refactoring

* Cache validation fix: minor refactoring

* Cache validation fix: added unit test for no bids returned

* Cache validation fix: minor refactoring

* Remove hard coded targeting keys (prebid#923)
katsuo5 pushed a commit to flux-dev-team/prebid-server-1 that referenced this pull request Dec 1, 2020
* Cache validation fix

if no bids returned - don't throw cache error, just return empty result

* Cache validation fix

- optimization: do not run auction logic if no bids returned

* Cache validation fix: minor refactoring

* Cache validation fix: minor refactoring

* Cache validation fix: added unit test for no bids returned

* Cache validation fix: minor refactoring
katsuo5 pushed a commit to flux-dev-team/prebid-server-1 that referenced this pull request Dec 2, 2020
* Cache validation fix

if no bids returned - don't throw cache error, just return empty result

* Cache validation fix

- optimization: do not run auction logic if no bids returned

* Cache validation fix: minor refactoring

* Cache validation fix: minor refactoring

* Cache validation fix: added unit test for no bids returned

* Cache validation fix: minor refactoring
katsuo5 pushed a commit to flux-dev-team/prebid-server-1 that referenced this pull request Dec 4, 2020
* Cache validation fix

if no bids returned - don't throw cache error, just return empty result

* Cache validation fix

- optimization: do not run auction logic if no bids returned

* Cache validation fix: minor refactoring

* Cache validation fix: minor refactoring

* Cache validation fix: added unit test for no bids returned

* Cache validation fix: minor refactoring
@VeronikaSolovei9 VeronikaSolovei9 deleted the cache_validation_fix branch March 22, 2021 05:46
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.

5 participants