Skip to content

Commit 3bce8ec

Browse files
UOE-10435: Migrate Wakanda to prebid (#783)
1 parent 4f57e3d commit 3bce8ec

31 files changed

+2258
-58
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ format:
3838
formatcheck:
3939
./scripts/format.sh -f false
4040

41+
mockgen: mockgeninstall mockgendb mockgencache mockgenmetrics mockgenlogger mockgenpublisherfeature mockgenwakanda
42+
4143
mockgen: mockgeninstall mockgendb mockgencache mockgenmetrics mockgenlogger mockgenpublisherfeature mockgenprofilemetadata
4244

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

74+
mockgenwakanda:
75+
mkdir -p modules/pubmatic/openwrap/wakanda/mock
76+
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/wakanda Commands,DebugInterface > modules/pubmatic/openwrap/wakanda/mock/mock.go
77+
7278
mockgenprofilemetadata:
7379
mkdir -p modules/pubmatic/openwrap/profilemetadata/mock
74-
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/profilemetadata ProfileMetaData > modules/pubmatic/openwrap/profilemetadata/mock/mock.go
80+
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/profilemetadata ProfileMetaData > modules/pubmatic/openwrap/profilemetadata/mock/mock.go

analytics/pubmatic/helper.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ import (
1313
"github.com/prebid/prebid-server/v2/analytics"
1414
"github.com/prebid/prebid-server/v2/analytics/pubmatic/mhttp"
1515
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
16+
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/wakanda"
1617
)
1718

19+
const parseUrlFormat = "json"
20+
1821
// PrepareLoggerURL returns the url for OW logger call
1922
func PrepareLoggerURL(wlog *WloggerRecord, loggerURL string, gdprEnabled int) string {
2023
if wlog == nil {
@@ -115,3 +118,35 @@ func (wlog *WloggerRecord) logProfileMetaData(rctx *models.RequestCtx) {
115118
wlog.AppSubIntegrationPath = rctx.AppSubIntegrationPath
116119
}
117120
}
121+
122+
func setWakandaObject(rCtx *models.RequestCtx, ao *analytics.AuctionObject, loggerURL string) {
123+
if rCtx.WakandaDebug != nil && rCtx.WakandaDebug.IsEnable() {
124+
setWakandaWinningBidFlag(rCtx.WakandaDebug, ao.Response)
125+
parseURL, err := url.Parse(loggerURL)
126+
if err != nil {
127+
glog.Errorf("Failed to parse loggerURL while setting wakanda object err: %s", err.Error())
128+
}
129+
if parseURL != nil {
130+
jsonParam := parseURL.Query().Get(parseUrlFormat)
131+
rCtx.WakandaDebug.SetLogger(json.RawMessage(jsonParam))
132+
}
133+
bytes, err := json.Marshal(ao.Response)
134+
if err != nil {
135+
glog.Errorf("Failed to marshal ao.Response while setting wakanda object err: %s", err.Error())
136+
}
137+
rCtx.WakandaDebug.SetHTTPResponseBodyWriter(string(bytes))
138+
rCtx.WakandaDebug.SetOpenRTB(ao.RequestWrapper.BidRequest)
139+
rCtx.WakandaDebug.WriteLogToFiles()
140+
}
141+
}
142+
143+
// setWakandaWinningBidFlag will set WinningBid flag to true if we are getting any positive bid in response
144+
func setWakandaWinningBidFlag(wakandaDebug wakanda.WakandaDebug, response *openrtb2.BidResponse) {
145+
if wakandaDebug != nil && response != nil {
146+
if len(response.SeatBid) > 0 &&
147+
len(response.SeatBid[0].Bid) > 0 &&
148+
response.SeatBid[0].Bid[0].Price > 0 {
149+
wakandaDebug.SetWinningBid(true)
150+
}
151+
}
152+
}

analytics/pubmatic/helper_test.go

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
mock_metrics "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/metrics/mock"
1515
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
1616
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/nbr"
17+
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/wakanda"
18+
"github.com/prebid/prebid-server/v2/openrtb_ext"
1719
"github.com/prebid/prebid-server/v2/util/ptrutil"
1820
"github.com/stretchr/testify/assert"
1921
)
@@ -546,3 +548,204 @@ func TestWloggerRecord_logProfileMetaData(t *testing.T) {
546548
})
547549
}
548550
}
551+
552+
func TestSetWakandaWinningBidFlag(t *testing.T) {
553+
type args struct {
554+
wakandaDebug wakanda.WakandaDebug
555+
response *openrtb2.BidResponse
556+
}
557+
tests := []struct {
558+
name string
559+
args args
560+
want wakanda.WakandaDebug
561+
}{
562+
{
563+
name: "all_empty_parameters",
564+
args: args{},
565+
want: nil,
566+
},
567+
{
568+
name: "only_wakanda_empty",
569+
args: args{
570+
wakandaDebug: nil,
571+
response: &openrtb2.BidResponse{
572+
SeatBid: []openrtb2.SeatBid{
573+
{
574+
Bid: []openrtb2.Bid{
575+
{
576+
Price: 5,
577+
},
578+
},
579+
},
580+
},
581+
},
582+
},
583+
want: nil,
584+
},
585+
{
586+
name: "only_response_empty",
587+
args: args{
588+
wakandaDebug: &wakanda.Debug{},
589+
response: nil,
590+
},
591+
want: &wakanda.Debug{},
592+
},
593+
{
594+
name: "no_seatbid",
595+
args: args{
596+
wakandaDebug: &wakanda.Debug{},
597+
response: &openrtb2.BidResponse{},
598+
},
599+
want: &wakanda.Debug{},
600+
},
601+
{
602+
name: "no_bid",
603+
args: args{
604+
wakandaDebug: &wakanda.Debug{},
605+
response: &openrtb2.BidResponse{
606+
SeatBid: []openrtb2.SeatBid{
607+
{},
608+
},
609+
},
610+
},
611+
want: &wakanda.Debug{},
612+
},
613+
{
614+
name: "no_price",
615+
args: args{
616+
wakandaDebug: &wakanda.Debug{},
617+
response: &openrtb2.BidResponse{
618+
SeatBid: []openrtb2.SeatBid{
619+
{
620+
Bid: []openrtb2.Bid{
621+
{},
622+
},
623+
},
624+
},
625+
},
626+
},
627+
want: &wakanda.Debug{},
628+
},
629+
{
630+
name: "non_zero_price",
631+
args: args{
632+
wakandaDebug: &wakanda.Debug{},
633+
response: &openrtb2.BidResponse{
634+
SeatBid: []openrtb2.SeatBid{
635+
{
636+
Bid: []openrtb2.Bid{
637+
{
638+
Price: 5,
639+
},
640+
},
641+
},
642+
},
643+
},
644+
},
645+
want: &wakanda.Debug{DebugData: wakanda.DebugData{WinningBid: true}},
646+
},
647+
}
648+
for _, tt := range tests {
649+
t.Run(tt.name, func(t *testing.T) {
650+
setWakandaWinningBidFlag(tt.args.wakandaDebug, tt.args.response)
651+
assert.Equal(t, tt.want, tt.args.wakandaDebug)
652+
})
653+
}
654+
}
655+
656+
func TestSetWakandaObject(t *testing.T) {
657+
type args struct {
658+
rCtx *models.RequestCtx
659+
ao *analytics.AuctionObject
660+
loggerURL string
661+
}
662+
testCases := []struct {
663+
name string
664+
args args
665+
want *models.RequestCtx
666+
}{
667+
{
668+
name: "rctx is empty",
669+
args: args{
670+
rCtx: &models.RequestCtx{},
671+
ao: &analytics.AuctionObject{},
672+
loggerURL: "",
673+
},
674+
want: &models.RequestCtx{},
675+
},
676+
{
677+
name: "wakanda is disabled",
678+
args: args{
679+
rCtx: &models.RequestCtx{WakandaDebug: &wakanda.Debug{Enabled: false}},
680+
ao: &analytics.AuctionObject{},
681+
loggerURL: "",
682+
},
683+
want: &models.RequestCtx{WakandaDebug: &wakanda.Debug{Enabled: false}},
684+
},
685+
{
686+
name: "wakanda is enabled",
687+
args: args{
688+
rCtx: &models.RequestCtx{WakandaDebug: &wakanda.Debug{Enabled: true}},
689+
ao: &analytics.AuctionObject{
690+
RequestWrapper: &openrtb_ext.RequestWrapper{
691+
BidRequest: &openrtb2.BidRequest{},
692+
},
693+
Response: &openrtb2.BidResponse{},
694+
},
695+
loggerURL: "",
696+
},
697+
want: &models.RequestCtx{WakandaDebug: &wakanda.Debug{Enabled: true, DebugData: wakanda.DebugData{WinningBid: false, HTTPResponseBody: "{\"id\":\"\"}", OpenRTB: &openrtb2.BidRequest{}, Logger: json.RawMessage{}}}},
698+
},
699+
{
700+
name: "wakanda enabled with valid flow",
701+
args: args{
702+
rCtx: &models.RequestCtx{WakandaDebug: &wakanda.Debug{Enabled: true}},
703+
ao: &analytics.AuctionObject{
704+
RequestWrapper: &openrtb_ext.RequestWrapper{
705+
BidRequest: &openrtb2.BidRequest{
706+
Imp: []openrtb2.Imp{
707+
{
708+
ID: "imp_1",
709+
},
710+
},
711+
},
712+
},
713+
Response: &openrtb2.BidResponse{
714+
ID: "123",
715+
BidID: "bid-id-1",
716+
Cur: "USD",
717+
SeatBid: []openrtb2.SeatBid{
718+
{
719+
Seat: "pubmatic",
720+
Bid: []openrtb2.Bid{
721+
{
722+
ID: "bid-id-1",
723+
ImpID: "imp_1",
724+
Price: 5,
725+
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"}`),
726+
},
727+
},
728+
},
729+
},
730+
},
731+
},
732+
loggerURL: "",
733+
},
734+
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\"}",
735+
Logger: json.RawMessage{},
736+
OpenRTB: &openrtb2.BidRequest{
737+
Imp: []openrtb2.Imp{
738+
{
739+
ID: "imp_1",
740+
},
741+
},
742+
}}}},
743+
},
744+
}
745+
for _, tt := range testCases {
746+
t.Run(tt.name, func(t *testing.T) {
747+
setWakandaObject(tt.args.rCtx, tt.args.ao, tt.args.loggerURL)
748+
assert.Equal(t, tt.want, tt.args.rCtx)
749+
})
750+
}
751+
}

