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

Release_9th_July_2024 #834

Merged
merged 7 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ format:
formatcheck:
./scripts/format.sh -f false

mockgen: mockgeninstall mockgendb mockgencache mockgenmetrics mockgenlogger mockgenpublisherfeature mockgenwakanda

mockgen: mockgeninstall mockgendb mockgencache mockgenmetrics mockgenlogger mockgenpublisherfeature mockgenprofilemetadata

# export GOPATH=~/go ; GOBIN=~/go/bin; export PATH=$PATH:$GOBIN
Expand Down Expand Up @@ -69,6 +71,10 @@ mockgenpublisherfeature:
mkdir -p modules/pubmatic/openwrap/publisherfeature
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/publisherfeature Feature > modules/pubmatic/openwrap/publisherfeature/mock/mock.go

mockgenwakanda:
mkdir -p modules/pubmatic/openwrap/wakanda/mock
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/wakanda Commands,DebugInterface > modules/pubmatic/openwrap/wakanda/mock/mock.go

mockgenprofilemetadata:
mkdir -p modules/pubmatic/openwrap/profilemetadata/mock
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/profilemetadata ProfileMetaData > modules/pubmatic/openwrap/profilemetadata/mock/mock.go
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/profilemetadata ProfileMetaData > modules/pubmatic/openwrap/profilemetadata/mock/mock.go
35 changes: 35 additions & 0 deletions analytics/pubmatic/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import (
"github.com/prebid/prebid-server/v2/analytics"
"github.com/prebid/prebid-server/v2/analytics/pubmatic/mhttp"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/wakanda"
)

const parseUrlFormat = "json"

// PrepareLoggerURL returns the url for OW logger call
func PrepareLoggerURL(wlog *WloggerRecord, loggerURL string, gdprEnabled int) string {
if wlog == nil {
Expand Down Expand Up @@ -115,3 +118,35 @@ func (wlog *WloggerRecord) logProfileMetaData(rctx *models.RequestCtx) {
wlog.AppSubIntegrationPath = rctx.AppSubIntegrationPath
}
}

func setWakandaObject(rCtx *models.RequestCtx, ao *analytics.AuctionObject, loggerURL string) {
if rCtx.WakandaDebug != nil && rCtx.WakandaDebug.IsEnable() {
setWakandaWinningBidFlag(rCtx.WakandaDebug, ao.Response)
parseURL, err := url.Parse(loggerURL)
if err != nil {
glog.Errorf("Failed to parse loggerURL while setting wakanda object err: %s", err.Error())
}
if parseURL != nil {
jsonParam := parseURL.Query().Get(parseUrlFormat)
rCtx.WakandaDebug.SetLogger(json.RawMessage(jsonParam))
}
bytes, err := json.Marshal(ao.Response)
if err != nil {
glog.Errorf("Failed to marshal ao.Response while setting wakanda object err: %s", err.Error())
}
rCtx.WakandaDebug.SetHTTPResponseBodyWriter(string(bytes))
rCtx.WakandaDebug.SetOpenRTB(ao.RequestWrapper.BidRequest)
rCtx.WakandaDebug.WriteLogToFiles()
}
}

// setWakandaWinningBidFlag will set WinningBid flag to true if we are getting any positive bid in response
func setWakandaWinningBidFlag(wakandaDebug wakanda.WakandaDebug, response *openrtb2.BidResponse) {
if wakandaDebug != nil && response != nil {
if len(response.SeatBid) > 0 &&
len(response.SeatBid[0].Bid) > 0 &&
response.SeatBid[0].Bid[0].Price > 0 {
wakandaDebug.SetWinningBid(true)
}
}
}
203 changes: 203 additions & 0 deletions analytics/pubmatic/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
mock_metrics "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/metrics/mock"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/nbr"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/wakanda"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/ptrutil"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -546,3 +548,204 @@ func TestWloggerRecord_logProfileMetaData(t *testing.T) {
})
}
}

