Skip to content

Commit

Permalink
pass bidder core name to BidderRequest hook
Browse files Browse the repository at this point in the history
  • Loading branch information
oaleksieiev committed Jan 9, 2024
1 parent a6dea2f commit f4daf86
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion exchange/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type bidderAdapterConfig struct {

func (bidder *bidderAdapter) requestBid(ctx context.Context, bidderRequest BidderRequest, conversions currency.Conversions, reqInfo *adapters.ExtraRequestInfo, adsCertSigner adscert.Signer, bidRequestOptions bidRequestOptions, alternateBidderCodes openrtb_ext.ExtAlternateBidderCodes, hookExecutor hookexecution.StageExecutor, ruleToAdjustments openrtb_ext.AdjustmentsByDealID) ([]*entities.PbsOrtbSeatBid, extraBidderRespInfo, []error) {
request := openrtb_ext.RequestWrapper{BidRequest: bidderRequest.BidRequest}
reject := hookExecutor.ExecuteBidderRequestStage(&request, string(bidderRequest.BidderName))
reject := hookExecutor.ExecuteBidderRequestStage(&request, string(bidderRequest.BidderName), bidderRequest.BidderCoreName)
if reject != nil {
return nil, extraBidderRespInfo{}, []error{reject}
}
Expand Down
8 changes: 4 additions & 4 deletions hooks/hookexecution/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type StageExecutor interface {
ExecuteEntrypointStage(req *http.Request, body []byte) ([]byte, *RejectError)
ExecuteRawAuctionStage(body []byte) ([]byte, *RejectError)
ExecuteProcessedAuctionStage(req *openrtb_ext.RequestWrapper) error
ExecuteBidderRequestStage(req *openrtb_ext.RequestWrapper, bidder string) *RejectError
ExecuteBidderRequestStage(req *openrtb_ext.RequestWrapper, bidder string, bidderCoreName openrtb_ext.BidderName) *RejectError
ExecuteRawBidderResponseStage(response *adapters.BidderResponse, bidder string) *RejectError
ExecuteAllProcessedBidResponsesStage(adapterBids map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid)
ExecuteAuctionResponseStage(response *openrtb2.BidResponse)
Expand Down Expand Up @@ -177,7 +177,7 @@ func (e *hookExecutor) ExecuteProcessedAuctionStage(request *openrtb_ext.Request
return reject
}

func (e *hookExecutor) ExecuteBidderRequestStage(req *openrtb_ext.RequestWrapper, bidder string) *RejectError {
func (e *hookExecutor) ExecuteBidderRequestStage(req *openrtb_ext.RequestWrapper, bidder string, bidderCoreName openrtb_ext.BidderName) *RejectError {
plan := e.planBuilder.PlanForBidderRequestStage(e.endpoint, e.account)
if len(plan) == 0 {
return nil
Expand All @@ -194,7 +194,7 @@ func (e *hookExecutor) ExecuteBidderRequestStage(req *openrtb_ext.RequestWrapper

stageName := hooks.StageBidderRequest.String()
executionCtx := e.newContext(stageName)
payload := hookstage.BidderRequestPayload{Request: req, Bidder: bidder}
payload := hookstage.BidderRequestPayload{Request: req, Bidder: bidder, BidderCoreName: bidderCoreName}
outcome, payload, contexts, reject := executeStage(executionCtx, plan, payload, handler, e.metricEngine)
outcome.Entity = entity(bidder)
outcome.Stage = stageName
Expand Down Expand Up @@ -332,7 +332,7 @@ func (executor EmptyHookExecutor) ExecuteProcessedAuctionStage(_ *openrtb_ext.Re
return nil
}

func (executor EmptyHookExecutor) ExecuteBidderRequestStage(_ *openrtb_ext.RequestWrapper, bidder string) *RejectError {
func (executor EmptyHookExecutor) ExecuteBidderRequestStage(_ *openrtb_ext.RequestWrapper, bidder string, bidderCoreName openrtb_ext.BidderName) *RejectError {
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions hooks/hookexecution/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestEmptyHookExecutor(t *testing.T) {
entrypointBody, entrypointRejectErr := executor.ExecuteEntrypointStage(req, body)
rawAuctionBody, rawAuctionRejectErr := executor.ExecuteRawAuctionStage(body)
processedAuctionRejectErr := executor.ExecuteProcessedAuctionStage(&openrtb_ext.RequestWrapper{BidRequest: &openrtb2.BidRequest{}})
bidderRequestRejectErr := executor.ExecuteBidderRequestStage(&openrtb_ext.RequestWrapper{BidRequest: bidderRequest}, "bidder-name")
bidderRequestRejectErr := executor.ExecuteBidderRequestStage(&openrtb_ext.RequestWrapper{BidRequest: bidderRequest}, "bidder-name", "bidder-core-name")
executor.ExecuteAuctionResponseStage(&openrtb2.BidResponse{})

outcomes := executor.GetOutcomes()
Expand Down Expand Up @@ -916,6 +916,7 @@ func TestExecuteProcessedAuctionStage(t *testing.T) {

func TestExecuteBidderRequestStage(t *testing.T) {
bidderName := "the-bidder"
bidderCoreName := openrtb_ext.BidderName("the-bidder-core-name")
foobarModuleCtx := &moduleContexts{ctxs: map[string]hookstage.ModuleContext{"foobar": nil}}
account := &config.Account{}

Expand Down Expand Up @@ -1171,7 +1172,7 @@ func TestExecuteBidderRequestStage(t *testing.T) {
exec := NewHookExecutor(test.givenPlanBuilder, EndpointAuction, &metricsConfig.NilMetricsEngine{})
exec.SetAccount(test.givenAccount)

reject := exec.ExecuteBidderRequestStage(&openrtb_ext.RequestWrapper{BidRequest: test.givenBidderRequest}, bidderName)
reject := exec.ExecuteBidderRequestStage(&openrtb_ext.RequestWrapper{BidRequest: test.givenBidderRequest}, bidderName, bidderCoreName)

assert.Equal(t, test.expectedReject, reject, "Unexpected stage reject.")
assert.Equal(t, test.expectedBidderRequest, test.givenBidderRequest, "Incorrect bidder request.")
Expand Down
6 changes: 4 additions & 2 deletions hooks/hookstage/bidderrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hookstage

import (
"context"

"github.com/prebid/prebid-server/v2/openrtb_ext"
)

Expand All @@ -24,6 +25,7 @@ type BidderRequest interface {
// distilled for the particular bidder.
// Hooks are allowed to modify openrtb2.BidRequest using mutations.
type BidderRequestPayload struct {
Request *openrtb_ext.RequestWrapper
Bidder string
Request *openrtb_ext.RequestWrapper
Bidder string
BidderCoreName openrtb_ext.BidderName
}

0 comments on commit f4daf86

Please sign in to comment.