analytics/pubmatic/pubmatic.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,16 @@ func (ow HTTPLogger) LogAuctionObject(ao *analytics.AuctionObject) {
6464
glog.Error("Failed to restore bid response for pub:[%d], profile:[%d], version:[%d], err:[%s].", rCtx.PubID, rCtx.ProfileID, rCtx.VersionID, err.Error())
6565
}
6666

67-
url, headers := GetLogAuctionObjectAsURL(*ao, rCtx, false, false)
68-
if url == "" {
67+
loggerURL, headers := GetLogAuctionObjectAsURL(*ao, rCtx, false, false)
68+
if loggerURL == "" {
6969
glog.Errorf("Failed to prepare the owlogger for pub:[%d], profile:[%d], version:[%d].",
7070
rCtx.PubID, rCtx.ProfileID, rCtx.VersionID)
7171
return
7272
}
7373

74-
go send(rCtx, url, headers, mhttp.NewMultiHttpContext())
74+
go send(rCtx, loggerURL, headers, mhttp.NewMultiHttpContext())
75+
76+
setWakandaObject(rCtx, ao, loggerURL)
7577
}
7678

7779
// Writes VideoObject to file

endpoints/openrtb2/auction_ow.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,8 @@ func UpdateResponseExtOW(w http.ResponseWriter, bidResponse *openrtb2.BidRespons
8383
w.WriteHeader(http.StatusNoContent)
8484
}
8585
}
86+
87+
if rCtx.WakandaDebug.IsEnable() {
88+
rCtx.WakandaDebug.SetHTTPResponseWriter(w)
89+
}
8690
}

0 commit comments

Comments
 (0)