Skip to content

Commit

Permalink
Merge pull request #680 from PubMatic-OpenWrap/ci
Browse files Browse the repository at this point in the history
Release_9th_january_2023
  • Loading branch information
pm-nilesh-chate authored Jan 5, 2024
2 parents 887f705 + ea58f15 commit 886db52
Show file tree
Hide file tree
Showing 42 changed files with 4,438 additions and 93 deletions.
18 changes: 10 additions & 8 deletions analytics/pubmatic/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,32 @@ func TestPrepareLoggerURL(t *testing.T) {
args: args{
wlog: &WloggerRecord{
record: record{
PubID: 10,
ProfileID: "1",
VersionID: "0",
PubID: 10,
ProfileID: "1",
VersionID: "0",
CustomDimensions: "age=23;traffic=media",
},
},
loggerURL: "http://t.pubmatic.com/wl",
gdprEnabled: 0,
},
owlogger: `http://t.pubmatic.com/wl?json={"pubid":10,"pid":"1","pdvid":"0","dvc":{},"ft":0}&pubid=10`,
owlogger: `http://t.pubmatic.com/wl?json={"pubid":10,"pid":"1","pdvid":"0","dvc":{},"ft":0,"cds":"age=23;traffic=media"}&pubid=10`,
},
{
name: "private endpoint",
args: args{
wlog: &WloggerRecord{
record: record{
PubID: 5,
ProfileID: "5",
VersionID: "1",
PubID: 5,
ProfileID: "5",
VersionID: "1",
CustomDimensions: "age=23;traffic=media",
},
},
loggerURL: "http://10.172.141.11/wl",
gdprEnabled: 0,
},
owlogger: `http://10.172.141.11/wl?json={"pubid":5,"pid":"5","pdvid":"1","dvc":{},"ft":0}&pubid=5`,
owlogger: `http://10.172.141.11/wl?json={"pubid":5,"pid":"5","pdvid":"1","dvc":{},"ft":0,"cds":"age=23;traffic=media"}&pubid=5`,
},
}
for _, tt := range tests {
Expand Down
13 changes: 8 additions & 5 deletions analytics/pubmatic/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/prebid/prebid-server/analytics"
"github.com/prebid/prebid-server/hooks/hookexecution"
"github.com/prebid/prebid-server/modules/pubmatic/openwrap"
"github.com/prebid/prebid-server/modules/pubmatic/openwrap/customdimensions"
"github.com/prebid/prebid-server/modules/pubmatic/openwrap/models"
"github.com/prebid/prebid-server/modules/pubmatic/openwrap/utils"
"github.com/prebid/prebid-server/openrtb_ext"
Expand Down Expand Up @@ -123,9 +124,10 @@ func GetLogAuctionObjectAsURL(ao analytics.AuctionObject, rCtx *models.RequestCt
wlog.logFloorType(&rCtx.NewReqExt.Prebid)
}

// set the floor details from tracker
floorDetailsSet := false
// set the floor details and cds from tracker
cdsAndfloorDetailsSet := false
for _, tracker := range rCtx.Trackers {
wlog.CustomDimensions = tracker.Tracker.CustomDimensions
wlog.FloorType = tracker.Tracker.FloorType
wlog.FloorModelVersion = tracker.Tracker.FloorModelVersion
wlog.FloorSource = tracker.Tracker.FloorSource
Expand All @@ -134,13 +136,14 @@ func GetLogAuctionObjectAsURL(ao analytics.AuctionObject, rCtx *models.RequestCt
for i := range wlog.Slots {
wlog.Slots[i].FloorSkippedFlag = tracker.Tracker.FloorSkippedFlag
}
floorDetailsSet = true
break // For all trackers, floor-details are common so break the loop
cdsAndfloorDetailsSet = true
break // For all trackers, floor-details and cds are common so break the loop
}

// if floor details not present in tracker then use response.ext
// this wil happen only if no valid bid is present in response.seatbid
if !floorDetailsSet {
if !cdsAndfloorDetailsSet {
wlog.CustomDimensions = customdimensions.ConvertCustomDimensionsToString(rCtx.CustomDimensions)
if rCtx.ResponseExt.Prebid != nil {
// wlog.SetFloorDetails(rCtx.ResponseExt.Prebid.Floors)
floorDetails := models.GetFloorsDetails(rCtx.ResponseExt)
Expand Down
17 changes: 12 additions & 5 deletions analytics/pubmatic/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3956,7 +3956,7 @@ func TestGetLogAuctionObjectAsURLForFloorType(t *testing.T) {
})
}
}
func TestGetLogAuctionObjectAsURLForFloorDetails(t *testing.T) {
func TestGetLogAuctionObjectAsURLForFloorDetailsAndCDS(t *testing.T) {
cfg := ow.cfg
uuidFunc := getUUID
defer func() {
Expand Down Expand Up @@ -4007,6 +4007,7 @@ func TestGetLogAuctionObjectAsURLForFloorDetails(t *testing.T) {
FloorProvider: "provider",
FloorFetchStatus: ptrutil.ToPtr(3),
},
CustomDimensions: "traffic=media;age=23",
},
},
},
Expand All @@ -4015,7 +4016,7 @@ func TestGetLogAuctionObjectAsURLForFloorDetails(t *testing.T) {
forRespExt: true,
},
want: want{
logger: `http://t.pubmatic.com/wl?json={"pubid":5890,"pid":"0","pdvid":"0","sl":1,"dvc":{},"fmv":"model-version","fsrc":2,"ft":0,"ffs":3,"fp":"provider"}&pubid=5890`,
logger: `http://t.pubmatic.com/wl?json={"pubid":5890,"pid":"0","pdvid":"0","sl":1,"dvc":{},"fmv":"model-version","fsrc":2,"ft":0,"ffs":3,"fp":"provider","cds":"traffic=media;age=23"}&pubid=5890`,
header: http.Header{
models.USER_AGENT_HEADER: []string{""},
models.IP_HEADER: []string{""},
Expand Down Expand Up @@ -4059,6 +4060,7 @@ func TestGetLogAuctionObjectAsURLForFloorDetails(t *testing.T) {
FloorProvider: "provider",
FloorFetchStatus: ptrutil.ToPtr(3),
},
CustomDimensions: "traffic=media;age=23",
},
},
},
Expand All @@ -4067,15 +4069,15 @@ func TestGetLogAuctionObjectAsURLForFloorDetails(t *testing.T) {
forRespExt: true,
},
want: want{
logger: ow.cfg.Endpoint + `?json={"pubid":5890,"pid":"0","pdvid":"0","sl":1,"s":[{"sid":"uuid","sn":"sn","au":"au","ps":[],"fskp":1}],"dvc":{},"fmv":"model-version","fsrc":2,"ft":0,"ffs":3,"fp":"provider"}&pubid=5890`,
logger: ow.cfg.Endpoint + `?json={"pubid":5890,"pid":"0","pdvid":"0","sl":1,"s":[{"sid":"uuid","sn":"sn","au":"au","ps":[],"fskp":1}],"dvc":{},"fmv":"model-version","fsrc":2,"ft":0,"ffs":3,"fp":"provider","cds":"traffic=media;age=23"}&pubid=5890`,
header: http.Header{
models.USER_AGENT_HEADER: []string{""},
models.IP_HEADER: []string{""},
},
},
},
{
name: "set floor details from responseExt if tracker details are absent",
name: "set floor details from responseExt and cds from rtcx if tracker details are absent",
args: args{
ao: analytics.AuctionObject{
RequestWrapper: &openrtb_ext.RequestWrapper{
Expand All @@ -4100,6 +4102,11 @@ func TestGetLogAuctionObjectAsURLForFloorDetails(t *testing.T) {
SlotName: "sn",
},
},
CustomDimensions: map[string]models.CustomDimension{
"author": {
Value: "robertshinde",
},
},
ResponseExt: openrtb_ext.ExtBidResponse{
Prebid: &openrtb_ext.ExtResponsePrebid{
Floors: &openrtb_ext.PriceFloorRules{
Expand All @@ -4125,7 +4132,7 @@ func TestGetLogAuctionObjectAsURLForFloorDetails(t *testing.T) {
forRespExt: true,
},
want: want{
logger: ow.cfg.Endpoint + `?json={"pubid":5890,"pid":"0","pdvid":"0","sl":1,"s":[{"sid":"uuid","sn":"sn","au":"au","ps":[],"fskp":1}],"dvc":{},"fmv":"model-version","fsrc":2,"ft":1,"ffs":2,"fp":"provider"}&pubid=5890`,
logger: ow.cfg.Endpoint + `?json={"pubid":5890,"pid":"0","pdvid":"0","sl":1,"s":[{"sid":"uuid","sn":"sn","au":"au","ps":[],"fskp":1}],"dvc":{},"fmv":"model-version","fsrc":2,"ft":1,"ffs":2,"fp":"provider","cds":"author=robertshinde"}&pubid=5890`,
header: http.Header{
models.USER_AGENT_HEADER: []string{""},
models.IP_HEADER: []string{""},
Expand Down
1 change: 1 addition & 0 deletions analytics/pubmatic/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type record struct {
FloorFetchStatus *int `json:"ffs,omitempty"`
FloorProvider string `json:"fp,omitempty"`
PDC string `json:"pdc,omitempty"`
CustomDimensions string `json:"cds,omitempty"`
}

// Device struct for storing device information
Expand Down
17 changes: 13 additions & 4 deletions modules/pubmatic/openwrap/adapters/bidder_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@ import (
"github.com/prebid/prebid-server/openrtb_ext"
)

// Alias will return copy of exisiting alias
func Alias() map[string]string {

return map[string]string{
models.BidderAdGenerationAlias: string(openrtb_ext.BidderAdgeneration),
models.BidderDistrictmDMXAlias: string(openrtb_ext.BidderDmx),
models.BidderPubMaticSecondaryAlias: string(openrtb_ext.BidderPubmatic),
models.BidderDistrictmAlias: string(openrtb_ext.BidderAppnexus),
models.BidderAndBeyondAlias: string(openrtb_ext.BidderAdkernel),
models.BidderMediaFuseAlias: string(openrtb_ext.BidderAppnexus),
}
}

//ResolveOWBidder it resolves hardcoded bidder alias names

func ResolveOWBidder(bidderName string) string {

var coreBidderName string

switch bidderName {

case models.BidderAdGenerationAlias:
coreBidderName = string(openrtb_ext.BidderAdgeneration)
case models.BidderDistrictmDMXAlias:
Expand All @@ -25,8 +36,6 @@ func ResolveOWBidder(bidderName string) string {
coreBidderName = string(openrtb_ext.BidderAdkernel)
default:
coreBidderName = bidderName

}

return coreBidderName
}
29 changes: 29 additions & 0 deletions modules/pubmatic/openwrap/adapters/bidder_alias_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package adapters

import (
"testing"

"github.com/prebid/prebid-server/modules/pubmatic/openwrap/models"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/stretchr/testify/assert"
)

func TestAlias(t *testing.T) {
expected := map[string]string{
models.BidderAdGenerationAlias: string(openrtb_ext.BidderAdgeneration),
models.BidderDistrictmDMXAlias: string(openrtb_ext.BidderDmx),
models.BidderPubMaticSecondaryAlias: string(openrtb_ext.BidderPubmatic),
models.BidderDistrictmAlias: string(openrtb_ext.BidderAppnexus),
models.BidderAndBeyondAlias: string(openrtb_ext.BidderAdkernel),
models.BidderMediaFuseAlias: string(openrtb_ext.BidderAppnexus),
}
assert.Equal(t, expected, Alias())
}

func TestResolveOWBidder(t *testing.T) {
assert.Equal(t, "", ResolveOWBidder(""))
assert.Equal(t, models.BidderPubMatic, ResolveOWBidder(models.BidderPubMatic))
for alias, coreBidder := range Alias() {
assert.Equal(t, coreBidder, ResolveOWBidder(alias))
}
}
39 changes: 38 additions & 1 deletion modules/pubmatic/openwrap/adapters/bidders.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func PrepareBidParamJSONForPartner(width *int64, height *int64, fieldMap map[str
}

//get callback function and execute it
callback := getBuilder(params.AdapterName)
callback := GetBuilder(params.AdapterName)
return callback(params)
}

Expand Down Expand Up @@ -602,3 +602,40 @@ func builderBoldwin(params BidderParameters) (json.RawMessage, error) {
jsonStr.WriteByte('}')
return jsonStr.Bytes(), nil
}

func builderColossus(params BidderParameters) (json.RawMessage, error) {
jsonStr := bytes.Buffer{}
jsonStr.WriteByte('{')
oneOf := []string{BidderParamColossusTagID, BidderParamColossusgroupID}
for _, param := range oneOf {
if key, ok := getString(params.FieldMap[param]); ok {
fmt.Fprintf(&jsonStr, `"%s":"%s"`, param, key)
break
}
}
// len=0 (no mandatory params present)
if jsonStr.Len() == 1 {
return nil, fmt.Errorf(errMandatoryParameterMissingFormat, params.AdapterName, oneOf)
}

jsonStr.WriteByte('}')
return jsonStr.Bytes(), nil
}

func builderNextmillennium(params BidderParameters) (json.RawMessage, error) {
jsonStr := bytes.Buffer{}

anyOf := []string{"placement_id", "group_id"}
for _, param := range anyOf {
if val, ok := getString(params.FieldMap[param]); ok {
fmt.Fprintf(&jsonStr, `{"%s":"%s"}`, param, val)
break
}
}

if jsonStr.Len() == 0 {
return nil, fmt.Errorf(errMandatoryParameterMissingFormat, params.AdapterName, anyOf)
}

return jsonStr.Bytes(), nil
}
Loading

0 comments on commit 886db52

Please sign in to comment.