-
Notifications
You must be signed in to change notification settings - Fork 748
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
Introduced FetchRate field to select source of floors from request or dynamically fetched #3380
Changes from 3 commits
7ac2216
161b0a8
e0593e3
a394f69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import ( | |
"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" | ||
"github.com/prebid/prebid-server/v2/util/timeutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
@@ -396,6 +397,32 @@ func TestValidatePriceFloorRules(t *testing.T) { | |
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Invalid useFetchDataRate", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: Can you update the name here to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
args: args{ | ||
configs: config.AccountFloorFetch{ | ||
Enabled: true, | ||
URL: testURL, | ||
Timeout: 5, | ||
MaxFileSizeKB: 20, | ||
MaxRules: 1, | ||
MaxAge: 20, | ||
Period: 10, | ||
}, | ||
priceFloors: &openrtb_ext.PriceFloorRules{ | ||
Data: &openrtb_ext.PriceFloorData{ | ||
SkipRate: 10, | ||
ModelGroups: []openrtb_ext.PriceFloorModelGroup{{ | ||
Values: map[string]float64{ | ||
"*|*|www.website.com": 15.01, | ||
}, | ||
}}, | ||
FetchRate: ptrutil.ToPtr(-11), | ||
}, | ||
}, | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ const ( | |
enforceRateMin int = 0 | ||
enforceRateMax int = 100 | ||
floorPrecision float64 = 0.01 | ||
dataRateMin int = 0 | ||
dataRateMax int = 100 | ||
) | ||
|
||
// EnrichWithPriceFloors checks for floors enabled in account and request and selects floors data from dynamic fetched if present | ||
|
@@ -136,24 +138,35 @@ func isPriceFloorsEnabledForRequest(bidRequestWrapper *openrtb_ext.RequestWrappe | |
return true | ||
} | ||
|
||
// useFetchedData will check if to use fetched data or request data | ||
func useFetchedData(rate *int) bool { | ||
if rate == nil { | ||
return true | ||
} | ||
randomNumber := rand.Intn(dataRateMax) | ||
return randomNumber < *rate | ||
} | ||
|
||
// resolveFloors does selection of floors fields from request data and dynamic fetched data if dynamic fetch is enabled | ||
func resolveFloors(account config.Account, bidRequestWrapper *openrtb_ext.RequestWrapper, conversions currency.Conversions, priceFloorFetcher FloorFetcher) (*openrtb_ext.PriceFloorRules, []error) { | ||
var errList []error | ||
var floorRules *openrtb_ext.PriceFloorRules | ||
var ( | ||
errList []error | ||
floorRules *openrtb_ext.PriceFloorRules | ||
fetchResult *openrtb_ext.PriceFloorRules | ||
fetchStatus string | ||
) | ||
|
||
reqFloor := extractFloorsFromRequest(bidRequestWrapper) | ||
if reqFloor != nil && reqFloor.Location != nil && len(reqFloor.Location.URL) > 0 { | ||
account.PriceFloors.Fetcher.URL = reqFloor.Location.URL | ||
} | ||
account.PriceFloors.Fetcher.AccountID = account.ID | ||
|
||
var fetchResult *openrtb_ext.PriceFloorRules | ||
var fetchStatus string | ||
if priceFloorFetcher != nil && account.PriceFloors.UseDynamicData { | ||
fetchResult, fetchStatus = priceFloorFetcher.Fetch(account.PriceFloors) | ||
} | ||
|
||
if fetchResult != nil && fetchStatus == openrtb_ext.FetchSuccess { | ||
if fetchResult != nil && fetchStatus == openrtb_ext.FetchSuccess && useFetchedData(fetchResult.Data.FetchRate) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: Although the
I guess to prevent panics in case the code changes in the future. Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case of fetchStatus == openrtb_ext.FetchSuccess, fetchResult.Data can not be nil [https://github.com/prebid/prebid-server/blob/498955bcd5c242866a9b05886ac4e703cc850b2f/floors/fetcher.go#L140], so no need to add redundant check. |
||
mergedFloor := mergeFloors(reqFloor, fetchResult, conversions) | ||
floorRules, errList = createFloorsFrom(mergedFloor, account, fetchStatus, openrtb_ext.FetchLocation) | ||
} else if reqFloor != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: In case the value of the
dataRateMin
anddataRateMax
constants changes someday, should we use their values in the error message instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very less chance of constant getting changed as these are % based values which will have range 0 to 100 always.