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

Changed FS bidder names to mixed case #2390

Merged
merged 6 commits into from
Sep 29, 2022
Merged

Conversation

VeronikaSolovei9
Copy link
Contributor

No description provided.

@VeronikaSolovei9 VeronikaSolovei9 marked this pull request as ready for review September 27, 2022 02:57
@SyntaxNode SyntaxNode self-assigned this Sep 27, 2022
@SyntaxNode SyntaxNode self-requested a review September 27, 2022 16:25
// should appear in result in lowercase
bidder := "somebidder"
// should appear in result in mixed case
bidder := "stroeerCore"
Copy link
Contributor

@SyntaxNode SyntaxNode Sep 28, 2022

Choose a reason for hiding this comment

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

For future contributors: stroeerCore was chosen at random just because we needed a real mixed case bidder name. There is no other significance to this choice. Our usual real bidder choices do not have mixed upper and lower case in their name.


}

type MockInfoReader struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Please rename to either StubInfoReader or FakeInfoReader (technically, this is a stub). Mock implies we can define expectations on the object, control the object responses, and assert expectations later.

givenFsBidderInfos: BidderInfos{"unknown": {Endpoint: "original"}},
givenConfigBidderInfos: BidderInfos{"bidderA": {Syncer: &Syncer{Key: "override"}}},
expectedError: "error setting configuration for bidder bidderA: unknown bidder",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use unique descriptions so we know which test fails from the error message.

SyntaxNode
SyntaxNode previously approved these changes Sep 28, 2022
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.

Looks pretty good. I left a couple of questions but feel like approving either way.

