Skip to content

Commit

Permalink
record PBS-auction-response preparation time (prebid#2841)
Browse files Browse the repository at this point in the history
co-authored by @onkarvhanumante
  • Loading branch information
onkarvhanumante authored Jul 21, 2023
1 parent b0a9b2f commit 9973c15
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
5 changes: 5 additions & 0 deletions endpoints/openrtb2/amp_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ func (deps *endpointDeps) AmpAuction(w http.ResponseWriter, r *http.Request, _ h
}

auctionResponse, err := deps.ex.HoldAuction(ctx, auctionRequest, nil)
defer func() {
if !auctionRequest.BidderResponseStartTime.IsZero() {
deps.metricsEngine.RecordOverheadTime(metrics.MakeAuctionResponse, time.Since(auctionRequest.BidderResponseStartTime))
}
}()
var response *openrtb2.BidResponse
if auctionResponse != nil {
response = auctionResponse.BidResponse
Expand Down
5 changes: 5 additions & 0 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ http
Activities: activities,
}
auctionResponse, err := deps.ex.HoldAuction(ctx, auctionRequest, nil)
defer func() {
if !auctionRequest.BidderResponseStartTime.IsZero() {
deps.metricsEngine.RecordOverheadTime(metrics.MakeAuctionResponse, time.Since(auctionRequest.BidderResponseStartTime))
}
}()
ao.RequestWrapper = req
ao.Account = account
var response *openrtb2.BidResponse
Expand Down
5 changes: 5 additions & 0 deletions endpoints/openrtb2/video_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ func (deps *endpointDeps) VideoAuctionEndpoint(w http.ResponseWriter, r *http.Re
}

auctionResponse, err := deps.ex.HoldAuction(ctx, auctionRequest, &debugLog)
defer func() {
if !auctionRequest.BidderResponseStartTime.IsZero() {
deps.metricsEngine.RecordOverheadTime(metrics.MakeAuctionResponse, time.Since(auctionRequest.BidderResponseStartTime))
}
}()
vo.RequestWrapper = bidReqWrapper
var response *openrtb2.BidResponse
if auctionResponse != nil {
Expand Down
12 changes: 7 additions & 5 deletions exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,12 @@ type AuctionRequest struct {
// map of imp id to stored response
StoredAuctionResponses stored_responses.ImpsWithBidResponses
// map of imp id to bidder to stored response
StoredBidResponses stored_responses.ImpBidderStoredResp
BidderImpReplaceImpID stored_responses.BidderImpReplaceImpID
PubID string
HookExecutor hookexecution.StageExecutor
QueryParams url.Values
StoredBidResponses stored_responses.ImpBidderStoredResp
BidderImpReplaceImpID stored_responses.BidderImpReplaceImpID
PubID string
HookExecutor hookexecution.StageExecutor
QueryParams url.Values
BidderResponseStartTime time.Time
}

// BidderRequest holds the bidder specific request and all other
Expand Down Expand Up @@ -370,6 +371,7 @@ func (e *exchange) HoldAuction(ctx context.Context, r *AuctionRequest, debugLog
adapterBids, adapterExtra, extraRespInfo = e.getAllBids(auctionCtx, bidderRequests, bidAdjustmentFactors, conversions, accountDebugAllow, r.GlobalPrivacyControlHeader, debugLog.DebugOverride, alternateBidderCodes, requestExtLegacy.Prebid.Experiment, r.HookExecutor, r.StartTime, bidAdjustmentRules)
fledge = extraRespInfo.fledge
anyBidsReturned = extraRespInfo.bidsFound
r.BidderResponseStartTime = extraRespInfo.bidderResponseStartTime
}

var (
Expand Down
7 changes: 6 additions & 1 deletion exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func TestDebugBehaviour(t *testing.T) {
// Assert no HoldAuction error
assert.NoErrorf(t, err, "%s. ex.HoldAuction returned an error: %v \n", test.desc, err)
assert.NotNilf(t, outBidResponse.Ext, "%s. outBidResponse.Ext should not be nil \n", test.desc)

assert.False(t, auctionRequest.BidderResponseStartTime.IsZero())
actualExt := &openrtb_ext.ExtBidResponse{}
err = json.Unmarshal(outBidResponse.Ext, actualExt)
assert.NoErrorf(t, err, "%s. \"ext\" JSON field could not be unmarshaled. err: \"%v\" \n outBidResponse.Ext: \"%s\" \n", test.desc, err, outBidResponse.Ext)
Expand Down Expand Up @@ -540,6 +540,7 @@ func TestTwoBiddersDebugDisabledAndEnabled(t *testing.T) {
// Assert no HoldAuction err
assert.NoErrorf(t, err, "ex.HoldAuction returned an err")
assert.NotNilf(t, outBidResponse.Ext, "outBidResponse.Ext should not be nil")
assert.False(t, auctionRequest.BidderResponseStartTime.IsZero())

actualExt := &openrtb_ext.ExtBidResponse{}
err = json.Unmarshal(outBidResponse.Ext, actualExt)
Expand Down Expand Up @@ -715,6 +716,7 @@ func TestOverrideWithCustomCurrency(t *testing.T) {

// Assertions
assert.NoErrorf(t, err, "%s. HoldAuction error: %v \n", test.desc, err)
assert.False(t, auctionRequest.BidderResponseStartTime.IsZero())

if test.expected.numBids > 0 {
// Assert out currency
Expand Down Expand Up @@ -1362,6 +1364,7 @@ func TestReturnCreativeEndToEnd(t *testing.T) {
continue
} else {
assert.NoErrorf(t, err, "%s: %s. HoldAuction error: %v \n", testGroup.groupDesc, test.desc, err)
assert.False(t, auctionRequest.BidderResponseStartTime.IsZero())
}

// Assert returned bid
Expand Down Expand Up @@ -5143,6 +5146,7 @@ func TestOverrideConfigAlternateBidderCodesWithRequestValues(t *testing.T) {
// Assertions
assert.NoErrorf(t, err, "%s. HoldAuction error: %v \n", test.desc, err)
assert.NotNil(t, outBidResponse)
assert.False(t, auctionRequest.BidderResponseStartTime.IsZero())

// So 2 seatBids are expected as,
// the default "" and "pubmatic" bids will be in one seat and the extra-bids "groupm"/"appnexus"/"ix" in another seat.
Expand Down Expand Up @@ -5569,6 +5573,7 @@ func TestModulesCanBeExecutedForMultipleBiddersSimultaneously(t *testing.T) {
_, err := e.HoldAuction(context.Background(), auctionRequest, &DebugLog{})
// Assert no HoldAuction err
assert.NoErrorf(t, err, "ex.HoldAuction returned an err")
assert.False(t, auctionRequest.BidderResponseStartTime.IsZero())

// check stage outcomes
assert.Equal(t, len(exec.GetOutcomes()), len(e.adapterMap), "stage outcomes append operation failed")
Expand Down
2 changes: 1 addition & 1 deletion metrics/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func NewMetrics(cfg config.PrometheusMetrics, disabledMetrics config.DisabledMet
cacheWriteTimeBuckets := []float64{0.001, 0.002, 0.005, 0.01, 0.025, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 1}
priceBuckets := []float64{250, 500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000}
queuedRequestTimeBuckets := []float64{0, 1, 5, 30, 60, 120, 180, 240, 300}
overheadTimeBuckets := []float64{0.00005, 0.0001, 0.0005, 0.001, 0.002, 0.005, 0.01, 0.05}
overheadTimeBuckets := []float64{0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1}

metrics := Metrics{}
reg := prometheus.NewRegistry()
Expand Down

0 comments on commit 9973c15

Please sign in to comment.