-
Notifications
You must be signed in to change notification settings - Fork 762
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
Separate "debug" behavior from "billable" behavior #1387
Changes from 3 commits
525f4b7
2a44f47
ea1b013
200abc1
566417e
9515325
30d01d4
47d75d4
cc85f02
abe0bbe
8bd1af4
0be0124
86a2634
ed5044a
210f0a6
a27d8a2
c54ffbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,7 @@ func TestSingleBidder(t *testing.T) { | |
} | ||
bidder := adaptBidder(bidderImpl, server.Client(), &config.Configuration{}, &metricsConfig.DummyMetricsEngine{}) | ||
currencyConverter := currencies.NewRateConverterDefault() | ||
seatBid, errs := bidder.requestBid(context.Background(), &openrtb.BidRequest{}, "test", bidAdjustment, currencyConverter.Rates(), &adapters.ExtraRequestInfo{}) | ||
seatBid, errs := bidder.requestBid(context.Background(), &openrtb.BidRequest{}, "test", bidAdjustment, currencyConverter.Rates(), &adapters.ExtraRequestInfo{}, false) | ||
|
||
// Make sure the goodSingleBidder was called with the expected arguments. | ||
if bidderImpl.httpResponse == nil { | ||
|
@@ -156,7 +156,7 @@ func TestMultiBidder(t *testing.T) { | |
} | ||
bidder := adaptBidder(bidderImpl, server.Client(), &config.Configuration{}, &metricsConfig.DummyMetricsEngine{}) | ||
currencyConverter := currencies.NewRateConverterDefault() | ||
seatBid, errs := bidder.requestBid(context.Background(), &openrtb.BidRequest{}, "test", 1.0, currencyConverter.Rates(), &adapters.ExtraRequestInfo{}) | ||
seatBid, errs := bidder.requestBid(context.Background(), &openrtb.BidRequest{}, "test", 1.0, currencyConverter.Rates(), &adapters.ExtraRequestInfo{}, false) | ||
|
||
if seatBid == nil { | ||
t.Fatalf("SeatBid should exist, because bids exist.") | ||
|
@@ -526,6 +526,7 @@ func TestMultiCurrencies(t *testing.T) { | |
1, | ||
currencyConverter.Rates(), | ||
&adapters.ExtraRequestInfo{}, | ||
false, | ||
) | ||
|
||
// Verify: | ||
|
@@ -670,6 +671,7 @@ func TestMultiCurrencies_RateConverterNotSet(t *testing.T) { | |
1, | ||
currencyConverter.Rates(), | ||
&adapters.ExtraRequestInfo{}, | ||
false, | ||
) | ||
|
||
// Verify: | ||
|
@@ -843,6 +845,7 @@ func TestMultiCurrencies_RequestCurrencyPick(t *testing.T) { | |
1, | ||
currencyConverter.Rates(), | ||
&adapters.ExtraRequestInfo{}, | ||
false, | ||
) | ||
|
||
// Verify: | ||
|
@@ -955,6 +958,7 @@ func TestServerCallDebugging(t *testing.T) { | |
1.0, | ||
currencyConverter.Rates(), | ||
&adapters.ExtraRequestInfo{}, | ||
true, | ||
) | ||
|
||
if len(bids.httpCalls) != 1 { | ||
|
@@ -1065,6 +1069,7 @@ func TestMobileNativeTypes(t *testing.T) { | |
1.0, | ||
currencyConverter.Rates(), | ||
&adapters.ExtraRequestInfo{}, | ||
false, | ||
) | ||
|
||
var actualValue string | ||
|
@@ -1078,7 +1083,7 @@ func TestMobileNativeTypes(t *testing.T) { | |
func TestErrorReporting(t *testing.T) { | ||
bidder := adaptBidder(&bidRejector{}, nil, &config.Configuration{}, &metricsConfig.DummyMetricsEngine{}) | ||
currencyConverter := currencies.NewRateConverterDefault() | ||
bids, errs := bidder.requestBid(context.Background(), &openrtb.BidRequest{}, "test", 1.0, currencyConverter.Rates(), &adapters.ExtraRequestInfo{}) | ||
bids, errs := bidder.requestBid(context.Background(), &openrtb.BidRequest{}, "test", 1.0, currencyConverter.Rates(), &adapters.ExtraRequestInfo{}, false) | ||
if bids != nil { | ||
t.Errorf("There should be no seatbid if no http requests are returned.") | ||
} | ||
|
@@ -1306,6 +1311,30 @@ func (bidder *goodSingleBidder) MakeBids(internalRequest *openrtb.BidRequest, ex | |
return bidder.bidResponse, nil | ||
} | ||
|
||
type requestModifyingBidder struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's difficult for me to understand the behavior of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
bidRequest *openrtb.BidRequest | ||
httpRequest *adapters.RequestData | ||
httpResponse *adapters.ResponseData | ||
bidResponse *adapters.BidderResponse | ||
} | ||
|
||
func (bidder *requestModifyingBidder) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
//This bidder modifies the requests of the request argument which is a shallow copy of the original *openrtb.BidRequest | ||
if request.Test == 1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .. so then this is something like: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was suggesting to add that to the struct, like:
and then here, just do
The reversing of the test flag is confusing to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
request.Test = 0 | ||
} else { | ||
request.Test = 1 | ||
} | ||
|
||
bidder.bidRequest = request | ||
return []*adapters.RequestData{bidder.httpRequest}, nil | ||
} | ||
|
||
func (bidder *requestModifyingBidder) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
bidder.httpResponse = response | ||
return bidder.bidResponse, nil | ||
} | ||
|
||
type goodMultiHTTPCallsBidder struct { | ||
bidRequest *openrtb.BidRequest | ||
httpRequest []*adapters.RequestData | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,7 @@ func (e *exchange) HoldAuction(ctx context.Context, bidRequest *openrtb.BidReque | |
shouldCacheVAST := false | ||
var bidAdjustmentFactors map[string]float64 | ||
var requestExt openrtb_ext.ExtRequest | ||
debugInfo := bidRequest.Test == 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider calling this debugMode to match with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
if len(bidRequest.Ext) > 0 { | ||
err := json.Unmarshal(bidRequest.Ext, &requestExt) | ||
if err != nil { | ||
|
@@ -139,6 +140,8 @@ func (e *exchange) HoldAuction(ctx context.Context, bidRequest *openrtb.BidReque | |
} | ||
targData.cacheHost, targData.cachePath = e.cache.GetExtCacheData() | ||
} | ||
// if true, the bidResponse will be returned with debug information. | ||
debugInfo = debugInfo || requestExt.Prebid.Debug | ||
} | ||
|
||
// If we need to cache bids, then it will take some time to call prebid cache. | ||
|
@@ -149,7 +152,7 @@ func (e *exchange) HoldAuction(ctx context.Context, bidRequest *openrtb.BidReque | |
// Get currency rates conversions for the auction | ||
conversions := e.currencyConverter.Rates() | ||
|
||
adapterBids, adapterExtra, anyBidsReturned := e.getAllBids(auctionCtx, cleanRequests, aliases, bidAdjustmentFactors, blabels, conversions) | ||
adapterBids, adapterExtra, anyBidsReturned := e.getAllBids(auctionCtx, cleanRequests, aliases, bidAdjustmentFactors, blabels, conversions, debugInfo) | ||
|
||
var auc *auction = nil | ||
var bidResponseExt *openrtb_ext.ExtBidResponse = nil | ||
|
@@ -180,7 +183,7 @@ func (e *exchange) HoldAuction(ctx context.Context, bidRequest *openrtb.BidReque | |
} | ||
|
||
if debugLog != nil && debugLog.Enabled { | ||
bidResponseExt = e.makeExtBidResponse(adapterBids, adapterExtra, bidRequest, resolvedRequest, errs) | ||
bidResponseExt = e.makeExtBidResponse(adapterBids, adapterExtra, bidRequest, resolvedRequest, debugInfo, errs) | ||
if bidRespExtBytes, err := json.Marshal(bidResponseExt); err == nil { | ||
debugLog.Data.Response = string(bidRespExtBytes) | ||
} else { | ||
|
@@ -205,7 +208,7 @@ func (e *exchange) HoldAuction(ctx context.Context, bidRequest *openrtb.BidReque | |
} | ||
|
||
// Build the response | ||
return e.buildBidResponse(ctx, liveAdapters, adapterBids, bidRequest, resolvedRequest, adapterExtra, auc, bidResponseExt, errs) | ||
return e.buildBidResponse(ctx, liveAdapters, adapterBids, bidRequest, resolvedRequest, adapterExtra, auc, bidResponseExt, debugInfo, errs) | ||
} | ||
|
||
type DealTierInfo struct { | ||
|
@@ -296,7 +299,7 @@ func (e *exchange) makeAuctionContext(ctx context.Context, needsCache bool) (auc | |
} | ||
|
||
// This piece sends all the requests to the bidder adapters and gathers the results. | ||
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) { | ||
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, debug bool) (map[openrtb_ext.BidderName]*pbsOrtbSeatBid, map[openrtb_ext.BidderName]*seatResponseExtra, bool) { | ||
// Set up pointers to the bid results | ||
adapterBids := make(map[openrtb_ext.BidderName]*pbsOrtbSeatBid, len(cleanRequests)) | ||
adapterExtra := make(map[openrtb_ext.BidderName]*seatResponseExtra, len(cleanRequests)) | ||
|
@@ -326,7 +329,7 @@ func (e *exchange) getAllBids(ctx context.Context, cleanRequests map[openrtb_ext | |
} | ||
var reqInfo adapters.ExtraRequestInfo | ||
reqInfo.PbsEntryPoint = bidlabels.RType | ||
bids, err := e.adapterMap[coreBidder].requestBid(ctx, request, aName, adjustmentFactor, conversions, &reqInfo) | ||
bids, err := e.adapterMap[coreBidder].requestBid(ctx, request, aName, adjustmentFactor, conversions, &reqInfo, debug) | ||
|
||
// Add in time reporting | ||
elapsed := time.Since(start) | ||
|
@@ -445,7 +448,7 @@ func errsToBidderErrors(errs []error) []openrtb_ext.ExtBidderError { | |
} | ||
|
||
// This piece takes all the bids supplied by the adapters and crafts an openRTB response to send back to the requester | ||
func (e *exchange) buildBidResponse(ctx context.Context, liveAdapters []openrtb_ext.BidderName, adapterBids map[openrtb_ext.BidderName]*pbsOrtbSeatBid, bidRequest *openrtb.BidRequest, resolvedRequest json.RawMessage, adapterExtra map[openrtb_ext.BidderName]*seatResponseExtra, auc *auction, bidResponseExt *openrtb_ext.ExtBidResponse, errList []error) (*openrtb.BidResponse, error) { | ||
func (e *exchange) buildBidResponse(ctx context.Context, liveAdapters []openrtb_ext.BidderName, adapterBids map[openrtb_ext.BidderName]*pbsOrtbSeatBid, bidRequest *openrtb.BidRequest, resolvedRequest json.RawMessage, adapterExtra map[openrtb_ext.BidderName]*seatResponseExtra, auc *auction, bidResponseExt *openrtb_ext.ExtBidResponse, includeDebugInfo bool, errList []error) (*openrtb.BidResponse, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please either change the name of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finally went for |
||
bidResponse := new(openrtb.BidResponse) | ||
|
||
bidResponse.ID = bidRequest.ID | ||
|
@@ -469,7 +472,7 @@ func (e *exchange) buildBidResponse(ctx context.Context, liveAdapters []openrtb_ | |
bidResponse.SeatBid = seatBids | ||
|
||
if bidResponseExt == nil { | ||
bidResponseExt = e.makeExtBidResponse(adapterBids, adapterExtra, bidRequest, resolvedRequest, errList) | ||
bidResponseExt = e.makeExtBidResponse(adapterBids, adapterExtra, bidRequest, resolvedRequest, includeDebugInfo, errList) | ||
} | ||
buffer := &bytes.Buffer{} | ||
enc := json.NewEncoder(buffer) | ||
|
@@ -656,13 +659,13 @@ func getPrimaryAdServer(adServerId int) (string, error) { | |
} | ||
|
||
// Extract all the data from the SeatBids and build the ExtBidResponse | ||
func (e *exchange) makeExtBidResponse(adapterBids map[openrtb_ext.BidderName]*pbsOrtbSeatBid, adapterExtra map[openrtb_ext.BidderName]*seatResponseExtra, req *openrtb.BidRequest, resolvedRequest json.RawMessage, errList []error) *openrtb_ext.ExtBidResponse { | ||
func (e *exchange) makeExtBidResponse(adapterBids map[openrtb_ext.BidderName]*pbsOrtbSeatBid, adapterExtra map[openrtb_ext.BidderName]*seatResponseExtra, req *openrtb.BidRequest, resolvedRequest json.RawMessage, includeDebugInfo bool, errList []error) *openrtb_ext.ExtBidResponse { | ||
bidResponseExt := &openrtb_ext.ExtBidResponse{ | ||
Errors: make(map[openrtb_ext.BidderName][]openrtb_ext.ExtBidderError, len(adapterBids)), | ||
ResponseTimeMillis: make(map[openrtb_ext.BidderName]int, len(adapterBids)), | ||
RequestTimeoutMillis: req.TMax, | ||
} | ||
if req.Test == 1 { | ||
if includeDebugInfo { | ||
bidResponseExt.Debug = &openrtb_ext.ExtResponseDebug{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is not a change specific to this PR but I'd suggest we call This should be a simple and quick enough simplification of the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd agree with you if |
||
HttpCalls: make(map[openrtb_ext.BidderName][]*openrtb_ext.ExtHttpCall), | ||
} | ||
|
@@ -673,7 +676,7 @@ func (e *exchange) makeExtBidResponse(adapterBids map[openrtb_ext.BidderName]*pb | |
|
||
for bidderName, responseExtra := range adapterExtra { | ||
|
||
if req.Test == 1 { | ||
if includeDebugInfo { | ||
bidResponseExt.Debug.HttpCalls[bidderName] = responseExtra.HttpCalls | ||
} | ||
// Only make an entry for bidder errors if the bidder reported any. | ||
|
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.
This function signature is becoming bigger and bigger every day lol.
How about utilizing
ctx
to store request level info likedebugMode
? You can then just add this value toctx
in theHoldAuction
function and then can read it out fromctx
in subsequent functions likegetAllBids
,requestBid
, etc without having to pass them around in the function arguments. You can use thecontext.WithValue
function to achieve this.Ref: https://blog.golang.org/context
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. It did simplify the PR Mansi, thanks