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

Introduce bidderResponse in raw_bidder_response_stage #3882

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hooks/hookexecution/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ func (e *hookExecutor) ExecuteRawBidderResponseStage(response *adapters.BidderRe

stageName := hooks.StageRawBidderResponse.String()
executionCtx := e.newContext(stageName)
payload := hookstage.RawBidderResponsePayload{Bids: response.Bids, Bidder: bidder}
payload := hookstage.RawBidderResponsePayload{BidderResponse: response, Bidder: bidder}

outcome, payload, contexts, reject := executeStage(executionCtx, plan, payload, handler, e.metricEngine)
response.Bids = payload.Bids
response = payload.BidderResponse
outcome.Entity = entity(bidder)
outcome.Stage = stageName

Expand Down
4 changes: 2 additions & 2 deletions hooks/hookexecution/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (e mockTimeoutHook) HandleRawBidderResponseHook(_ context.Context, _ hookst
time.Sleep(20 * time.Millisecond)
c := hookstage.ChangeSet[hookstage.RawBidderResponsePayload]{}
c.AddMutation(func(payload hookstage.RawBidderResponsePayload) (hookstage.RawBidderResponsePayload, error) {
payload.Bids[0].BidMeta = &openrtb_ext.ExtBidPrebidMeta{AdapterCode: "new-code"}
payload.BidderResponse.Bids[0].BidMeta = &openrtb_ext.ExtBidPrebidMeta{AdapterCode: "new-code"}
return payload, nil
}, hookstage.MutationUpdate, "bidderResponse", "bidMeta.AdapterCode")

Expand Down Expand Up @@ -351,7 +351,7 @@ func (e mockUpdateBidderResponseHook) HandleRawBidderResponseHook(_ context.Cont
c := hookstage.ChangeSet[hookstage.RawBidderResponsePayload]{}
c.AddMutation(
func(payload hookstage.RawBidderResponsePayload) (hookstage.RawBidderResponsePayload, error) {
payload.Bids[0].DealPriority = 10
payload.BidderResponse.Bids[0].DealPriority = 10
return payload, nil
}, hookstage.MutationUpdate, "bidderResponse", "bid.deal-priority",
)
Expand Down
9 changes: 4 additions & 5 deletions hooks/hookstage/rawbidderresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ type RawBidderResponse interface {
) (HookResult[RawBidderResponsePayload], error)
}

// RawBidderResponsePayload consists of a list of adapters.TypedBid
// objects representing bids returned by a particular bidder.
// Hooks are allowed to modify bids using mutations.
// RawBidderResponsePayload consists of a bidder response returned by a particular bidder.
// Hooks are allowed to modify bidder response using mutations.
type RawBidderResponsePayload struct {
Bids []*adapters.TypedBid
Bidder string
BidderResponse *adapters.BidderResponse
Bidder string
}
5 changes: 3 additions & 2 deletions hooks/hookstage/rawbidderresponse_mutations.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ type ChangeSetBids[T any] struct {
changeSetRawBidderResponse ChangeSetRawBidderResponse[T]
}

func (c ChangeSetBids[T]) Update(bids []*adapters.TypedBid) {
// UpdateBids updates the list of bids present in bidder-response using mutations.
func (c ChangeSetBids[T]) UpdateBids(bids []*adapters.TypedBid) {
c.changeSetRawBidderResponse.changeSet.AddMutation(func(p T) (T, error) {
bidderPayload, err := c.changeSetRawBidderResponse.castPayload(p)
if err == nil {
bidderPayload.Bids = bids
bidderPayload.BidderResponse.Bids = bids
}
if payload, ok := any(bidderPayload).(T); ok {
return payload, nil
Expand Down
6 changes: 3 additions & 3 deletions modules/prebid/ortb2blocking/hook_raw_bidder_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func handleRawBidderResponseHook(

// allowedBids will store all bids that have passed the attribute check
allowedBids := make([]*adapters.TypedBid, 0)
for _, bid := range payload.Bids {
for _, bid := range payload.BidderResponse.Bids {

failedChecksData := make(map[string]interface{})
bidMediaTypes := mediaTypesFromBid(bid)
Expand Down Expand Up @@ -77,8 +77,8 @@ func handleRawBidderResponseHook(
}

changeSet := hookstage.ChangeSet[hookstage.RawBidderResponsePayload]{}
if len(payload.Bids) != len(allowedBids) {
changeSet.RawBidderResponse().Bids().Update(allowedBids)
if len(payload.BidderResponse.Bids) != len(allowedBids) {
changeSet.RawBidderResponse().Bids().UpdateBids(allowedBids)
result.ChangeSet = changeSet
}

Expand Down
Loading
Loading