Skip to content

Commit

Permalink
Merge pull request #573 from PubMatic-OpenWrap/ci
Browse files Browse the repository at this point in the history
Release OpenWrap_Q4_04-Oct-23
  • Loading branch information
PubMatic-OpenWrap authored Sep 28, 2023
2 parents 2e523c3 + e72a230 commit c8b1dfc
Show file tree
Hide file tree
Showing 16 changed files with 412 additions and 61 deletions.
2 changes: 1 addition & 1 deletion floors/enforce.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func enforceFloorToBids(bidRequestWrapper *openrtb_ext.RequestWrapper, seatBids
}

bidPrice := rate * bid.Bid.Price
if reqImp.BidFloor > bidPrice {
if (bidPrice + floorPrecision) < reqImp.BidFloor {
if bid.BidFloors != nil {
// Need USD for OW analytics
// TODO: Move this to better place where 'conversions' (deduced from host+request) is available
Expand Down
65 changes: 65 additions & 0 deletions floors/enforce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,71 @@ func TestEnforceFloorToBids(t *testing.T) {
},
expErrs: []error{},
},
{
name: "Bids with price less than bidfloor with floorsPrecision",
args: args{
bidRequestWrapper: func() *openrtb_ext.RequestWrapper {
bw := openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{
ID: "some-request-id",
Imp: []openrtb2.Imp{
{ID: "some-impression-id-1", BidFloor: 1, BidFloorCur: "USD"},
{ID: "some-impression-id-2", BidFloor: 2, BidFloorCur: "USD"},
},
},
}
bw.RebuildRequest()
return &bw
}(),
seatBids: map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid{
"pubmatic": {
Bids: []*entities.PbsOrtbBid{
{Bid: &openrtb2.Bid{ID: "some-bid-1", Price: 0.998, ImpID: "some-impression-id-1"}},
{Bid: &openrtb2.Bid{ID: "some-bid-2", Price: 1.5, DealID: "deal_Id", ImpID: "some-impression-id-2"}},
},
Seat: "pubmatic",
Currency: "USD",
},
"appnexus": {
Bids: []*entities.PbsOrtbBid{
{Bid: &openrtb2.Bid{ID: "some-bid-11", Price: 0.8, ImpID: "some-impression-id-1"}},
{Bid: &openrtb2.Bid{ID: "some-bid-12", Price: 2.2, ImpID: "some-impression-id-2"}},
},
Seat: "appnexus",
Currency: "USD",
},
},
conversions: currency.Conversions(convert{}),
enforceDealFloors: false,
},
expEligibleBids: map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid{
"pubmatic": {
Bids: []*entities.PbsOrtbBid{
{Bid: &openrtb2.Bid{ID: "some-bid-1", Price: 0.998, ImpID: "some-impression-id-1"}},
{Bid: &openrtb2.Bid{ID: "some-bid-2", Price: 1.5, DealID: "deal_Id", ImpID: "some-impression-id-2"}},
},
Seat: "pubmatic",
Currency: "USD",
},
"appnexus": {
Bids: []*entities.PbsOrtbBid{
{Bid: &openrtb2.Bid{ID: "some-bid-12", Price: 2.2, ImpID: "some-impression-id-2"}},
},
Seat: "appnexus",
Currency: "USD",
},
},
expRejectedBids: []*entities.PbsOrtbSeatBid{
{
Seat: "appnexus",
Currency: "USD",
Bids: []*entities.PbsOrtbBid{
{Bid: &openrtb2.Bid{ID: "some-bid-11", Price: 0.8, ImpID: "some-impression-id-1"}},
},
},
},
expErrs: []error{},
},
{
name: "Bids with different currency with enforceDealFloor true",
args: args{
Expand Down
23 changes: 12 additions & 11 deletions floors/floors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ type Price struct {
}

const (
defaultCurrency string = "USD"
defaultDelimiter string = "|"
catchAll string = "*"
skipRateMin int = 0
skipRateMax int = 100
modelWeightMax int = 100
modelWeightMin int = 1
enforceRateMin int = 0
enforceRateMax int = 100
dataRateMin int = 0
dataRateMax int = 100
defaultCurrency string = "USD"
defaultDelimiter string = "|"
catchAll string = "*"
skipRateMin int = 0
skipRateMax int = 100
modelWeightMax int = 100
modelWeightMin int = 1
enforceRateMin int = 0
enforceRateMax int = 100
dataRateMin int = 0
dataRateMax int = 100
floorPrecision float64 = 0.01
)

// EnrichWithPriceFloors checks for floors enabled in account and request and selects floors data from dynamic fetched if present
Expand Down
18 changes: 10 additions & 8 deletions modules/pubmatic/openwrap/cache/gocache/gocache.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ func key(format string, v ...interface{}) string {
// any db or cache should be injectable
type cache struct {
sync.Map
cache *gocache.Cache
cfg config.Cache
db database.Database
metricEngine metrics.MetricsEngine
cache *gocache.Cache
cfg config.Cache
db database.Database
metricEngine metrics.MetricsEngine
partnerConfigExpiry int
}

var c *cache
Expand All @@ -44,10 +45,11 @@ func New(goCache *gocache.Cache, database database.Database, cfg config.Cache, m
cOnce.Do(
func() {
c = &cache{
cache: goCache,
db: database,
cfg: cfg,
metricEngine: metricEngine,
cache: goCache,
db: database,
cfg: cfg,
metricEngine: metricEngine,
partnerConfigExpiry: cfg.CacheDefaultExpiry - 60, // Reduced partnerConfig expiry by 1 minute to avoid inconsistent exipry of partnerConfig, adUnitConfig and WrapperConfig
}
})
return c
Expand Down
10 changes: 7 additions & 3 deletions modules/pubmatic/openwrap/cache/gocache/partner_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func (c *cache) GetPartnerConfigMap(pubID, profileID, displayVersion int, endpoi
}

func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileID, displayVersion int) (err error) {
var errWrapperSlotMapping error
var errAdunitConfig error
cacheKey := key(PUB_HB_PARTNER, pubID, profileID, displayVersion)
partnerConfigMap, err := c.db.GetActivePartnerConfigurations(pubID, profileID, displayVersion)
if err != nil {
Expand All @@ -75,16 +77,15 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI
return fmt.Errorf("there are no active partners for pubId:%d, profileId:%d, displayVersion:%d", pubID, profileID, displayVersion)
}

c.cache.Set(cacheKey, partnerConfigMap, getSeconds(c.cfg.CacheDefaultExpiry))
if errWrapperSlotMapping := c.populateCacheWithWrapperSlotMappings(pubID, partnerConfigMap, profileID, displayVersion); errWrapperSlotMapping != nil {
if errWrapperSlotMapping = c.populateCacheWithWrapperSlotMappings(pubID, partnerConfigMap, profileID, displayVersion); errWrapperSlotMapping != nil {
err = errorWrap(err, errWrapperSlotMapping)
queryType := models.WrapperSlotMappingsQuery
if displayVersion == 0 {
queryType = models.WrapperLiveVersionSlotMappings
}
c.metricEngine.RecordDBQueryFailure(queryType, strconv.Itoa(pubID), strconv.Itoa(profileID))
}
if errAdunitConfig := c.populateCacheWithAdunitConfig(pubID, profileID, displayVersion); errAdunitConfig != nil {
if errAdunitConfig = c.populateCacheWithAdunitConfig(pubID, profileID, displayVersion); errAdunitConfig != nil {
queryType := models.AdunitConfigQuery
if displayVersion == 0 {
queryType = models.AdunitConfigForLiveVersion
Expand All @@ -95,5 +96,8 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI
c.metricEngine.RecordDBQueryFailure(queryType, strconv.Itoa(pubID), strconv.Itoa(profileID))
err = errorWrap(err, errAdunitConfig)
}
if errWrapperSlotMapping == nil && errAdunitConfig == nil {
c.cache.Set(cacheKey, partnerConfigMap, getSeconds(c.partnerConfigExpiry))
}
return
}
Loading

0 comments on commit c8b1dfc

Please sign in to comment.