Skip to content

Commit

Permalink
Refactor Disabled Bidders List (#2993)
Browse files Browse the repository at this point in the history
* Refactor Disabled Bidders

* Simplified
  • Loading branch information
SyntaxNode authored Aug 3, 2023
1 parent 39166d3 commit dda9230
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 66 deletions.
2 changes: 1 addition & 1 deletion endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ func doBadAliasRequest(t *testing.T, filename string, expectMsg string) {
bidderInfos := getBidderInfos(nil, openrtb_ext.CoreBidderNames())

bidderMap := exchange.GetActiveBidders(bidderInfos)
disabledBidders := exchange.GetDisabledBiddersErrorMessages(bidderInfos)
disabledBidders := exchange.GetDisabledBidderWarningMessages(bidderInfos)

// NewMetrics() will create a new go_metrics MetricsEngine, bypassing the need for a crafted configuration set to support it.
// As a side effect this gives us some coverage of the go_metrics piece of the metrics engine.
Expand Down
2 changes: 1 addition & 1 deletion endpoints/openrtb2/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ func buildTestEndpoint(test testCase, cfg *config.Configuration) (httprouter.Han

bidderInfos := getBidderInfos(test.Config.DisabledAdapters, openrtb_ext.CoreBidderNames())
bidderMap := exchange.GetActiveBidders(bidderInfos)
disabledBidders := exchange.GetDisabledBiddersErrorMessages(bidderInfos)
disabledBidders := exchange.GetDisabledBidderWarningMessages(bidderInfos)
met := &metricsConfig.NilMetricsEngine{}
mockFetcher := empty_fetcher.EmptyFetcher{}

Expand Down
11 changes: 8 additions & 3 deletions exchange/adapter_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ func GetActiveBidders(infos config.BidderInfos) map[string]openrtb_ext.BidderNam
return activeBidders
}

// GetDisabledBiddersErrorMessages returns a map of error messages for disabled bidders.
func GetDisabledBiddersErrorMessages(infos config.BidderInfos) map[string]string {
disabledBidders := map[string]string{
func GetDisabledBidderWarningMessages(infos config.BidderInfos) map[string]string {
removed := map[string]string{
"lifestreet": `Bidder "lifestreet" is no longer available in Prebid Server. Please update your configuration.`,
"adagio": `Bidder "adagio" is no longer available in Prebid Server. Please update your configuration.`,
"somoaudience": `Bidder "somoaudience" is no longer available in Prebid Server. Please update your configuration.`,
Expand All @@ -100,6 +99,12 @@ func GetDisabledBiddersErrorMessages(infos config.BidderInfos) map[string]string
"brightroll": `Bidder "brightroll" is no longer available in Prebid Server. Please update your configuration.`,
}

return mergeRemovedAndDisabledBidderWarningMessages(removed, infos)
}

func mergeRemovedAndDisabledBidderWarningMessages(removed map[string]string, infos config.BidderInfos) map[string]string {
disabledBidders := removed

for name, info := range infos {
if info.Disabled {
msg := fmt.Sprintf(`Bidder "%s" has been disabled on this instance of Prebid Server. Please work with the PBS host to enable this bidder again.`, name)
Expand Down
113 changes: 53 additions & 60 deletions exchange/adapter_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
metrics "github.com/prebid/prebid-server/metrics/config"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var (
Expand Down Expand Up @@ -204,79 +205,71 @@ func TestGetActiveBidders(t *testing.T) {
}
}

func TestGetDisabledBiddersErrorMessages(t *testing.T) {
func TestGetDisabledBidderWarningMessages(t *testing.T) {
t.Run("removed", func(t *testing.T) {
result := GetDisabledBidderWarningMessages(nil)

// test proper construction by verifying one expected bidder is in the list
require.Contains(t, result, "groupm")
assert.Equal(t, result["groupm"], `Bidder "groupm" is no longer available in Prebid Server. Please update your configuration.`)
})

t.Run("removed-and-disabled", func(t *testing.T) {
result := GetDisabledBidderWarningMessages(map[string]config.BidderInfo{"bidderA": infoDisabled})

// test proper construction by verifying one expected bidder is in the list with the disabled bidder
require.Contains(t, result, "groupm")
assert.Equal(t, result["groupm"], `Bidder "groupm" is no longer available in Prebid Server. Please update your configuration.`)

require.Contains(t, result, "bidderA")
assert.Equal(t, result["bidderA"], `Bidder "bidderA" has been disabled on this instance of Prebid Server. Please work with the PBS host to enable this bidder again.`)
})
}

func TestMergeRemovedAndDisabledBidderWarningMessages(t *testing.T) {
testCases := []struct {
description string
bidderInfos map[string]config.BidderInfo
expected map[string]string
name string
givenRemoved map[string]string
givenBidderInfos map[string]config.BidderInfo
expected map[string]string
}{
{
description: "None",
bidderInfos: map[string]config.BidderInfo{},
expected: map[string]string{
"lifestreet": `Bidder "lifestreet" is no longer available in Prebid Server. Please update your configuration.`,
"adagio": `Bidder "adagio" is no longer available in Prebid Server. Please update your configuration.`,
"somoaudience": `Bidder "somoaudience" is no longer available in Prebid Server. Please update your configuration.`,
"yssp": `Bidder "yssp" is no longer available in Prebid Server. If you're looking to use the Yahoo SSP adapter, please rename it to "yahooAds" in your configuration.`,
"andbeyondmedia": `Bidder "andbeyondmedia" is no longer available in Prebid Server. If you're looking to use the AndBeyond.Media SSP adapter, please rename it to "beyondmedia" in your configuration.`,
"oftmedia": `Bidder "oftmedia" is no longer available in Prebid Server. Please update your configuration.`,
"groupm": `Bidder "groupm" is no longer available in Prebid Server. Please update your configuration.`,
"verizonmedia": `Bidder "verizonmedia" is no longer available in Prebid Server. Please update your configuration.`,
"brightroll": `Bidder "brightroll" is no longer available in Prebid Server. Please update your configuration.`,
},
name: "none",
givenRemoved: map[string]string{},
givenBidderInfos: map[string]config.BidderInfo{},
expected: map[string]string{},
},
{
description: "Enabled",
bidderInfos: map[string]config.BidderInfo{"appnexus": infoEnabled},
expected: map[string]string{
"lifestreet": `Bidder "lifestreet" is no longer available in Prebid Server. Please update your configuration.`,
"adagio": `Bidder "adagio" is no longer available in Prebid Server. Please update your configuration.`,
"somoaudience": `Bidder "somoaudience" is no longer available in Prebid Server. Please update your configuration.`,
"yssp": `Bidder "yssp" is no longer available in Prebid Server. If you're looking to use the Yahoo SSP adapter, please rename it to "yahooAds" in your configuration.`,
"andbeyondmedia": `Bidder "andbeyondmedia" is no longer available in Prebid Server. If you're looking to use the AndBeyond.Media SSP adapter, please rename it to "beyondmedia" in your configuration.`,
"oftmedia": `Bidder "oftmedia" is no longer available in Prebid Server. Please update your configuration.`,
"groupm": `Bidder "groupm" is no longer available in Prebid Server. Please update your configuration.`,
"verizonmedia": `Bidder "verizonmedia" is no longer available in Prebid Server. Please update your configuration.`,
"brightroll": `Bidder "brightroll" is no longer available in Prebid Server. Please update your configuration.`,
},
name: "removed",
givenRemoved: map[string]string{"bidderA": `Bidder A Message`},
givenBidderInfos: map[string]config.BidderInfo{},
expected: map[string]string{"bidderA": `Bidder A Message`},
},
{
description: "Disabled",
bidderInfos: map[string]config.BidderInfo{"appnexus": infoDisabled},
expected: map[string]string{
"lifestreet": `Bidder "lifestreet" is no longer available in Prebid Server. Please update your configuration.`,
"adagio": `Bidder "adagio" is no longer available in Prebid Server. Please update your configuration.`,
"somoaudience": `Bidder "somoaudience" is no longer available in Prebid Server. Please update your configuration.`,
"yssp": `Bidder "yssp" is no longer available in Prebid Server. If you're looking to use the Yahoo SSP adapter, please rename it to "yahooAds" in your configuration.`,
"appnexus": `Bidder "appnexus" has been disabled on this instance of Prebid Server. Please work with the PBS host to enable this bidder again.`,
"andbeyondmedia": `Bidder "andbeyondmedia" is no longer available in Prebid Server. If you're looking to use the AndBeyond.Media SSP adapter, please rename it to "beyondmedia" in your configuration.`,
"oftmedia": `Bidder "oftmedia" is no longer available in Prebid Server. Please update your configuration.`,
"groupm": `Bidder "groupm" is no longer available in Prebid Server. Please update your configuration.`,
"verizonmedia": `Bidder "verizonmedia" is no longer available in Prebid Server. Please update your configuration.`,
"brightroll": `Bidder "brightroll" is no longer available in Prebid Server. Please update your configuration.`,
},
name: "enabled",
givenRemoved: map[string]string{},
givenBidderInfos: map[string]config.BidderInfo{"bidderA": infoEnabled},
expected: map[string]string{},
},
{
description: "Mixed",
bidderInfos: map[string]config.BidderInfo{"appnexus": infoDisabled, "openx": infoEnabled},
expected: map[string]string{
"lifestreet": `Bidder "lifestreet" is no longer available in Prebid Server. Please update your configuration.`,
"adagio": `Bidder "adagio" is no longer available in Prebid Server. Please update your configuration.`,
"somoaudience": `Bidder "somoaudience" is no longer available in Prebid Server. Please update your configuration.`,
"yssp": `Bidder "yssp" is no longer available in Prebid Server. If you're looking to use the Yahoo SSP adapter, please rename it to "yahooAds" in your configuration.`,
"appnexus": `Bidder "appnexus" has been disabled on this instance of Prebid Server. Please work with the PBS host to enable this bidder again.`,
"andbeyondmedia": `Bidder "andbeyondmedia" is no longer available in Prebid Server. If you're looking to use the AndBeyond.Media SSP adapter, please rename it to "beyondmedia" in your configuration.`,
"oftmedia": `Bidder "oftmedia" is no longer available in Prebid Server. Please update your configuration.`,
"groupm": `Bidder "groupm" is no longer available in Prebid Server. Please update your configuration.`,
"verizonmedia": `Bidder "verizonmedia" is no longer available in Prebid Server. Please update your configuration.`,
"brightroll": `Bidder "brightroll" is no longer available in Prebid Server. Please update your configuration.`,
},
name: "disabled",
givenRemoved: map[string]string{},
givenBidderInfos: map[string]config.BidderInfo{"bidderA": infoDisabled},
expected: map[string]string{"bidderA": `Bidder "bidderA" has been disabled on this instance of Prebid Server. Please work with the PBS host to enable this bidder again.`},
},
{
name: "mixed",
givenRemoved: map[string]string{"bidderA": `Bidder A Message`},
givenBidderInfos: map[string]config.BidderInfo{"bidderB": infoEnabled, "bidderC": infoDisabled},
expected: map[string]string{"bidderA": `Bidder A Message`, "bidderC": `Bidder "bidderC" has been disabled on this instance of Prebid Server. Please work with the PBS host to enable this bidder again.`},
},
}

for _, test := range testCases {
result := GetDisabledBiddersErrorMessages(test.bidderInfos)
assert.Equal(t, test.expected, result, test.description)
t.Run(test.name, func(t *testing.T) {
result := mergeRemovedAndDisabledBidderWarningMessages(test.givenRemoved, test.givenBidderInfos)
assert.Equal(t, test.expected, result, test.name)
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func New(cfg *config.Configuration, rateConvertor *currency.RateConverter) (r *R
}

activeBidders := exchange.GetActiveBidders(cfg.BidderInfos)
disabledBidders := exchange.GetDisabledBiddersErrorMessages(cfg.BidderInfos)
disabledBidders := exchange.GetDisabledBidderWarningMessages(cfg.BidderInfos)

defaultAliases, defReqJSON := readDefaultRequest(cfg.DefReqConfig)
if err := validateDefaultAliases(defaultAliases); err != nil {
Expand Down

0 comments on commit dda9230

Please sign in to comment.