Skip to content

Commit

Permalink
Set updated tmax value to bidder's MakeRequest implementation (#2930)
Browse files Browse the repository at this point in the history
co-authored by: @onkarvhanumante
  • Loading branch information
onkarvhanumante authored Jul 25, 2023
1 parent 61a9fcb commit 35db00f
Show file tree
Hide file tree
Showing 14 changed files with 352 additions and 19 deletions.
9 changes: 8 additions & 1 deletion endpoints/openrtb2/amp_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func NewAmpEndpoint(
bidderMap map[string]openrtb_ext.BidderName,
storedRespFetcher stored_requests.Fetcher,
hookExecutionPlanBuilder hooks.ExecutionPlanBuilder,
tmaxAdjustments *exchange.TmaxAdjustmentsPreprocessed,
) (httprouter.Handle, error) {

if ex == nil || validator == nil || requestsById == nil || accounts == nil || cfg == nil || metricsEngine == nil {
Expand Down Expand Up @@ -100,7 +101,9 @@ func NewAmpEndpoint(
nil,
ipValidator,
storedRespFetcher,
hookExecutionPlanBuilder}).AmpAuction), nil
hookExecutionPlanBuilder,
tmaxAdjustments,
}).AmpAuction), nil

}

Expand Down Expand Up @@ -251,6 +254,7 @@ func (deps *endpointDeps) AmpAuction(w http.ResponseWriter, r *http.Request, _ h
QueryParams: r.URL.Query(),
TCF2Config: tcf2Config,
Activities: activities,
TmaxAdjustments: deps.tmaxAdjustments,
}

auctionResponse, err := deps.ex.HoldAuction(ctx, auctionRequest, nil)
Expand Down Expand Up @@ -292,6 +296,9 @@ func (deps *endpointDeps) AmpAuction(w http.ResponseWriter, r *http.Request, _ h
}

labels, ao = sendAmpResponse(w, hookExecutor, auctionResponse, reqWrapper, account, labels, ao, errL)
if len(ao.Errors) == 0 && !auctionRequest.BidderResponseStartTime.IsZero() {
deps.metricsEngine.RecordOverheadTime(metrics.MakeAuctionResponse, time.Since(auctionRequest.BidderResponseStartTime))
}
}

func rejectAmpRequest(
Expand Down
13 changes: 13 additions & 0 deletions endpoints/openrtb2/amp_auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func TestAMPPageInfo(t *testing.T) {
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)
request := httptest.NewRequest("GET", fmt.Sprintf("/openrtb2/auction/amp?tag_id=1&curl=%s", url.QueryEscape(page)), nil)
recorder := httptest.NewRecorder()
Expand Down Expand Up @@ -319,6 +320,7 @@ func TestGDPRConsent(t *testing.T) {
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)

// Invoke Endpoint
Expand Down Expand Up @@ -742,6 +744,7 @@ func TestCCPAConsent(t *testing.T) {
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)

// Invoke Endpoint
Expand Down Expand Up @@ -855,6 +858,7 @@ func TestConsentWarnings(t *testing.T) {
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)

// Invoke Endpoint
Expand Down Expand Up @@ -953,6 +957,7 @@ func TestNewAndLegacyConsentBothProvided(t *testing.T) {
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)

// Invoke Endpoint
Expand Down Expand Up @@ -1007,6 +1012,7 @@ func TestAMPSiteExt(t *testing.T) {
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)
request, err := http.NewRequest("GET", "/openrtb2/auction/amp?tag_id=1", nil)
if !assert.NoError(t, err) {
Expand Down Expand Up @@ -1049,6 +1055,7 @@ func TestAmpBadRequests(t *testing.T) {
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)
for requestID := range badRequests {
request := httptest.NewRequest("GET", fmt.Sprintf("/openrtb2/auction/amp?tag_id=%s", requestID), nil)
Expand Down Expand Up @@ -1082,6 +1089,7 @@ func TestAmpDebug(t *testing.T) {
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)

for requestID := range requests {
Expand Down Expand Up @@ -1217,6 +1225,7 @@ func TestQueryParamOverrides(t *testing.T) {
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)

requestID := "1"
Expand Down Expand Up @@ -1374,6 +1383,7 @@ func (s formatOverrideSpec) execute(t *testing.T) {
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)

url := fmt.Sprintf("/openrtb2/auction/amp?tag_id=1&debug=1&w=%d&h=%d&ow=%d&oh=%d&ms=%s&account=%s", s.width, s.height, s.overrideWidth, s.overrideHeight, s.multisize, s.account)
Expand Down Expand Up @@ -1914,6 +1924,7 @@ func ampObjectTestSetup(t *testing.T, inTagId string, inStoredRequest json.RawMe
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)
return &actualAmpObject, endpoint
}
Expand Down Expand Up @@ -1966,6 +1977,7 @@ func TestAmpAuctionResponseHeaders(t *testing.T) {
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)

for _, test := range testCases {
Expand Down Expand Up @@ -2001,6 +2013,7 @@ func TestRequestWithTargeting(t *testing.T) {
openrtb_ext.BuildBidderMap(),
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)
url, err := url.Parse("/openrtb2/auction/amp")
assert.NoError(t, err, "unexpected error received while parsing url")
Expand Down
9 changes: 8 additions & 1 deletion endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func NewEndpoint(
bidderMap map[string]openrtb_ext.BidderName,
storedRespFetcher stored_requests.Fetcher,
hookExecutionPlanBuilder hooks.ExecutionPlanBuilder,
tmaxAdjustments *exchange.TmaxAdjustmentsPreprocessed,
) (httprouter.Handle, error) {
if ex == nil || validator == nil || requestsById == nil || accounts == nil || cfg == nil || metricsEngine == nil {
return nil, errors.New("NewEndpoint requires non-nil arguments.")
Expand Down Expand Up @@ -122,7 +123,8 @@ func NewEndpoint(
nil,
ipValidator,
storedRespFetcher,
hookExecutionPlanBuilder}).Auction), nil
hookExecutionPlanBuilder,
tmaxAdjustments}).Auction), nil
}

type endpointDeps struct {
Expand All @@ -144,6 +146,7 @@ type endpointDeps struct {
privateNetworkIPValidator iputil.IPValidator
storedRespFetcher stored_requests.Fetcher
hookExecutionPlanBuilder hooks.ExecutionPlanBuilder
tmaxAdjustments *exchange.TmaxAdjustmentsPreprocessed
}

func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
Expand Down Expand Up @@ -250,6 +253,7 @@ func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ http
HookExecutor: hookExecutor,
TCF2Config: tcf2Config,
Activities: activities,
TmaxAdjustments: deps.tmaxAdjustments,
}
auctionResponse, err := deps.ex.HoldAuction(ctx, auctionRequest, nil)
defer func() {
Expand Down Expand Up @@ -288,6 +292,9 @@ func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ http
glog.Errorf("Error setting seat non-bid: %v", err)
}
labels, ao = sendAuctionResponse(w, hookExecutor, response, req.BidRequest, account, labels, ao)
if len(ao.Errors) == 0 && !auctionRequest.BidderResponseStartTime.IsZero() {
deps.metricsEngine.RecordOverheadTime(metrics.MakeAuctionResponse, time.Since(auctionRequest.BidderResponseStartTime))
}
}

// setSeatNonBidRaw is transitional function for setting SeatNonBid inside bidResponse.Ext
Expand Down
1 change: 1 addition & 0 deletions endpoints/openrtb2/auction_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func BenchmarkOpenrtbEndpoint(b *testing.B) {
nil,
empty_fetcher.EmptyFetcher{},
hooks.EmptyPlanBuilder{},
nil,
)

b.ResetTimer()
Expand Down
Loading

0 comments on commit 35db00f

Please sign in to comment.