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

Pass Host Config Info to Bid Adapters #2370

Merged
merged 20 commits into from
Oct 12, 2022

Conversation

AlexBVolcy
Copy link
Contributor

@AlexBVolcy AlexBVolcy commented Sep 6, 2022

This PR addresses this issue: #1739

The goal of the PR is to pass specific host info to bid adapters in two different ways

This host info data we want passed consists of: externalUrl, gvlID, and datacenter

One way is to pass this info in the auction request itself at the path ext.prebid.server (i.e. ext.prebid.server.datacenter)

The second way is to pass this info as a configuration data structure

When it comes to adding the info to the auction request, all bid adapters get a copy of the request, so as long as I properly update the request to include these new values (and ensure they don't get cleaned), this should suffice in accomplishing the first way of passing the info.

To do this, what I needed was to create a new request object in openrtb_ext/request.go called ExtRequestPrebidServer, which will hold the three host info values we want to support. This object is then added as another parameter of the ExtRequestPrebid object.

To ensure the new host info wouldn't be scrubbed from the request that's sent to bid adapters, I had to update cleanOpenRTBRequests() --> buildRequestExtForBidder() and add the new host info Server object to the ExtRequestPrebid object that's being built there.

When it comes to passing this info as config data structure, I created a new data structure in config.go called Server which holds the three host info values, and that object is added to the Configuration object. And then I updated SetupViper() so that the host could set the values of this object.

In order for this config object to be available to adapters, I had to update the Builder() function that all adapters use to build a new instance of their adapter. Simply, the Builder() function is updated to accept the config Server object (which is taken from the Server object defined by Viper), and that Server object is then added to that particular adapter object.

This change had to be applied to all adapters, and all adapters tests, so that's where the bulk of the files changed comes from.

@AlexBVolcy AlexBVolcy changed the title Pass Host Config to Bid Adapters Pass Host Config Info to Bid Adapters Sep 6, 2022
@@ -15,6 +15,7 @@ import (

type TtxAdapter struct {
endpoint string
Server config.Server
Copy link
Contributor

Choose a reason for hiding this comment

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

You're not going to like this after already completing the work, but I recommend not to add the server variable to the adapter structs. Let's leave it to adapters to capture that information in the future if they'd like. For now, I think we're good with just the updates to the Builder methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries, I've got the muscle memory down for updating the adapters! I'll remove this

Copy link
Contributor

Choose a reason for hiding this comment

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

😂

config/config.go Show resolved Hide resolved
@@ -57,7 +57,8 @@ type ExtRequestPrebid struct {
// NoSale specifies bidders with whom the publisher has a legal relationship where the
// passing of personally identifiable information doesn't constitute a sale per CCPA law.
// The array may contain a single sstar ('*') entry to represent all bidders.
NoSale []string `json:"nosale,omitempty"`
NoSale []string `json:"nosale,omitempty"`
Server *ExtRequestPrebidServer `json:"server,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add this alphabetically in the above section.

@SyntaxNode SyntaxNode self-assigned this Sep 6, 2022
@bsardo bsardo self-requested a review September 6, 2022 17:20
@bsardo bsardo self-assigned this Sep 6, 2022
Copy link
Contributor

@SyntaxNode SyntaxNode left a comment

Choose a reason for hiding this comment

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

Looks good. Thank you for the updates. I noticed two more things in this review pas.

exchange/utils.go Outdated Show resolved Hide resolved
@@ -26,7 +27,7 @@ func BuildAdapters(client *http.Client, cfg *config.Configuration, infos config.
return exchangeBidders, nil
}

func buildBidders(adapterConfig map[string]config.Adapter, infos config.BidderInfos, builders map[openrtb_ext.BidderName]adapters.Builder) (map[openrtb_ext.BidderName]adapters.Bidder, []error) {
func buildBidders(adapterConfig map[string]config.Adapter, infos config.BidderInfos, builders map[openrtb_ext.BidderName]adapters.Builder, hostInfo config.Server) (map[openrtb_ext.BidderName]adapters.Bidder, []error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend to rename hostInfo to server to match the name in the Builder definition and to consider keeping the builders argument as the last one in the signature.

config/config.go Outdated
@@ -597,6 +598,12 @@ type Debug struct {
OverrideToken string `mapstructure:"override_token"`
}

type Server struct {
ExternalUrl string `mapstructure:"external_url"`
GdprID int `mapstructure:"gdpr_id"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: Can we change this name to indicate it is a GVL ID or the GDPR host vendor ID so it is more indicative of what it represents? This data structure appears to be internal to PBS so it should be ok to deviate from what is described in the issue.

@@ -108,6 +109,12 @@ type ExtRequestPrebidCache struct {
VastXML *ExtRequestPrebidCacheVAST `json:"vastxml"`
}

type ExtRequestPrebidServer struct {
ExternalUrl string `json:"externalurl"`
GdprID string `json:"gvlid"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we call this something else like GVLID, HostGVLID or GDPRHostVendorID instead of GdprID to more accurately reflect what this is? I see this is referred to as Gdpr ID in the issue but changing this variable name shouldn't have any external effect since the name of the field on a request is gvlid and the config value is gdpr.host_vendor_id.

bsardo
bsardo previously approved these changes Sep 22, 2022
@bsardo bsardo self-requested a review September 22, 2022 15:57
@@ -202,6 +204,7 @@ func (e *exchange) HoldAuction(ctx context.Context, r AuctionRequest, debugLog *
if err != nil {
return nil, err
}
requestExt.Prebid.Server = &openrtb_ext.ExtRequestPrebidServer{ExternalUrl: e.server.ExternalUrl, GvlID: e.server.GvlID, Datacenter: e.server.Datacenter}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we only be setting this if we have at least one piece of server data? Otherwise we end up with an empty prebid.server object in our bid requests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably a good idea. An Empty method on ExtRequestPrebidServer might be nice to check for this condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good check to add! Will update

config/config.go Outdated
@@ -95,7 +95,7 @@ type Configuration struct {
HostSChainNode *openrtb2.SupplyChainNode `mapstructure:"host_schain_node"`
// Experiment configures non-production ready features.
Experiment Experiment `mapstructure:"experiment"`

Datacenter string `mapstructure:"datacenter"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Consider changing name to DataCenter. The Viper name and mapstructure should stay as is.

config/config.go Outdated
type Server struct {
ExternalUrl string `mapstructure:"external_url"`
GvlID int `mapstructure:"gvlid"`
Datacenter string `mapstructure:"datacenter"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Consider changing name to DataCenter. You can use the rename functionality in your editor to do this easily.

config/config.go Outdated
type Server struct {
ExternalUrl string `mapstructure:"external_url"`
GvlID int `mapstructure:"gvlid"`
Datacenter string `mapstructure:"datacenter"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Please remove the mapstructure attributes. Those are for viper and we're not using viper here.

config/config.go Outdated
@@ -729,7 +735,7 @@ func (cfg *Configuration) AccountDefaultsJSON() json.RawMessage {
return cfg.accountDefaultsJSON
}

//Allows for protocol relative URL if scheme is empty
// Allows for protocol relative URL if scheme is empty
Copy link
Contributor

Choose a reason for hiding this comment

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

Nipick: If you're going to fix the comment, please change it to start with the function name, ie
// GetBaseURL allows for...

type ExtRequestPrebidServer struct {
ExternalUrl string `json:"externalurl"`
GvlID int `json:"gvlid"`
Datacenter string `json:"datacenter"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Consider changing field name to DataCenter.

Comment on lines 207 to 209
if requestExt.Prebid.Server.Empty() {
requestExt.Prebid.Server = &openrtb_ext.ExtRequestPrebidServer{ExternalUrl: e.server.ExternalUrl, GvlID: e.server.GvlID, DataCenter: e.server.DataCenter}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah my earlier thought here wasn't about checking if there was any server data specified in the request, but rather about checking if there was any host data so that we only set requestExt.Prebid.Server if e.server is non-empty in order to avoid creating an object at ext.prebid.server without any real data in it.

My understanding is that server info specified in the host config should always overwrite what is specified in the request.

@SyntaxNode, your suggestion was that it might make sense to put an Empty method on ExtRequestPrebidServer. Were you thinking the logic would then be something like this?

serverInfo := openrtb_ext.ExtRequestPrebidServer{ExternalUrl: e.server.ExternalUrl, GvlID: e.server.GvlID, DataCenter: e.server.DataCenter}
if !extPrebidServer.Empty() {
    requestExt.Prebid.Server = &serverInfo
}

Or should the Empty method go on type Server defined in config/config.go instead?

Copy link
Contributor Author

@AlexBVolcy AlexBVolcy Sep 27, 2022

Choose a reason for hiding this comment

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

Oh yes, I think I messed this up! I think you're right in saying we should only set requestExt.Prebid.Server here when e.server is non-empty. And I could add an Empty method to check if e.server is non-empty.

bsardo
bsardo previously approved these changes Sep 28, 2022
Copy link
Collaborator

@bsardo bsardo left a comment

Choose a reason for hiding this comment

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

LGTM, but need confirmation from @SyntaxNode regarding handling an empty host config.

@@ -2369,74 +2369,28 @@ func TestBuildRequestExtForBidder(t *testing.T) {
expectedJson: json.RawMessage(`{"prebid":{}}`),
},
{
description: "Prebid - Allowed Fields Only",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you might have made a mistake when merging with master. The test cases in this test shouldn't have been deleted or modified to remove references to the test input alternateBidderCodes.
I think you might want to just augment some of these test cases by adding references to request.ext.prebid.server. Actually I think you had done this but lost it during the merge.

@AlexBVolcy AlexBVolcy merged commit c2e6c25 into prebid:master Oct 12, 2022
shunj-nb pushed a commit to ParticleMedia/prebid-server that referenced this pull request Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants