Skip to content

Commit

Permalink
Modules: Add bidder response to raw bidder response stage payload (pr…
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishshinde-pubm authored Nov 22, 2024
1 parent 95895a1 commit 3f413a0
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 191 deletions.
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

0 comments on commit 3f413a0

Please sign in to comment.