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

Concurrent auctions #1593

Merged
merged 64 commits into from
Sep 26, 2017
Merged

Concurrent auctions #1593

merged 64 commits into from
Sep 26, 2017

Conversation

jaiminpanchal27
Copy link
Collaborator

Continuing from here #1421

…auctions

# Conflicts:
#	modules/appnexusAstBidAdapter.js
#	src/targeting.js
…auctions

# Conflicts:
#	modules/appnexusAstBidAdapter.js
…auctions

# Conflicts:
#	modules/rubiconBidAdapter.js
#	src/adaptermanager.js
#	src/bidmanager.js
#	src/prebid.js
Add getBidsRequested function
Added exclude to karma temporarily to support unit tests
…auctions

# Conflicts:
#	modules/appnexusBidAdapter.js
#	src/prebid.js
#	test/spec/unit/pbjs_api_spec.js
@@ -152,16 +150,17 @@ export function newBidder(spec) {
const adUnitCodesHandled = {};
function addBidWithCode(adUnitCode, bid) {
adUnitCodesHandled[adUnitCode] = true;
bidmanager.addBidResponse(adUnitCode, bid);
addBidResponse(adUnitCode, bid);
}
function fillNoBids() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Calls to this function can be replaced by done(). Prebid 0.x used empty bids to "infer" when the bidder was done. In Prebid 1.x it's explicit... so the rest of this logic should be deletable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated code

src/prebid.js Outdated
@@ -272,7 +236,8 @@ $$PREBID_GLOBAL$$.renderAd = function (doc, id) {
if (doc && id) {
try {
// lookup ad by ad Id
const bid = $$PREBID_GLOBAL$$._bidsReceived.find(bid => bid.adId === id);
const bid = auctionManager.findBidByAdId(id);
// const bid = $$PREBID_GLOBAL$$._bidsReceived.find(bid => bid.adId === id);
Copy link
Contributor

Choose a reason for hiding this comment

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

can be deleted

src/targeting.js Outdated
var pbTargetingKeys = [];

targeting.resetPresetTargeting = function(adUnitCode) {
if (isGptPubadsDefined()) {
export function newTargeting(auctionManager) {
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're going to update targeting to use the newTargeting pattern, I would strongly recommend doing it in master.

It looks like your changes here are confined to the implementations of the methods. So if you do it master, then the only merge conflicts will be if someone updates those implementations in master, too. If do it in 1.0 only, then there will also be conflicts whenever someone in master uses these methods.

If these two branches diverge too much, then prebid 1.0 will fall apart... so try to minimize the chances for conflict whenever you can.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. #1606


export function createAuction({adUnits, adUnitCodes}) {
return newAuction({adUnits, adUnitCodes});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just export newAuction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done here #1644

var code = bid.bidderCode;
var bidPriceAdjusted = bid.cpm;
if (code && $$PREBID_GLOBAL$$.bidderSettings && $$PREBID_GLOBAL$$.bidderSettings[code]) {
if (typeof $$PREBID_GLOBAL$$.bidderSettings[code].bidCpmAdjustment === 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these bidderSettings be moved to setConfig?

Not in this PR, of course. Another question for @matthewlane probably.

getBidRequests: () => _bidderRequests,
getBidsReceived: () => _bidsReceived,
startAuctionTimer,
callBids
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little concerned by this API. How would you write code to do something with the bidsReceived once the auction completes?

The best I can come up with is something like this:

auction = newAuction(...);
...
setInterval(function() {
  if (auction.getAuctionStatus === AUCTION_COMPLETED) {
    bids = auction.getBidsReceived();
    // do stuff with bids
  }
}, 50)

...but this would be pretty crappy code. If the auction happened to finish in 201 ms, I'd be wasting 49ms until your code could actually do something with the bids.

Another (smaller) issue is that this API leaves a lot of room for caller errors. Remember one of the defining features of a good API is "makes mistakes impossible." Here's a small list of possible mistakes:

  1. Calling startAuctionTimer significantly later (or earlier) than callBids
  2. Calling startAuctionTimer multiple times
  3. Forgetting to callBids after loading someone's callback into startAuctionTimer

All that in mind... I'd suggest something like the following:

function newAuction({ adUnits, adUnitCodes, done, timeout }

An Auction would start immediately upon construction. It would promise to finish before the timeout, and execute done exactly once, using the bidsReceived (and possibly other data) as an argument as soon as it completes. That way there'd be no dead time (as in the setInterval example), and no chance of misusing the auction timer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

1st part related to bidsReceived discussed offline.
Auction api improvement #1644

src/auction.js Outdated
import { getCacheUrl, store } from './videoCache';
import { Renderer } from 'src/Renderer';
import { config } from 'src/config';
import { userSync } from 'src/userSync.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

should be src/userSync

}

function doCallbacksIfNeeded() {
if (bid.timeToRespond > $$PREBID_GLOBAL$$.cbTimeout + $$PREBID_GLOBAL$$.timeoutBuffer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not specifically for this PR, but... should these be on config @matthewlane?

If they make sense as global configs, then they probably should. If not, then you should accept them as params here. I don't think it makes sense to read from $$PREBID_GLOBAL$$ in either case, though.

If they are moving to config, that change should go in master.

describe('request function', () => {
let xhr;
let requests;
describe('inherited functions', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good test... but it's actually testing the newBidder implementation. It should move to bidderFactory_spec if it exists.

That said... nearly every test in bidderFactory_spec calls callBids... so they'd all fail if it weren't there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it can be added their as well.

In bidderFactory_spec we are using sampleBidder. And here it tests the actual implementation of bidder. So this would test that implementation is correct and it has inherited needed functions

});

it('should attach valid video params to the tag', () => {
bidRequests[0].params.video = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a side-effect. If the test fails, the delete line at the end will never be executed, which causes cascading failures.

You've got to either copy the object before mutating, or move this to a beforeEach and afterEach block. Either one is fine... but for what it's worth, I tend to find the first one easier. JSON.parse(JSON.stringify(obj)) is an inefficient, but concise way to make a deep copy.

The same goes for some of these other tests as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

});

it('handles non-banner media responses', () => {
server.respondWith(JSON.stringify({
// debugger; // eslint-disable-line
Copy link
Contributor

Choose a reason for hiding this comment

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

Stray comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Damn, i tend to forget these debugger's a lot. Removing it.


const ENDPOINT = '//ib.adnxs.com/ut/v3/prebid';

const REQUEST = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also... shouldn't these tests be updated in master? There's nothing 1.0 or concurrent-auctions about them.

Did we give up on making those centralized tests so that adapter-specific ones only need to define JSON files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, tests can be updated for master as well. I will create a PR for that.

Plan for JSON file based tests is still on. I will be adding that pretty soon.

@mkendall07 mkendall07 self-assigned this Sep 25, 2017
@jaiminpanchal27 jaiminpanchal27 merged commit 1bdedd6 into prebid-1.0 Sep 26, 2017
@jaiminpanchal27 jaiminpanchal27 mentioned this pull request Sep 29, 2017
1 task
@matthewlane matthewlane deleted the concurrent-auctions branch October 6, 2017 23:54
matthewlane pushed a commit that referenced this pull request Dec 7, 2017
* Concurrent auctions (#1593)

* Adding timestamp function to utils

* Auction manager (WIP)

* WIP

* Updated targeting with auction instances and added auction status

* Updated appnexus and appnexusAst adapter

* Added done callback

* Removing bidmanager functions

* Removing deprecated public api functions

* remove bidmanager file

* Revert "remove bidmanager file"

This reverts commit 616409e.

* Updated appnexus and rubicon adapters to call done callback after all responses are back

* Added todo

* Fixing circular dependency

* filter s2s requests

* Emit auction end
Add getBidsRequested function

* remove unused stuff from adapters

* cleanup and fixes

* Unit test fixes
Added exclude to karma temporarily to support unit tests

* added setTimeout for each auction instance

* added constants closer to code

* binded auction object inside done method

* Adding auctionmanager_spec tests and fixes

* Remove breakpoint

* Moving auction to separate file and unit tests

* Merged manually

* Merged config api changes

* Passing adunits, adunitscodes via constructor and fixing unit tests

* added ajax with timeout

* convert targeting module to factory pattern

* Auction code refactored and unit tests

* Updated bidderfactory for 1.0 changes and added unit tests

* Renamed placementCode to adUnitCode

* Refactor auction and update unit tests

* JSDoc for auction and auctionManager

* Unit test fixes after rebase

* Manual merge new updates to bidmanager and its spec file into auction

* Update appnexusAst spec file

* Refactor

* Prebid 1.0 does not require no_bid to be added

* removed side effect by cloning objects

* bug fix to set status on already used bid

* Removing all !1.0 complaiant adapters

* Adding aliases to appnexusAst adapter

* Removed bidmanager from currency

* Add ignore-loader to handle .md files (#1646)

* Auction module refactor (#1644)

* Auction moduel refactor

* remove comment and global cbtimeout

* Config api updates (#1633)

* Add timeoutBuffer, s2sconfig, bidderSequence to config

* Removing deprecated function and its unit test

* fixed linting errors

* Adapter/rubicon bid adapter markup (#1674)

* initial take on rubiconBidAdapter markup

* formatting

* formatting, cont.

* formatting, cont.

* Prebid 1.0 Fix issue with video bid validation (#1680)

* Fix issue with video bid validation

* Modified tests to stub `auctionManager.getBidsRequested` instead of `getBidRequest`

* Move stub to beforeEach hook

* Fix lint errors

* Add bidRequests param to bid validation

* Auction module updated to support currency/hook (#1733)

* added hook module to prebid core that allows extension of arbitrary functions

* remove unused dependency tiny-queue

* change PluginFunction to HookedFunction

* more hook documentation fixes

* Auction module updated to support currency/hook

* remove unused dependency tiny-queue

* change PluginFunction to HookedFunction

* more hook documentation fixes

* WIP

* allow context for hooked functions

* added tests for context

* remove withContext, just use bind

* fix in hooks so asyncSeries keeps proper bound context

* Unit test fixes

* Updated bid validation function

* Fixed video unit test

* updated sizeMapping to use sizeConfig and support labels (#1772)

* updated sizeMapping to use sizeConfig and support labels

* added new tests for labels and sizes w/ sizeConfig when making auction

* made some names clearer and added type to labels for sizeMapping

* make error message more descriptive in adaptermanager

* remove extra line in adpatermanager

* update package.json with correct version. (#1813)

* Unit test fixes for IE 10 and other old browsers (#1810)

* Added fix for location.origin

* Fixed test case failing in IE and Safari browsers

* Added utils.getOrigin method

* Updated renderer to use hooks

* Rename appnexusAst adapter to appnexus adapter (#1848)

* Renamed appnexusAst adapter to appnexus

* Updated unit test to use appnexus bidderCode

* Remove completed todo comment

* fixed safeframe for 1.0 (#1834)

* Emit array of objects from BID_TIMEOUT event (#1824)

* Emit array of objects from BID_TIMEOUT event

* requestId is now auctionId

* Use v4 UUID to match previous requestId format

* Move function

* Move public winningBids to auction (#1828)

* Move public winningBids to auction

* removed _winningBids

* removed _winningBids

* bugfix: return only new bids

* Updates for PubWise Prebid 1.0 Support (#1847)

* Updates for Prebid 1.0 Support

* Updates for Bug Fixes and a small refactor

* update JSDoc comment. Remove trailing space (#1872)

tests were failing due to no trailing space eslint rule.

* Prebid 1.0 adxcg analytics adapter fix for bidtimeout event (#1871)

* adxcg analytics adapter for 1.0 bidtimeout event

* update tests for adxcg analytics 1.0

* Prebid 1.0 prebid server (#1846)

* fix adaptermanager s2sTest unit tests

* fix s2s log message

* remove errant comment

* fixed log statement

* removed seemingly unnecessary call to transformHeightWidth(adUnit);

* removed legacy sizeMapping code block

* initial refactor of prebidServerBidAdapter working w/o tests

(cherry picked from commit 2b843d0)

* add transformSizes back for prebidServer adUnits to fix request

* fixed adapterManager_spec tests

* added prebidServerBidAdapter tests for 1.0

* fixed lint errors

* make sure addBidResponse and doneCb are stubbed for s2s calls

* s2s requests now firing BID_REQUESTED event

* fixed commented tests and other minor fixes

* update defaults in prebidServerBidAdapter and fix doBidderSync bug

* add new API for setting defaults in config for modules

* Targeting updates (#1689)

* Cherry pick alias bidder

* Cherry pick alias bidder

* Cherry pick alias bidder

* Updated test case to not import adapter

* targeting updates

* targeting functions refactoring

* Refactored functions

* more refactor of function

* added jsdoc and some more refactor

* check bid expiry and filtering used bids

* make sure we have the right version

* Update version to fix invalid semver

* video bug fix (#1906)

* video bug fix
added required params to prebidServerAdapter

* Emitted auction_end and updated ttl for prebidServer

* fix logging of server adapters

* Manually merge bidManager code to auction module (#1905)

* Unit test fix in IE for adxcgAnalytics Adapter (#1929)

* IE bug fix

* get only unique bidders

* added log message for xhr timeout (#1928)

* remove polyfill.js and remove global polyfills (#1918)

* remove polyfill.js and remove global polyfills

* make sure find, findIndex, and includes use core-js in tests

* switch from virtual function bind core-js to explicit usage.

* remove transform-function-bind babel plugin

* Replace usePrebidCache with cache:url and remove default (#1904)

* replace usePrebidCache with video:cacheUrl and remove default

* remove newConfig in dfpAdServerVideo_spec that isn't doing anything

* change video.cacheUrl to cache.url

* update to cache.url in auction and remove from adapter

* pulsepointLiteBidAdapter renamed to pulsepointBidAdapter (#1931)

* ET-1691: Pulsepoint Analytics adapter for Prebid. (#1)

* ET-1691: Adding pulsepoint analytics and tests for pulsepoint adapter

* ET-1691: Adding pulsepoint analytics and tests for pulsepoint adapter

* ET-1691: cleanup

* ET-1691: minor

* ET-1691: revert package.json change

* Adding bidRequest to bidFactory.createBid method as per #509

* ET-1765: Adding support for additional params in PulsePoint adapter (#2)

* ET-1850: Fixing #866

* Minor fix

* Adding mandatory parameters to Bid

* Pulsepoint adapter changes

* readme updates

* add 'x_source.tid' to rubicon requests (#1933)

* Bring in pre-1.0 native-image asset adapter change (#1934)

* 33Across Adapter: Removed the usage of utils library (#1917)

* Removed the usage of utils library to get bidder requests during userSync since this info will now be passed into the method

* Fixed extra space which cause lint to fail

* Implemented user sync per code review feedback in #1917

* Minor feedback changes

* Re-instated lint check for all files which was accidentally commited after testing

* Prebid 1.0 server cache (#1935)

* add cache stuff to video for prebid server

* add description for cacheMarkup
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.

3 participants