-
Notifications
You must be signed in to change notification settings - Fork 749
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
Modularity: Make request wrapper accessible in bidder request hook #3096
Changes from 3 commits
79ac96c
cdc8f22
39f39d4
80daab8
64ca130
358c3b4
d841a8a
37a5e5a
c5a7249
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,7 @@ package hookstage | |
|
||
import ( | ||
"context" | ||
|
||
"github.com/prebid/openrtb/v19/openrtb2" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
// BidderRequest hooks are invoked for each bidder participating in auction. | ||
|
@@ -25,6 +24,6 @@ type BidderRequest interface { | |
// distilled for the particular bidder. | ||
// Hooks are allowed to modify openrtb2.BidRequest using mutations. | ||
type BidderRequestPayload struct { | ||
BidRequest *openrtb2.BidRequest | ||
Bidder string | ||
RequestWrapper *openrtb_ext.RequestWrapper | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO the RequestWrapper is an abstraction on top of the bid request, but it still represents a bid request. I recommend leaving this variable name (and others) as "BidRequest" of type RequestWrapper. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed. Also renamed |
||
Bidder string | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ package hookstage | |
|
||
import ( | ||
"errors" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
|
||
"github.com/prebid/openrtb/v19/adcom1" | ||
"github.com/prebid/openrtb/v19/openrtb2" | ||
) | ||
|
||
func (c *ChangeSet[T]) BidderRequest() ChangeSetBidderRequest[T] { | ||
|
@@ -31,12 +31,12 @@ func (c ChangeSetBidderRequest[T]) BApp() ChangeSetBApp[T] { | |
return ChangeSetBApp[T]{changeSetBidderRequest: c} | ||
} | ||
|
||
func (c ChangeSetBidderRequest[T]) castPayload(p T) (*openrtb2.BidRequest, error) { | ||
func (c ChangeSetBidderRequest[T]) castPayload(p T) (*openrtb_ext.RequestWrapper, error) { | ||
if payload, ok := any(p).(BidderRequestPayload); ok { | ||
if payload.BidRequest == nil { | ||
if payload.RequestWrapper == nil { | ||
return nil, errors.New("empty BidRequest provided") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: We should update the error messages in this method to not refer to the specific argument. Perhaps messages like "payload contains a nil bid request" and "failed to cast payload". |
||
} | ||
return payload.BidRequest, nil | ||
return payload.RequestWrapper, nil | ||
} | ||
return nil, errors.New("failed to cast BidderRequestPayload") | ||
} | ||
|
@@ -47,9 +47,9 @@ type ChangeSetBAdv[T any] struct { | |
|
||
func (c ChangeSetBAdv[T]) Update(badv []string) { | ||
c.changeSetBidderRequest.changeSet.AddMutation(func(p T) (T, error) { | ||
bidRequest, err := c.changeSetBidderRequest.castPayload(p) | ||
bidRequestWrapper, err := c.changeSetBidderRequest.castPayload(p) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the return value from |
||
if err == nil { | ||
bidRequest.BAdv = badv | ||
bidRequestWrapper.BAdv = badv | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I imagine it is guaranteed that if we got this far There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically auction and mutation functions should be never executed with nil bid request. req = &openrtb_ext.RequestWrapper{}
req.BidRequest = &openrtb2.BidRequest{} I added extra nil check in if payload.BidRequest == nil || payload.BidRequest.BidRequest == nil {...} |
||
} | ||
return p, err | ||
}, MutationUpdate, "bidrequest", "badv") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,11 @@ func handleBidderRequestHook( | |
cfg config, | ||
payload hookstage.BidderRequestPayload, | ||
) (result hookstage.HookResult[hookstage.BidderRequestPayload], err error) { | ||
if payload.BidRequest == nil { | ||
if payload.RequestWrapper == nil || payload.RequestWrapper.BidRequest == nil { | ||
return result, hookexecution.NewFailure("empty BidRequest provided") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update the error message to a more generic wording, to no longer reference a specific variable name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's harder than it seems. Is "empty input provided" ok? |
||
} | ||
|
||
mediaTypes := mediaTypesFrom(payload.BidRequest) | ||
mediaTypes := mediaTypesFrom(payload.RequestWrapper.BidRequest) | ||
changeSet := hookstage.ChangeSet[hookstage.BidderRequestPayload]{} | ||
blockingAttributes := blockingAttributes{} | ||
|
||
|
@@ -60,7 +60,7 @@ func updateBAdv( | |
result *hookstage.HookResult[hookstage.BidderRequestPayload], | ||
changeSet *hookstage.ChangeSet[hookstage.BidderRequestPayload], | ||
) (err error) { | ||
if len(payload.BidRequest.BAdv) > 0 { | ||
if len(payload.RequestWrapper.BAdv) > 0 { | ||
return nil | ||
} | ||
|
||
|
@@ -87,7 +87,7 @@ func updateBApp( | |
result *hookstage.HookResult[hookstage.BidderRequestPayload], | ||
changeSet *hookstage.ChangeSet[hookstage.BidderRequestPayload], | ||
) (err error) { | ||
if len(payload.BidRequest.BApp) > 0 { | ||
if len(payload.RequestWrapper.BApp) > 0 { | ||
return nil | ||
} | ||
|
||
|
@@ -114,7 +114,7 @@ func updateBCat( | |
result *hookstage.HookResult[hookstage.BidderRequestPayload], | ||
changeSet *hookstage.ChangeSet[hookstage.BidderRequestPayload], | ||
) (err error) { | ||
if len(payload.BidRequest.BCat) > 0 { | ||
if len(payload.RequestWrapper.BCat) > 0 { | ||
return nil | ||
} | ||
|
||
|
@@ -191,7 +191,7 @@ func updateCatTax( | |
attributes *blockingAttributes, | ||
changeSet *hookstage.ChangeSet[hookstage.BidderRequestPayload], | ||
) { | ||
if payload.BidRequest.CatTax > 0 { | ||
if payload.RequestWrapper.CatTax > 0 { | ||
return | ||
} | ||
|
||
|
@@ -226,7 +226,7 @@ func mutationForImp( | |
impUpdater impUpdateFunc, | ||
) hookstage.MutationFunc[hookstage.BidderRequestPayload] { | ||
return func(payload hookstage.BidderRequestPayload) (hookstage.BidderRequestPayload, error) { | ||
for i, imp := range payload.BidRequest.Imp { | ||
for i, imp := range payload.RequestWrapper.Imp { | ||
if values, ok := valuesByImp[imp.ID]; ok { | ||
if len(values) == 0 { | ||
continue | ||
|
@@ -236,7 +236,7 @@ func mutationForImp( | |
imp.Banner = &openrtb2.Banner{} | ||
} | ||
|
||
payload.BidRequest.Imp[i] = impUpdater(imp, values) | ||
payload.RequestWrapper.Imp[i] = impUpdater(imp, values) | ||
} | ||
} | ||
return payload, nil | ||
|
@@ -310,7 +310,7 @@ func findImpressionOverrides( | |
overrides := map[string][]int{} | ||
messages := []string{} | ||
|
||
for _, imp := range payload.BidRequest.Imp { | ||
for _, imp := range payload.RequestWrapper.Imp { | ||
// do not add override for attribute if it already exists in request | ||
if isAttrPresent(imp) { | ||
continue | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a variable name other than
brw
we could use? I'd prefer something likereqWrapper
for clarity, but if you preferbrw
I'm fine to keep it like this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to
request
, similar to other renames