func TestSetWakandaWinningBidFlag(t *testing.T) {
type args struct {
wakandaDebug wakanda.WakandaDebug
response *openrtb2.BidResponse
}
tests := []struct {
name string
args args
want wakanda.WakandaDebug
}{
{
name: "all_empty_parameters",
args: args{},
want: nil,
},
{
name: "only_wakanda_empty",
args: args{
wakandaDebug: nil,
response: &openrtb2.BidResponse{
SeatBid: []openrtb2.SeatBid{
{
Bid: []openrtb2.Bid{
{
Price: 5,
},
},
},
},
},
},
want: nil,
},
{
name: "only_response_empty",
args: args{
wakandaDebug: &wakanda.Debug{},
response: nil,
},
want: &wakanda.Debug{},
},
{
name: "no_seatbid",
args: args{
wakandaDebug: &wakanda.Debug{},
response: &openrtb2.BidResponse{},
},
want: &wakanda.Debug{},
},
{
name: "no_bid",
args: args{
wakandaDebug: &wakanda.Debug{},
response: &openrtb2.BidResponse{
SeatBid: []openrtb2.SeatBid{
{},
},
},
},
want: &wakanda.Debug{},
},
{
name: "no_price",
args: args{
wakandaDebug: &wakanda.Debug{},
response: &openrtb2.BidResponse{
SeatBid: []openrtb2.SeatBid{
{
Bid: []openrtb2.Bid{
{},
},
},
},
},
},
want: &wakanda.Debug{},
},
{
name: "non_zero_price",
args: args{
wakandaDebug: &wakanda.Debug{},
response: &openrtb2.BidResponse{
SeatBid: []openrtb2.SeatBid{
{
Bid: []openrtb2.Bid{
{
Price: 5,
},
},
},
},
},
},
want: &wakanda.Debug{DebugData: wakanda.DebugData{WinningBid: true}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
setWakandaWinningBidFlag(tt.args.wakandaDebug, tt.args.response)
assert.Equal(t, tt.want, tt.args.wakandaDebug)
})
}
}

func TestSetWakandaObject(t *testing.T) {
type args struct {
rCtx *models.RequestCtx
ao *analytics.AuctionObject
loggerURL string
}
testCases := []struct {
name string
args args
want *models.RequestCtx
}{
{
name: "rctx is empty",
args: args{
rCtx: &models.RequestCtx{},
ao: &analytics.AuctionObject{},
loggerURL: "",
},
want: &models.RequestCtx{},
},
{
name: "wakanda is disabled",
args: args{
rCtx: &models.RequestCtx{WakandaDebug: &wakanda.Debug{Enabled: false}},
ao: &analytics.AuctionObject{},
loggerURL: "",
},
want: &models.RequestCtx{WakandaDebug: &wakanda.Debug{Enabled: false}},
},
{
name: "wakanda is enabled",
args: args{
rCtx: &models.RequestCtx{WakandaDebug: &wakanda.Debug{Enabled: true}},
ao: &analytics.AuctionObject{
RequestWrapper: &openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{},
},
Response: &openrtb2.BidResponse{},
},
loggerURL: "",
},
want: &models.RequestCtx{WakandaDebug: &wakanda.Debug{Enabled: true, DebugData: wakanda.DebugData{WinningBid: false, HTTPResponseBody: "{\"id\":\"\"}", OpenRTB: &openrtb2.BidRequest{}, Logger: json.RawMessage{}}}},
},
{
name: "wakanda enabled with valid flow",
args: args{
rCtx: &models.RequestCtx{WakandaDebug: &wakanda.Debug{Enabled: true}},
ao: &analytics.AuctionObject{
RequestWrapper: &openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
ID: "imp_1",
},
},
},
},
Response: &openrtb2.BidResponse{
ID: "123",
BidID: "bid-id-1",
Cur: "USD",
SeatBid: []openrtb2.SeatBid{
{
Seat: "pubmatic",
Bid: []openrtb2.Bid{
{
ID: "bid-id-1",
ImpID: "imp_1",
Price: 5,
Ext: json.RawMessage(`{"signaldata":"{\"id\":\"123\",\"seatbid\":[{\"bid\":[{\"id\":\"bid-id-1\",\"impid\":\"imp_1\",\"price\":5}],\"seat\":\"pubmatic\"}],\"bidid\":\"bid-id-1\",\"cur\":\"USD\",\"ext\":{\"matchedimpression\":{\"appnexus\":50,\"pubmatic\":50}}}\r\n"}`),
},
},
},
},
},
},
loggerURL: "",
},
want: &models.RequestCtx{WakandaDebug: &wakanda.Debug{Enabled: true, DebugData: wakanda.DebugData{WinningBid: true, HTTPResponseBody: "{\"id\":\"123\",\"seatbid\":[{\"bid\":[{\"id\":\"bid-id-1\",\"impid\":\"imp_1\",\"price\":5,\"ext\":{\"signaldata\":\"{\\\"id\\\":\\\"123\\\",\\\"seatbid\\\":[{\\\"bid\\\":[{\\\"id\\\":\\\"bid-id-1\\\",\\\"impid\\\":\\\"imp_1\\\",\\\"price\\\":5}],\\\"seat\\\":\\\"pubmatic\\\"}],\\\"bidid\\\":\\\"bid-id-1\\\",\\\"cur\\\":\\\"USD\\\",\\\"ext\\\":{\\\"matchedimpression\\\":{\\\"appnexus\\\":50,\\\"pubmatic\\\":50}}}\\r\\n\"}}],\"seat\":\"pubmatic\"}],\"bidid\":\"bid-id-1\",\"cur\":\"USD\"}",
Logger: json.RawMessage{},
OpenRTB: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
ID: "imp_1",
},
},
}}}},
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
setWakandaObject(tt.args.rCtx, tt.args.ao, tt.args.loggerURL)
assert.Equal(t, tt.want, tt.args.rCtx)
})
}
}
Loading
Loading