-
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
Conversation
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.
LGTM
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 comment
The 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".
hooks/hookstage/bidderrequest.go
Outdated
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed. Also renamed RequestWrapper
to BidRequest
in ProcessedAuctionRequestPayload
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
It's harder than it seems. Is "empty input provided" ok?
if err == nil { | ||
bidRequest.BAdv = badv | ||
bidRequestWrapper.BAdv = badv |
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.
I imagine it is guaranteed that if we got this far bidRequestWrapper.BidRequest
is not nil, in which case this assignment to BAdv
will never fail, is that correct? I'm bringing this up because previously we were checking if the ortb2.BidRequest
was nil in the call to castPayload
but now that function just checks if the wrapper is nil, not if the wrapper's ortb2.BidRequest
is nil.
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.
Technically auction and mutation functions should be never executed with nil bid request. parseRequest
function sets this explicitly:
req = &openrtb_ext.RequestWrapper{}
req.BidRequest = &openrtb2.BidRequest{}
I added extra nil check in castPayload
just to be safe:
if payload.BidRequest == nil || payload.BidRequest.BidRequest == nil {...}
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the return value from castPayload
should still be referred to as bidRequest
as @SyntaxNode mentioned earlier.
if payload.BidRequest == nil { | ||
return result, hookexecution.NewFailure("empty BidRequest provided") | ||
if payload.BidRequest == nil || payload.BidRequest.BidRequest == nil { | ||
return result, hookexecution.NewFailure("empty input provided") |
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.
How about we use the same error message we now use in the mutation code: "payload contains a nil bid request
"?
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.
LGTM
@@ -26,5 +26,5 @@ type ProcessedAuctionRequest interface { | |||
// ProcessedAuctionRequestPayload consists of the openrtb_ext.RequestWrapper object. | |||
// Hooks are allowed to modify openrtb_ext.RequestWrapper using mutations. | |||
type ProcessedAuctionRequestPayload struct { | |||
RequestWrapper *openrtb_ext.RequestWrapper | |||
BidRequest *openrtb_ext.RequestWrapper |
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.
I think naming BidRequest
to request wrapper
object will be misleading as openrtb_ext.RequestWrapper
also have bidRequest object embedded
What are your thoughts?
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.
The Request Wrapper is an internal concept for optimization. I don't find the Bid Request misleading, since the RequestWrapper embeds the BidRequest it acts as a drop-in replacement with enhanced functionality.
Would it be better to name this simply Request instead of BidRequest?
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.
I think I prefer it being named RequestWrapper
since when we actually go ahead and access the BidRequest within the wrapper, right now it looks like payload.BidRequest.BidRequest
, and I think it's clearer for me to read something like payload.RequestWrapper.BidRequest
. I'm also fine with it being payload.Request.BidRequest
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.
Yep Request
will be fine
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.
Done
exchange/bidder.go
Outdated
@@ -130,7 +130,8 @@ 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) { | |||
reject := hookExecutor.ExecuteBidderRequestStage(bidderRequest.BidRequest, string(bidderRequest.BidderName)) | |||
brw := openrtb_ext.RequestWrapper{BidRequest: bidderRequest.BidRequest} |
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 like reqWrapper
for clarity, but if you prefer brw
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
@@ -26,5 +26,5 @@ type ProcessedAuctionRequest interface { | |||
// ProcessedAuctionRequestPayload consists of the openrtb_ext.RequestWrapper object. | |||
// Hooks are allowed to modify openrtb_ext.RequestWrapper using mutations. | |||
type ProcessedAuctionRequestPayload struct { | |||
RequestWrapper *openrtb_ext.RequestWrapper | |||
BidRequest *openrtb_ext.RequestWrapper |
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.
I think I prefer it being named RequestWrapper
since when we actually go ahead and access the BidRequest within the wrapper, right now it looks like payload.BidRequest.BidRequest
, and I think it's clearer for me to read something like payload.RequestWrapper.BidRequest
. I'm also fine with it being payload.Request.BidRequest
Prebid Server 2.0 has been released and Go Module name has changed from Please merge the |
Replaced BidRequest to RequestWrapper in BidderRequestPayload