normalizedBidderName, bidderNameExists := normalizeBidderName(bidderName[0])
if !bidderNameExists {
return nil, fmt.Errorf("error parsing config for bidder %s: unknown bidder", fileName)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

A map check is less expensive than unmarshalling the yaml file. A small optimization would occur if we switch the order of the operations:

213   func processBidderInfos(reader InfoReader, normalizeBidderName func(string) (openrtb_ext.BidderName, bool)) (BidderInfos, error) {
214       bidderConfigs, err := reader.Read()
215       if err != nil {
216           return nil, fmt.Errorf("error loading bidders data")
217       }
218   
219       infos := BidderInfos{}
220   
221       for fileName, data := range bidderConfigs {
222 -         info := BidderInfo{}
223 -         if err := yaml.Unmarshal(data, &info); err != nil {
224 -             return nil, fmt.Errorf("error parsing config for bidder %s: %v", fileName, err)
225 -         }
226 - 
227           bidderName := strings.Split(fileName, ".")
228           if len(bidderName) == 2 && bidderName[1] == "yaml" {
229               normalizedBidderName, bidderNameExists := normalizeBidderName(bidderName[0])
230               if !bidderNameExists {
231                   return nil, fmt.Errorf("error parsing config for bidder %s: unknown bidder", fileName)
232               }
    + 
    +             info := BidderInfo{}
    +             if err := yaml.Unmarshal(data, &info); err != nil {
    +                 return nil, fmt.Errorf("error parsing config for bidder %s: %v", fileName, err)
    +             }
    + 
233               infos[string(normalizedBidderName)] = info
234           }
235       }
236       return infos, nil
config/bidderinfo.go

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like a good idea. I would like to mention this code runs once at startup so performance is not a critical concern with this flow.

@@ -59,7 +60,7 @@ const infoDirectory = "./static/bidder-info"
func loadConfig(bidderInfos config.BidderInfos) (*config.Configuration, error) {
v := viper.New()
config.SetupViper(v, configFileName, bidderInfos)
return config.New(v, bidderInfos)
return config.New(v, bidderInfos, openrtb_ext.NormalizeBidderName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to pass openrtb_ext.NormalizeBidderName from main.go all the way down to config/bidderinfo.go's applyBidderInfoConfigOverrides(...) function? I see the need for bidderInfos to be passed from main.go and also the convenience of passing a mock function to applyBidderInfoConfigOverrides(...) for testing purposes but, I'm wondering if maybe we can simplify config.New(...) by not adding that third paramenter:

619   // New uses viper to get our server configurations.
620 - func New(v *viper.Viper, bidderInfos BidderInfos) (*Configuration, error) {
    + func New(v *viper.Viper, bidderInfos BidderInfos, normalizeBidderName func(string) (openrtb_ext.BidderName, bool)) (*Configuration, error) {
621       var c Configuration
622       if err := v.Unmarshal(&c); err != nil {
623   *-- 78 lines: return nil, fmt.Errorf("viper failed to unmarshal app config: %v", err)------------------------------------
701       resolvedStoredRequestsConfig(&c)
702   
703 -     mergedBidderInfos, err := applyBidderInfoConfigOverrides(c.BidderInfos, bidderInfos, normalizeBidderName)
    +     mergedBidderInfos, err := applyBidderInfoConfigOverrides(c.BidderInfos, bidderInfos, openrtb_ext.NormalizeBidderName)
704       if err != nil {
705           return nil, err
706       }
config/config.go

Therefore we could rollback to:

60   func loadConfig(bidderInfos config.BidderInfos) (*config.Configuration, error) {
61       v := viper.New()
62       config.SetupViper(v, configFileName, bidderInfos)
63 -     return config.New(v, bidderInfos, openrtb_ext.NormalizeBidderName)
   +     return config.New(v, bidderInfos)
64   }
main.go

Unless passing it from main.go makes something happen behind the scenes that I'm missing.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is necessary for New to accept the normalize function so unit tests are free to use fake bidder names instead of being forced to use real ones. The bidder name flow will continue to evolve and in the near future the normalize func will likely no longer be required. We're focused on restoring functionality to fix the bug and will design a better solution as a follow-up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I was thinking about this too. We also need this parameter in config_test.go -> newDefaultConfig

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

@SyntaxNode SyntaxNode merged commit f3e4403 into master Sep 29, 2022
gwi-mmuths added a commit to gwinteractive/prebid-server that referenced this pull request Oct 10, 2022
* origin/master: (316 commits)
  Fix alt bidder code test broken by imp wrapper commit (prebid#2405)
  ImpWrapper (prebid#2375)
  Update sspBC adapter to v5.7 (prebid#2394)
  Change errors to warnings (prebid#2385)
  TheMediaGrid: support native mediaType (prebid#2377)
  Huaweiadsadapter gdpr (prebid#2345)
  Add alternatebiddercodes in Prebid request ext (prebid#2339)
  Changed FS bidder names to mixed case (prebid#2390)
  Load bidders names from file system in lowercase (prebid#2388)
  consumable adapter: add schain and coppa support (prebid#2361)
  Adapter aliases: moved adapter related configs to bidder.yaml files (prebid#2353)
  pubmatic adapter: add param prebiddealpriority (prebid#2281)
  Yieldlab Adapter: Add support for ad unit sizes (prebid#2364)
  GDPR: add enforce_algo config flag and convert enforce_purpose to bool (prebid#2330)
  Resolves CVE-2022-27664 (prebid#2376)
  AMP Endpoint: support parameters consentType and gdprApplies (prebid#2338)
  Dianomi - added usync for redirect (prebid#2368)
  Create issue_prioritization.yml (prebid#2372)
  Update yaml files for gzip supported bidders (prebid#2365)
  Adnuntius Adapter: Set no cookies as a parameter (prebid#2352)
  ...
shunj-nb pushed a commit to ParticleMedia/prebid-server that referenced this pull request Nov 8, 2022
@SyntaxNode SyntaxNode deleted the bidder_names_case_fix branch March 13, 2023 13:55
mobfxoHB pushed a commit to mobfxoHB/prebid-server that referenced this pull request Aug 22, 2023
* Create admaticBidAdapter.js

* Create admaticBidAdapter.md

* Update admaticBidAdapter.js

* Update admaticBidAdapter.js

* Update admaticBidAdapter.js

* Update admaticBidAdapter.js
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.

3 participants