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

Modularity: Make request wrapper accessible in bidder request hook #3096

Merged
merged 9 commits into from
Nov 16, 2023

Conversation

VeronikaSolovei9
Copy link
Contributor

Replaced BidRequest to RequestWrapper in BidderRequestPayload

exchange/bidder.go Outdated Show resolved Hide resolved
@hhhjort hhhjort self-assigned this Sep 12, 2023
@SyntaxNode SyntaxNode self-assigned this Sep 12, 2023
hhhjort
hhhjort previously approved these changes Sep 19, 2023
Copy link
Collaborator

@hhhjort hhhjort left a 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")
Copy link
Contributor

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".

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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")
Copy link
Contributor

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.

Copy link
Contributor Author

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?

@bsardo bsardo assigned bsardo and unassigned SyntaxNode Sep 27, 2023
@bsardo bsardo changed the title BidderRequestPayload - RequestWrapper Modularity: Make request wrapper accessible in bidder request hook Sep 28, 2023
if err == nil {
bidRequest.BAdv = badv
bidRequestWrapper.BAdv = badv
Copy link
Collaborator

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.

Copy link
Contributor Author

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)
Copy link
Collaborator

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")
Copy link
Collaborator

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"?

hhhjort
hhhjort previously approved these changes Oct 3, 2023
Copy link
Collaborator

@hhhjort hhhjort left a 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
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@bsardo bsardo assigned AlexBVolcy and unassigned bsardo Oct 4, 2023
@@ -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}
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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

@SyntaxNode
Copy link
Contributor

Prebid Server 2.0 has been released and Go Module name has changed from github.com/prebid/prebid-server to github.com/prebid/prebid-server/v2, per Go versioning conventions.

Please merge the master branch and update all prebid-server import statements to reference the v2 name change. Thank you.

@bsardo bsardo merged commit f9f5546 into master Nov 16, 2023
3 checks passed
@SyntaxNode SyntaxNode deleted the bidderRequestPayload_RequestWrapper branch November 17, 2023 22:13
svamiftah pushed a commit to sovrn/prebid-server that referenced this pull request Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants