Skip to content

Commit

Permalink
Removing geodb from request context
Browse files Browse the repository at this point in the history
  • Loading branch information
Pubmatic-Dhruv-Sonone committed May 22, 2024
1 parent 9ba901e commit 87dcd4f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
1 change: 0 additions & 1 deletion modules/pubmatic/openwrap/entrypointhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func (m OpenWrap) handleEntrypointHook(
}
return 0, err
},
GeoInfoFetcher: m.geoInfoFetcher,
}

// only http.ErrNoCookie is returned, we can ignore it
Expand Down
2 changes: 0 additions & 2 deletions modules/pubmatic/openwrap/models/openwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/openrtb/v20/openrtb3"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/geodb"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/metrics"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/adunitconfig"
"github.com/prebid/prebid-server/v2/openrtb_ext"
Expand Down Expand Up @@ -106,7 +105,6 @@ type RequestCtx struct {
AppLovinMax AppLovinMax
LoggerDisabled bool
TrackerDisabled bool
GeoInfoFetcher geodb.Geography
}

type OwBid struct {
Expand Down
16 changes: 8 additions & 8 deletions modules/pubmatic/openwrap/traffic_shapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func (m OpenWrap) getFilteredBidders(rCtx models.RequestCtx, bidRequest *openrtb2.BidRequest) (map[string]struct{}, bool) {
filteredBidders := map[string]struct{}{}
data := generateEvaluationData(rCtx, bidRequest, m.geoInfoFetcher)
data := m.generateEvaluationData(rCtx, bidRequest, m.geoInfoFetcher)
allPartnersFilteredFlag := true
for _, partnerConfig := range rCtx.PartnerConfigMap {
if partnerConfig[models.SERVER_SIDE_FLAG] != "1" {
Expand All @@ -37,22 +37,22 @@ func (m OpenWrap) getFilteredBidders(rCtx models.RequestCtx, bidRequest *openrtb
return filteredBidders, allPartnersFilteredFlag
}

func generateEvaluationData(rCtx models.RequestCtx, bidRequest *openrtb2.BidRequest, gif geodb.Geography) string {
func (m OpenWrap) generateEvaluationData(rCtx models.RequestCtx, bidRequest *openrtb2.BidRequest, gif geodb.Geography) string {
builder := &strings.Builder{}
builder.WriteString("{")
country := getCountryFromRequest(rCtx, gif, bidRequest)
country := m.getCountryFromRequest(rCtx, bidRequest)
builder.WriteString(fmt.Sprintf(`"country":"%s"`, country))
builder.WriteString("}")
return builder.String()
}

func getCountryFromRequest(rctx models.RequestCtx, gif geodb.Geography, bidRequest *openrtb2.BidRequest) string {
func (m OpenWrap) getCountryFromRequest(rctx models.RequestCtx, bidRequest *openrtb2.BidRequest) string {
if len(rctx.Country) > 0 {
return rctx.Country
}

if rctx.IP != "" {
country, err := getCountryFromIP(gif, rctx.IP)
country, err := m.getCountryFromIP(rctx.IP)
if err == nil {
return country
}
Expand All @@ -70,11 +70,11 @@ func evaluateBiddingCondition(data, rules string) bool {
return strings.TrimSpace(result.String()) == "true"
}

func getCountryFromIP(geoInfoFetcher geodb.Geography, ip string) (string, error) {
if geoInfoFetcher == nil {
func (m OpenWrap) getCountryFromIP(ip string) (string, error) {
if m.geoInfoFetcher == nil {
return "", errors.New("geoDB instance is missing")
}
geoData, err := geoInfoFetcher.LookUp(ip)
geoData, err := m.geoInfoFetcher.LookUp(ip)
if err != nil {
return "", err
}
Expand Down
10 changes: 8 additions & 2 deletions modules/pubmatic/openwrap/traffic_shapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,11 @@ func TestGetCountryFromRequest(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := OpenWrap{
geoInfoFetcher: mockGeoDb,
}
tt.setup()
got := getCountryFromRequest(tt.args.rCtx, mockGeoDb, tt.args.bidRequest)
got := m.getCountryFromRequest(tt.args.rCtx, tt.args.bidRequest)
assert.Equal(t, got, tt.want)
})
}
Expand Down Expand Up @@ -348,7 +351,10 @@ func TestGetCountryFromIP(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.setup()
got, err := getCountryFromIP(tt.args.geoInfoFetcher, tt.args.ip)
m := OpenWrap{
geoInfoFetcher: tt.args.geoInfoFetcher,
}
got, err := m.getCountryFromIP(tt.args.ip)
assert.Equal(t, got, tt.want)
assert.Equal(t, err, tt.err)

Expand Down

0 comments on commit 87dcd4f

Please sign in to comment.