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

Rubicon: Remove pchain support #4166

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions adapters/rubicon/rubicon.go
Original file line number Diff line number Diff line change
@@ -436,37 +436,26 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
rubiconRequest.App = &appCopy
}

if request.Source != nil || rubiconExt.PChain != "" {
var sourceCopy openrtb2.Source
if request.Source != nil {
sourceCopy = *request.Source
} else {
sourceCopy = openrtb2.Source{}
}

if sourceCopy.SChain != nil {
var sourceCopyExt openrtb_ext.ExtSource
if sourceCopy.Ext != nil {
if err = jsonutil.Unmarshal(sourceCopy.Ext, &sourceCopyExt); err != nil {
errs = append(errs, &errortypes.BadInput{Message: err.Error()})
continue
}
} else {
sourceCopyExt = openrtb_ext.ExtSource{}
}

sourceCopyExt.SChain = sourceCopy.SChain
sourceCopy.SChain = nil
if request.Source != nil && request.Source.SChain != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider the following test case:

    {
        desc: "3) non-nil source, pchain = \"\", nil SChain",
        in: testInput{
            request: &openrtb2.BidRequest{
                Source: &openrtb2.Source{TID: "someSourceTID"},
            },
            pChain: "",
        },
    },

The && operator will prevent the request.Source to get copied to rubiconRequest.Source causing a loss of information that request.Source might be carrying, like the request.Source.TID field set to "someSourceTID" in our example. Is this the desired behavior?

If not, 4 of the 6 scenarios considered below, fail because of this logic.

func TestFunc(t *testing.T) {
	type testInput struct {
		request *openrtb2.BidRequest
		pChain  string
	}
	testCases := []struct {
		desc string
		in   testInput
	}{
		{
			desc: "1) nil Source, pchain = \"\"",
			in: testInput{
				request: &openrtb2.BidRequest{},
				pChain:  "",
			},
		},
		{
			desc: "2) nil Source, pchain = \"pchain\"",

			in: testInput{
				request: &openrtb2.BidRequest{},
				pChain:  "pchain",
			},
		},
		{
			desc: "3) non-nil source, pchain = \"\", nil SChain",
			in: testInput{
				request: &openrtb2.BidRequest{
					Source: &openrtb2.Source{TID: "someSourceTID"},
				},
				pChain: "",
			},
		},
		{
			desc: "4) non-nil Source, pchain = \"\", non-nil SChain",
			in: testInput{
				request: &openrtb2.BidRequest{
					Source: &openrtb2.Source{
						TID: "someSourceTID",
						SChain: &openrtb2.SupplyChain{
							Complete: 0,
						},
					},
				},
				pChain: "",
			},
		},
		{
			desc: "5) non-nil Source, pchain = \"pchain\", nil SChain",
			in: testInput{
				request: &openrtb2.BidRequest{
					Source: &openrtb2.Source{TID: "someSourceTID"},
				},
				pChain: "pchain",
			},
		},
		{
			desc: "6) non-nil Source, pchain = \"pchain\", non-nil SChain",
			in: testInput{
				request: &openrtb2.BidRequest{
					Source: &openrtb2.Source{
						TID: "someSourceTID",
						SChain: &openrtb2.SupplyChain{
							Complete: 0,
						},
					},
				},
				pChain: "pchain",
			},
		},
	}

	for _, tc := range testCases {
		beforeResult := &openrtb2.BidRequest{}
		afterResult := &openrtb2.BidRequest{}

		before(tc.in.request, beforeResult, tc.in.pChain)
		after(tc.in.request, afterResult, tc.in.pChain)

		assert.Equal(t, beforeResult, afterResult, tc.desc)
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only reason to change the source is having a schain field, otherwise we don't even need to make a copy of the source

I don't see any information loss since the rubiconRequest is a copy of request and the source is kept unchanged

sourceCopy := *request.Source

sourceCopy.Ext, err = json.Marshal(&sourceCopyExt)
if err != nil {
errs = append(errs, err)
var sourceCopyExt openrtb_ext.ExtSource
if sourceCopy.Ext != nil {
if err = jsonutil.Unmarshal(sourceCopy.Ext, &sourceCopyExt); err != nil {
errs = append(errs, &errortypes.BadInput{Message: err.Error()})
continue
}
} else {
sourceCopyExt = openrtb_ext.ExtSource{}
}

if rubiconExt.PChain != "" {
sourceCopy.PChain = rubiconExt.PChain
sourceCopyExt.SChain = sourceCopy.SChain
sourceCopy.SChain = nil

sourceCopy.Ext, err = json.Marshal(&sourceCopyExt)
if err != nil {
errs = append(errs, err)
continue
}

rubiconRequest.Source = &sourceCopy
Original file line number Diff line number Diff line change
@@ -154,8 +154,7 @@
"bidder": {
"accountId": 1001,
"siteId": 113932,
"zoneId": 535510,
"pchain": "pchain"
"zoneId": 535510
},
"skadn": {
"version": "1.0",
@@ -323,7 +322,6 @@
"bundle": "com.wls.testwlsapplication"
},
"source": {
"pchain": "pchain",
"ext": {
"schain": {
"complete": 0,
6 changes: 1 addition & 5 deletions adapters/rubicon/rubicontest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
@@ -131,8 +131,7 @@
"bidder": {
"accountId": 1001,
"siteId": 113932,
"zoneId": 535510,
"pchain": "pchain"
"zoneId": 535510
},
"skadn": {
"version": "1.0",
@@ -299,9 +298,6 @@
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"source": {
"pchain": "pchain"
},
"imp": [
{
"id": "test-imp-id",
1 change: 0 additions & 1 deletion openrtb_ext/imp_rubicon.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ type ExtImpRubicon struct {
Visitor json.RawMessage `json:"visitor,omitempty"`
Video rubiconVideoParams `json:"video"`
Debug impExtRubiconDebug `json:"debug,omitempty"`
PChain string `json:"pchain,omitempty"`
}

// rubiconVideoParams defines the contract for bidrequest.imp[i].ext.prebid.bidder.rubicon.video