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

Introduced FetchRate field to select source of floors from request or dynamically fetched #3380

Merged
merged 4 commits into from
Jan 29, 2024

Conversation

pm-jaydeep-mohite
Copy link
Contributor

@pm-jaydeep-mohite pm-jaydeep-mohite commented Jan 2, 2024

Changes proposed in #2755 are implemented in this PR

@pm-jaydeep-mohite pm-jaydeep-mohite changed the title Introduced UseFetchDataRate field to select source of floors from request or dynamic fetched Introduced UseFetchDataRate field to select source of floors from request or dynamically fetched Jan 2, 2024
@bsardo bsardo assigned bsardo, guscarreon and AlexBVolcy and unassigned bsardo Jan 2, 2024
Copy link
Contributor

@AlexBVolcy AlexBVolcy left a comment

Choose a reason for hiding this comment

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

Looks good, left minor comments.

@@ -88,6 +88,7 @@ type PriceFloorData struct {
ModelTimestamp int `json:"modeltimestamp,omitempty"`
ModelGroups []PriceFloorModelGroup `json:"modelgroups,omitempty"`
FloorProvider string `json:"floorprovider,omitempty"`
UseFetchDataRate *int `json:"usefetchdatarate,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if this can be named FetchDataRate or FetchRate instead? The current naming gives me the feeling like it's a boolean, but since it's an int, we could update the name to reflect that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to FetchRate

floors/floors.go Outdated
@@ -136,24 +138,35 @@ func isPriceFloorsEnabledForRequest(bidRequestWrapper *openrtb_ext.RequestWrappe
return true
}

// shouldUseFetchedData will check if to use fetched data or request data
func shouldUseFetchedData(rate *int) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the function name be just useFetchedData? I think it accomplishes the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@AlexBVolcy AlexBVolcy left a comment

Choose a reason for hiding this comment

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

Ready to approve, just one final comment.

@@ -396,6 +397,32 @@ func TestValidatePriceFloorRules(t *testing.T) {
},
wantErr: true,
},
{
name: "Invalid useFetchDataRate",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Can you update the name here to be Invalid FetchRate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@pm-jaydeep-mohite pm-jaydeep-mohite changed the title Introduced UseFetchDataRate field to select source of floors from request or dynamically fetched Introduced FetchRate field to select source of floors from request or dynamically fetched Jan 10, 2024
@@ -309,6 +309,10 @@ func validateRules(config config.AccountFloorFetch, priceFloors *openrtb_ext.Pri
return errors.New("skip rate should be greater than or equal to 0 and less than 100")
}

if priceFloors.Data.FetchRate != nil && (*priceFloors.Data.FetchRate < dataRateMin || *priceFloors.Data.FetchRate > dataRateMax) {
return errors.New("FetchRate should be greater than or equal to 0 and less than or equal to 100")
Copy link
Contributor

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 and dataRateMax constants changes someday, should we use their values in the error message instead?

312     if priceFloors.Data.FetchRate != nil && (*priceFloors.Data.FetchRate < dataRateMin || *priceFloors.Data.FetchRate > dataRateMax) {
313 -       return errors.New("FetchRate should be greater than or equal to 0 and less than or equal to 100")
    +       return fmt.Errorf("FetchRate should be greater than or equal to %d and less than or equal to %d", dataRateMin, dataRateMax)
314     }
315
floors/fetcher.go

Copy link
Contributor Author

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.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Although the Fetch(config config.AccountPriceFloors) implementation called in line 166 returns openrtb_ext.FetchNone when fetchResult.Data is nil, making it impossible for a nil fetchResult.Data in the third conditional in line 169, can we still add a check before dereferencing?

166         fetchResult, fetchStatus = priceFloorFetcher.Fetch(account.PriceFloors)
167     }
168
169 -   if fetchResult != nil && fetchStatus == openrtb_ext.FetchSuccess && useFetchedData(fetchResult.Data.FetchRate) {
    +   if fetchResult != nil && fetchStatus == openrtb_ext.FetchSuccess && fetchResult.Data != nil && useFetchedData(fetchResult.Data.FetchRate) {
170         mergedFloor := mergeFloors(reqFloor, fetchResult, conversions)
171         floorRules, errList = createFloorsFrom(mergedFloor, account, fetchStatus, openrtb_ext.FetchLocation)
172     } else if reqFloor != nil {
floors/floors.go

I guess to prevent panics in case the code changes in the future. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants