Skip to content
Open
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
22 changes: 0 additions & 22 deletions modules/pubmatic/openwrap/allprocessedbidresponsehook.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package openwrap

import (
"context"
"encoding/json"
"log"

"github.com/prebid/prebid-server/v3/exchange/entities"
"github.com/prebid/prebid-server/v3/hooks/hookstage"
Expand Down Expand Up @@ -35,8 +33,6 @@ func (m OpenWrap) handleAllProcessedBidResponsesHook(
return result, nil
}

updateWakandaHTTPCalls(&rCtx, payload)

//Do not execute the module for requests processed in SSHB(8001)
if rCtx.Sshb == "1" || rCtx.Endpoint == models.EndpointHybrid {
return result, nil
Expand All @@ -57,21 +53,3 @@ func updateBidIds(bidderResponses map[openrtb_ext.BidderName]*entities.PbsOrtbSe
}
}
}

func updateWakandaHTTPCalls(rCtx *models.RequestCtx, payload hookstage.AllProcessedBidResponsesPayload) {

if rCtx.WakandaDebug != nil && rCtx.WakandaDebug.IsEnable() {

bidderHttpCalls := make(map[openrtb_ext.BidderName][]*openrtb_ext.ExtHttpCall)
for abc, http := range payload.Responses {
bidderHttpCalls[abc] = append(bidderHttpCalls[abc], http.HttpCalls...)
}

wakandaDebugData, err := json.Marshal(bidderHttpCalls)
if err != nil {
log.Printf("Error marshaling bidderHttpCalls: %v", err)
} else {
rCtx.WakandaDebug.SetHttpCalls(json.RawMessage(wakandaDebugData))
}
}
}
107 changes: 0 additions & 107 deletions modules/pubmatic/openwrap/allprocessedbidresponsehook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package openwrap

import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"

"github.com/golang/mock/gomock"
Expand All @@ -14,7 +11,6 @@ import (
"github.com/prebid/prebid-server/v3/hooks/hookstage"
mock_cache "github.com/prebid/prebid-server/v3/modules/pubmatic/openwrap/cache/mock"
"github.com/prebid/prebid-server/v3/modules/pubmatic/openwrap/models"
"github.com/prebid/prebid-server/v3/modules/pubmatic/openwrap/wakanda"
"github.com/prebid/prebid-server/v3/openrtb_ext"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -249,106 +245,3 @@ func TestOpenWrap_handleAllProcessedBidResponsesHook(t *testing.T) {
})
}
}

func TestUpdateWakandaHTTPCalls(t *testing.T) {
tests := []struct {
name string
rCtx *models.RequestCtx
payload hookstage.AllProcessedBidResponsesPayload
expectedCalls wakanda.WakandaDebug
}{
{
name: "Debug enabled with valid payload",
rCtx: &models.RequestCtx{
WakandaDebug: &wakanda.Debug{Enabled: true},
},
payload: hookstage.AllProcessedBidResponsesPayload{
Responses: map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid{
"bidder1": {
HttpCalls: []*openrtb_ext.ExtHttpCall{{}},
},
"bidder2": {
HttpCalls: []*openrtb_ext.ExtHttpCall{{}},
},
},
},
expectedCalls: &wakanda.Debug{
Enabled: true,
FolderPaths: nil,
DebugData: wakanda.DebugData{
HTTPCalls: json.RawMessage(`{"bidder1":[{"uri":"","requestbody":"","requestheaders":null,"responsebody":"","status":0}],"bidder2":[{"uri":"","requestbody":"","requestheaders":null,"responsebody":"","status":0}]}`),
},
},
},
{
name: "Debug disabled",
rCtx: &models.RequestCtx{
WakandaDebug: &wakanda.Debug{},
},
payload: hookstage.AllProcessedBidResponsesPayload{
Responses: map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid{},
},
expectedCalls: &wakanda.Debug{
Enabled: false,
FolderPaths: []string(nil),
DebugLevel: 0,
DebugData: wakanda.DebugData{
HTTPRequest: (*http.Request)(nil),
HTTPRequestBody: json.RawMessage(nil),
HTTPResponse: http.ResponseWriter(nil),
HTTPResponseBody: "",
OpenRTB: (*openrtb2.BidRequest)(nil),
PrebidHTTPRequest: (*http.Request)(nil),
PrebidRequestBody: json.RawMessage(nil),
PrebidHTTPResponse: (*httptest.ResponseRecorder)(nil),
Logger: json.RawMessage(nil),
WinningBid: false,
HTTPCalls: json.RawMessage(nil)},
Config: wakanda.Wakanda{SFTP: wakanda.SFTP{User: "", Password: "", ServerIP: "", Destination: ""},
HostName: "", DCName: "", PodName: "", MaxDurationInMin: 0, CleanupFrequencyInMin: 0,
},
},
},
{
name: "Error in marshaling",
rCtx: &models.RequestCtx{
WakandaDebug: &wakanda.Debug{},
},
payload: hookstage.AllProcessedBidResponsesPayload{
Responses: map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid{
"bidder1": {
HttpCalls: []*openrtb_ext.ExtHttpCall{{}}, // Example HttpCalls
},
},
},
expectedCalls: &wakanda.Debug{
Enabled: false,
FolderPaths: []string(nil),
DebugLevel: 0,
DebugData: wakanda.DebugData{
HTTPRequest: (*http.Request)(nil),
HTTPRequestBody: json.RawMessage(nil),
HTTPResponse: http.ResponseWriter(nil),
HTTPResponseBody: "",
OpenRTB: (*openrtb2.BidRequest)(nil),
PrebidHTTPRequest: (*http.Request)(nil),
PrebidRequestBody: json.RawMessage(nil),
PrebidHTTPResponse: (*httptest.ResponseRecorder)(nil),
Logger: json.RawMessage(nil),
WinningBid: false,
HTTPCalls: json.RawMessage(nil)},
Config: wakanda.Wakanda{SFTP: wakanda.SFTP{User: "", Password: "", ServerIP: "", Destination: ""},
HostName: "", DCName: "", PodName: "", MaxDurationInMin: 0, CleanupFrequencyInMin: 0,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

updateWakandaHTTPCalls(tt.rCtx, tt.payload)

assert.Equal(t, tt.expectedCalls, tt.rCtx.WakandaDebug)
})
}
}
23 changes: 23 additions & 0 deletions modules/pubmatic/openwrap/auctionresponsehook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openwrap
import (
"context"
"encoding/json"
"log"
"strconv"
"time"

Expand Down Expand Up @@ -317,6 +318,10 @@ func (m OpenWrap) handleAuctionResponseHook(
}
}

if responseExt.Debug != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why wakanda guarded by debug? On production debug is turned off

updateWakandaHTTPCalls(&rctx, *responseExt.Debug)
}

if rctx.IsCTVRequest && rctx.Endpoint == models.EndpointJson {
if len(rctx.RedirectURL) > 0 {
responseExt.Wrapper = &openrtb_ext.ExtWrapper{
Expand Down Expand Up @@ -517,3 +522,21 @@ func CheckWinningBidId(bidId string, wbidIds []string) bool {

return false
}

func updateWakandaHTTPCalls(rCtx *models.RequestCtx, http openrtb_ext.ExtResponseDebug) {

Comment thread
pm-priyanka-bagade marked this conversation as resolved.
if rCtx.WakandaDebug != nil && rCtx.WakandaDebug.IsEnable() {

Comment thread
pm-priyanka-bagade marked this conversation as resolved.
bidderHttpCalls := make(map[openrtb_ext.BidderName][]*openrtb_ext.ExtHttpCall)
for abc, http := range http.HttpCalls {
bidderHttpCalls[abc] = append(bidderHttpCalls[abc], http...)
}

wakandaDebugData, err := json.Marshal(bidderHttpCalls)
if err != nil {
log.Printf("Error marshaling bidderHttpCalls: %v", err)
} else {
rCtx.WakandaDebug.SetHttpCalls(json.RawMessage(wakandaDebugData))
}
}
}
40 changes: 40 additions & 0 deletions modules/pubmatic/openwrap/auctionresponsehook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/prebid/prebid-server/v3/modules/pubmatic/openwrap/models"
"github.com/prebid/prebid-server/v3/modules/pubmatic/openwrap/models/nbr"
mock_feature "github.com/prebid/prebid-server/v3/modules/pubmatic/openwrap/publisherfeature/mock"
"github.com/prebid/prebid-server/v3/modules/pubmatic/openwrap/wakanda"
"github.com/prebid/prebid-server/v3/openrtb_ext"
"github.com/prebid/prebid-server/v3/util/ptrutil"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -1949,3 +1950,42 @@ func TestAuctionResponseHookForApplovinMax(t *testing.T) {
})
}
}

func TestUpdateWakandaHTTPCalls(t *testing.T) {
tests := []struct {
name string
rCtx *models.RequestCtx
debugResp openrtb_ext.ExtResponseDebug
expectedHTTPCalls *models.RequestCtx
}{
{
name: "Debug enabled with valid payload",
rCtx: &models.RequestCtx{
WakandaDebug: &wakanda.Debug{Enabled: true},
},
debugResp: openrtb_ext.ExtResponseDebug{
HttpCalls: map[openrtb_ext.BidderName][]*openrtb_ext.ExtHttpCall{
"bidder1": {{Uri: "http://test1.com"}},
"bidder2": {{Uri: "http://test2.com"}},
},
},
expectedHTTPCalls: &models.RequestCtx{WakandaDebug: &wakanda.Debug{Enabled: true, DebugData: wakanda.DebugData{HTTPCalls: json.RawMessage(`{"bidder1":[{"uri":"http://test1.com","requestbody":"","requestheaders":null,"responsebody":"","status":0}],"bidder2":[{"uri":"http://test2.com","requestbody":"","requestheaders":null,"responsebody":"","status":0}]}`)}}},
},
{
name: "Debug disabled - should not populate HTTPCalls",
rCtx: &models.RequestCtx{
WakandaDebug: &wakanda.Debug{Enabled: false},
},
debugResp: openrtb_ext.ExtResponseDebug{},
expectedHTTPCalls: &models.RequestCtx{WakandaDebug: &wakanda.Debug{}},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
updateWakandaHTTPCalls(tt.rCtx, tt.debugResp)

assert.Equal(t, tt.rCtx, tt.expectedHTTPCalls)
})
}
}
Loading