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

Core: ORTB video params validation (work on dupe) #11970

Merged

Conversation

osazos
Copy link
Collaborator

@osazos osazos commented Jul 12, 2024

Type of change

  • Feature
  • Refactoring (no functional changes, no api changes)

Description of change

This is part of the work currently done to remove dupe code and any feedback would be appreciated.

The PR

  • add a core helper function to validate (and remove if necessary) ORTB Video fields
  • use it during the validateVideoMediaType() call to ensure only valid params are passed along the auction
  • use it for the Adagio Bid Adapter in order to remove some duplicated code

It could be a starting point to address the following point:
There are a lot of adapters that use the pretty same logic which is to get the video params from an adUnit (at mediaTypes and/or bids{}.params level) ensure they are matching the Ortb spec and remove them if not during the buildRequests() function.
Note this PR is not dedicated to fix all of them, just to try to introduce a common way for now.

Copy link

Whoa there, partner! 🌵🤠 We wrangled some duplicated code in your PR:

Reducing code duplication by importing common functions from a library not only makes our code cleaner but also easier to maintain. Please move the common code from both files into a library and import it in each. We hate that we have to mention this, however, commits designed to hide from this utility by renaming variables or reordering an object are poor conduct. We will not look upon them kindly! Keep up the great work! 🚀

@osazos osazos force-pushed the chore/dupe/ortb-video-params-validation-bis branch from 4bb7799 to 545e5dc Compare July 15, 2024 12:21
Copy link

Whoa there, partner! 🌵🤠 We wrangled some duplicated code in your PR:

Reducing code duplication by importing common functions from a library not only makes our code cleaner but also easier to maintain. Please move the common code from both files into a library and import it in each. We hate that we have to mention this, however, commits designed to hide from this utility by renaming variables or reordering an object are poor conduct. We will not look upon them kindly! Keep up the great work! 🚀

@osazos osazos force-pushed the chore/dupe/ortb-video-params-validation-bis branch from 545e5dc to 335f25f Compare July 17, 2024 14:20
Copy link

Whoa there, partner! 🌵🤠 We wrangled some duplicated code in your PR:

Reducing code duplication by importing common functions from a library not only makes our code cleaner but also easier to maintain. Please move the common code from both files into a library and import it in each. We hate that we have to mention this, however, commits designed to hide from this utility by renaming variables or reordering an object are poor conduct. We will not look upon them kindly! Keep up the great work! 🚀

@patmmccann
Copy link
Collaborator

patmmccann commented Jul 23, 2024

Exciting, many more opportunities to import are out there I imagine, eg

const VIDEO_CUSTOM_PARAMS = {

@patmmccann
Copy link
Collaborator

And

if (skipmin && utils.isInteger(skipmin)) {

* Not included: `companionad`, `durfloors`, `ext`
* reference: https://github.com/InteractiveAdvertisingBureau/openrtb2.x/blob/main/2.6.md
*/
export const ORTB_VIDEO_PARAMS = new Map([
Copy link
Collaborator

@patmmccann patmmccann Jul 23, 2024

Choose a reason for hiding this comment

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

While this feels like a lot to add to core, so many prominent bid adapters do exactly this that it would likely be a net code reduction, very exciting

@patmmccann patmmccann requested review from pm-harshad-mane and dgirardi and removed request for pm-harshad-mane July 23, 2024 12:22
@patmmccann patmmccann changed the title Chore: ORTB video params validation (work on dupe) Core: ORTB video params validation (work on dupe) Jul 23, 2024
src/video.js Outdated
*/
export const ORTB_VIDEO_PARAMS = new Map([
[ 'mimes', { validate: (value) => Array.isArray(value) && value.length > 0 && value.every(v => typeof v === 'string') } ],
[ 'minduration', { validate: (value) => isInteger(value) } ],
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could be more compact ('minduration' -> isInteger, 'podid' -> isStr, etc). Are you envisioning it to contain more?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The idea was to make a map that was not a strict "validation map", it is easier to plug-in something else later, but honestly I don't know how to extend it right now. Tell me if you prefer I use the "compact" way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think compact is better because in terms of bundle size, N maps are still smaller than a map where each node has N things in it.

src/video.js Outdated
const valid = ORTB_VIDEO_PARAMS.get(key).validate(value);
if (!valid) {
delete videoParams[key];
logWarn(`Invalid value for mediaTypes.video.${key} ORTB property. The property has been removed.`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this enough info to track down the issue - should we log the offending adUnit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This way, I should update the function to validateOrtbVideoFields(adUnit); would it sound better?

In 1st attempt I would like to keep the function scoped on the videoParams object, but perhaps it makes no sense.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I tend to agree that the scope should be as small as possible, but I'm not sure code aesthetics will convince someone with a complicated setup and a bunch of cryptic warning messages :)

You could also do something like validateOrtbVideoFields(videoParams, onInvalidParam) to keep the scope limited, but let something else that has the adUnit do the logging.

Copy link

Whoa there, partner! 🌵🤠 We wrangled some duplicated code in your PR:

Reducing code duplication by importing common functions from a library not only makes our code cleaner but also easier to maintain. Please move the common code from both files into a library and import it in each. We hate that we have to mention this, however, commits designed to hide from this utility by renaming variables or reordering an object are poor conduct. We will not look upon them kindly! Keep up the great work! 🚀

@patmmccann patmmccann merged commit 6b2b59e into prebid:master Jul 25, 2024
4 of 6 checks passed
@osazos osazos deleted the chore/dupe/ortb-video-params-validation-bis branch August 28, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants