Skip to content

Commit

Permalink
Merge branch 'ci' into UOE-10435-1
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-priyanka-bagade committed May 7, 2024
2 parents 1a015c6 + 5cb451a commit f5ffba7
Show file tree
Hide file tree
Showing 26 changed files with 810 additions and 142 deletions.
15 changes: 15 additions & 0 deletions analytics/pubmatic/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func GetLogAuctionObjectAsURL(ao analytics.AuctionObject, rCtx *models.RequestCt
if ao.RequestWrapper == nil || ao.RequestWrapper.BidRequest == nil || rCtx == nil || rCtx.PubID == 0 || rCtx.LoggerDisabled {
return "", nil, nil
}
// Get Updated Floor values using floor rules from updated request
getFloorValueFromUpdatedRequest(ao.RequestWrapper, rCtx)

wlog := WloggerRecord{
record: record{
Expand Down Expand Up @@ -191,6 +193,19 @@ func GetRequestCtx(hookExecutionOutcome []hookexecution.StageOutcome) *models.Re
return nil
}

// getFloorValueFromUpdatedRequest gets updated floor values by floor module
func getFloorValueFromUpdatedRequest(reqWrapper *openrtb_ext.RequestWrapper, rCtx *models.RequestCtx) {
for _, imp := range reqWrapper.BidRequest.Imp {
if impCtx, ok := rCtx.ImpBidCtx[imp.ID]; ok {
if imp.BidFloor > 0 && impCtx.BidFloor != imp.BidFloor {
impCtx.BidFloor = imp.BidFloor
impCtx.BidFloorCur = imp.BidFloorCur
rCtx.ImpBidCtx[imp.ID] = impCtx
}
}
}
}

func convertNonBidToBidWrapper(nonBid *openrtb_ext.NonBid) (bid bidWrapper) {
bid.Bid = &openrtb2.Bid{
Price: nonBid.Ext.Prebid.Bid.Price,
Expand Down
203 changes: 203 additions & 0 deletions analytics/pubmatic/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4192,6 +4192,79 @@ func TestGetLogAuctionObjectAsURLForFloorDetailsAndCDS(t *testing.T) {
},
},
},
{
name: "set floor value from updated impression if tracker details are absent",
args: args{
ao: analytics.AuctionObject{
RequestWrapper: &openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
ID: "imp-1",
BidFloor: 10.10,
BidFloorCur: "USD",
},
},
},
},
Response: &openrtb2.BidResponse{
SeatBid: []openrtb2.SeatBid{
{
Seat: "pubmatic",
Bid: []openrtb2.Bid{
{
ID: "bid-id-1",
ImpID: "imp-1",
},
},
},
},
},
},
rCtx: &models.RequestCtx{
PubID: 5890,
NewReqExt: &models.RequestExt{
ExtRequest: openrtb_ext.ExtRequest{},
},
ImpBidCtx: map[string]models.ImpCtx{
"imp-1": {
AdUnitName: "au",
SlotName: "sn",
BidFloor: 2.0,
BidFloorCur: "USD",
},
},
ResponseExt: openrtb_ext.ExtBidResponse{
Prebid: &openrtb_ext.ExtResponsePrebid{
Floors: &openrtb_ext.PriceFloorRules{
FetchStatus: openrtb_ext.FetchError,
Data: &openrtb_ext.PriceFloorData{
ModelGroups: []openrtb_ext.PriceFloorModelGroup{
{
ModelVersion: "model-version",
},
},
FloorProvider: "provider1",
},
PriceFloorLocation: openrtb_ext.FetchLocation,
Enforcement: &openrtb_ext.PriceFloorEnforcement{
EnforcePBS: ptrutil.ToPtr(true),
},
},
},
},
},
logInfo: false,
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":[{"pn":"pubmatic","bc":"pubmatic","kgpv":"","kgpsv":"","psz":"0x0","af":"","eg":0,"en":0,"l1":0,"l2":0,"t":0,"wb":0,"bidid":"bid-id-1","origbidid":"bid-id-1","di":"-1","dc":"","db":0,"ss":1,"mi":0,"ocpm":0,"ocry":"USD","fv":10.1,"frv":10.1}]}],"dvc":{},"fmv":"model-version","fsrc":2,"ft":1,"ffs":2,"fp":"provider1"}&pubid=5890`,
header: http.Header{
models.USER_AGENT_HEADER: []string{""},
models.IP_HEADER: []string{""},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -4425,3 +4498,133 @@ func TestSlotRecordsInGetLogAuctionObjectAsURL(t *testing.T) {
})
}
}

func Test_getFloorValueFromUpdatedRequest(t *testing.T) {
type args struct {
reqWrapper *openrtb_ext.RequestWrapper
rCtx *models.RequestCtx
}
tests := []struct {
name string
args args
want *models.RequestCtx
}{
{
name: "No floor present in request and in rctx",
args: args{
reqWrapper: &openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
ID: "imp_1",
TagID: "tagid_1",
},
},
},
},
rCtx: &models.RequestCtx{
PubID: 5890,
Endpoint: models.EndpointV25,
ImpBidCtx: map[string]models.ImpCtx{
"imp_1": {
AdUnitName: "tagid_1",
},
},
},
},
want: &models.RequestCtx{
PubID: 5890,
Endpoint: models.EndpointV25,
ImpBidCtx: map[string]models.ImpCtx{
"imp_1": {
AdUnitName: "tagid_1",
},
},
},
},
{
name: "No floor change in request and in rctx",
args: args{
reqWrapper: &openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
ID: "imp_1",
TagID: "tagid_1",
BidFloor: 10,
BidFloorCur: "USD",
},
},
},
},
rCtx: &models.RequestCtx{
PubID: 5890,
Endpoint: models.EndpointV25,
ImpBidCtx: map[string]models.ImpCtx{
"imp_1": {
AdUnitName: "tagid_1",
BidFloor: 10,
BidFloorCur: "USD",
},
},
},
},
want: &models.RequestCtx{
PubID: 5890,
Endpoint: models.EndpointV25,
ImpBidCtx: map[string]models.ImpCtx{
"imp_1": {
AdUnitName: "tagid_1",
BidFloor: 10,
BidFloorCur: "USD",
},
},
},
},
{
name: "floor updated in request",
args: args{
reqWrapper: &openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
ID: "imp_1",
TagID: "tagid_1",
BidFloor: 20,
BidFloorCur: "EUR",
},
},
},
},
rCtx: &models.RequestCtx{
PubID: 5890,
Endpoint: models.EndpointV25,
ImpBidCtx: map[string]models.ImpCtx{
"imp_1": {
AdUnitName: "tagid_1",
BidFloor: 10,
BidFloorCur: "USD",
},
},
},
},
want: &models.RequestCtx{
PubID: 5890,
Endpoint: models.EndpointV25,
ImpBidCtx: map[string]models.ImpCtx{
"imp_1": {
AdUnitName: "tagid_1",
BidFloor: 20,
BidFloorCur: "EUR",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
getFloorValueFromUpdatedRequest(tt.args.reqWrapper, tt.args.rCtx)
assert.Equal(t, tt.want, tt.args.rCtx, tt.name)
})
}
}
2 changes: 1 addition & 1 deletion exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (e *exchange) HoldAuction(ctx context.Context, r *AuctionRequest, debugLog

var floorErrs []error
if e.priceFloorEnabled {
floorErrs = floors.EnrichWithPriceFloors(r.BidRequestWrapper, r.Account, conversions, e.priceFloorFetcher)
floorErrs = floors.EnrichWithPriceFloors(r.BidRequestWrapper, r.Account, conversions, e.priceFloorFetcher, e.me)
if floors.RequestHasFloors(r.BidRequestWrapper.BidRequest) {
// Record request count with non-zero imp.bidfloor value
e.me.RecordFloorsRequestForAccount(r.PubID)
Expand Down
3 changes: 3 additions & 0 deletions floors/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func (f *PriceFloorFetcher) Fetcher() {
func (f *PriceFloorFetcher) fetchAndValidate(config config.AccountFloorFetch) (*openrtb_ext.PriceFloorRules, int) {
floorResp, maxAge, err := f.fetchFloorRulesFromURL(config)
if floorResp == nil || err != nil {
f.metricEngine.RecordFloorStatus(config.AccountID, openrtb_ext.FetchLocation, fetchFailure)
glog.Errorf("Error while fetching floor data from URL: %s, reason : %s", config.URL, err.Error())
return nil, 0
}
Expand All @@ -244,11 +245,13 @@ func (f *PriceFloorFetcher) fetchAndValidate(config config.AccountFloorFetch) (*

var priceFloors openrtb_ext.PriceFloorRules
if err = json.Unmarshal(floorResp, &priceFloors.Data); err != nil {
f.metricEngine.RecordFloorStatus(config.AccountID, openrtb_ext.FetchLocation, unmarshalFailure)
glog.Errorf("Recieved invalid price floor json from URL: %s", config.URL)
return nil, 0
}

if err := validateRules(config, &priceFloors); err != nil {
f.metricEngine.RecordFloorStatus(config.AccountID, openrtb_ext.FetchLocation, invalidFloors)
glog.Errorf("Validation failed for floor JSON from URL: %s, reason: %s", config.URL, err.Error())
return nil, 0
}
Expand Down
26 changes: 25 additions & 1 deletion floors/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (

"github.com/alitto/pond"
"github.com/coocood/freecache"
"github.com/golang/mock/gomock"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/metrics"

metricsConf "github.com/prebid/prebid-server/v2/metrics/config"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/ptrutil"
Expand Down Expand Up @@ -628,6 +630,11 @@ func TestFetchFloorRulesFromURLInvalidMaxAge(t *testing.T) {
}

func TestFetchAndValidate(t *testing.T) {

ctrl := gomock.NewController(t)
defer ctrl.Finish()
me := &metrics.MetricsEngineMock{}

mockHandler := func(mockResponse []byte, mockStatus int) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Add(MaxAge, "30")
Expand All @@ -646,6 +653,7 @@ func TestFetchAndValidate(t *testing.T) {
responseStatus int
want *openrtb_ext.PriceFloorRules
want1 int
setup func()
}{
{
name: "Recieved valid price floor rules response",
Expand Down Expand Up @@ -676,6 +684,7 @@ func TestFetchAndValidate(t *testing.T) {
name: "No response from server",
args: args{
configs: config.AccountFloorFetch{
AccountID: "5890",
Enabled: true,
Timeout: 30,
MaxFileSizeKB: 700,
Expand All @@ -688,6 +697,9 @@ func TestFetchAndValidate(t *testing.T) {
responseStatus: 500,
want: nil,
want1: 0,
setup: func() {
me.On("RecordFloorStatus", "5890", "fetch", "1").Return()
},
},
{
name: "File is greater than MaxFileSize",
Expand All @@ -713,6 +725,7 @@ func TestFetchAndValidate(t *testing.T) {
name: "Malformed response : json unmarshalling failed",
args: args{
configs: config.AccountFloorFetch{
AccountID: "5890",
Enabled: true,
Timeout: 30,
MaxFileSizeKB: 800,
Expand All @@ -728,11 +741,15 @@ func TestFetchAndValidate(t *testing.T) {
responseStatus: 200,
want: nil,
want1: 0,
setup: func() {
me.On("RecordFloorStatus", "5890", "fetch", "2").Return()
},
},
{
name: "Validations failed for price floor rules response",
args: args{
configs: config.AccountFloorFetch{
AccountID: "5890",
Enabled: true,
Timeout: 30,
MaxFileSizeKB: 700,
Expand All @@ -748,14 +765,21 @@ func TestFetchAndValidate(t *testing.T) {
responseStatus: 200,
want: nil,
want1: 0,
setup: func() {
me.On("RecordFloorStatus", "5890", "fetch", "3").Return()
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.setup != nil {
tt.setup()
}
mockHttpServer := httptest.NewServer(mockHandler(tt.response, tt.responseStatus))
defer mockHttpServer.Close()
ppf := PriceFloorFetcher{
httpClient: mockHttpServer.Client(),
httpClient: mockHttpServer.Client(),
metricEngine: &metricsConf.NilMetricsEngine{},
}
tt.args.configs.URL = mockHttpServer.URL
got, got1 := ppf.fetchAndValidate(tt.args.configs)
Expand Down
Loading

0 comments on commit f5ffba7

Please sign in to comment.