-
Notifications
You must be signed in to change notification settings - Fork 187
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
Greenbids: Add account level config for modules RTD, analytics #3596
base: master
Are you sure you want to change the base?
Greenbids: Add account level config for modules RTD, analytics #3596
Conversation
private Partner parseAccountConfig(AuctionContext auctionContext) { | ||
final Map<String, ObjectNode> modules = Optional.ofNullable(auctionContext) | ||
.map(AuctionContext::getAccount) | ||
.map(Account::getHooks) | ||
.map(AccountHooksConfiguration::getModules) | ||
.orElse(null); | ||
} | ||
|
||
private boolean isNotEmptyObjectNode(JsonNode analytics) { | ||
return analytics != null && analytics.isObject() && !analytics.isEmpty(); | ||
Partner partner = null; | ||
if (modules != null && modules.containsKey("greenbids")) { | ||
final ObjectNode moduleConfig = modules.get("greenbids"); | ||
partner = toPartner(moduleConfig); | ||
} | ||
|
||
return partner; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can skip this parsing, and just call toPartner(invocationContext.accountConfig())
and you'll get what you need (of course some null checks and json parsing exception should be handled)
also if the Partner is considered to be a representation of the account config, I suggest rename it to the Config or GreenbidsConfig (something like that)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified to
private GreenbidsConfig parseAccountConfig(Account account) {
return Optional.ofNullable(account)
.map(Account::getHooks)
.map(AccountHooksConfiguration::getModules)
.map(modules -> modules.get(name()))
.map(this::toGreenbidsConfig)
.orElse(null);
}
private GreenbidsConfig toGreenbidsConfig(ObjectNode adapterNode) {
try {
return mapper.treeToValue(adapterNode, GreenbidsConfig.class);
} catch (JsonProcessingException e) {
return null;
}
}
The NPE is handled by the optional chain and JsonProcessingException is handled in toGreenbidsConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You haven't followed my suggestion. The idea of the account config is that the module has it already as the invocationContext.accountConfig()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...c/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/model/data/Partner.java
Outdated
Show resolved
Hide resolved
src/main/java/org/prebid/server/analytics/reporter/greenbids/GreenbidsAnalyticsReporter.java
Outdated
Show resolved
Hide resolved
Depends on PR: #3596 |
@EvgeniiMunin fix was merged, this PR should be unlocked |
9216dfd
to
f155ee3
Compare
final int hashInt = Integer.parseInt( | ||
greenbidsId.substring(greenbidsId.length() - 4), 16); | ||
return hashInt < partner.getExplorationRate() * RANGE_16_BIT_INTEGER_DIVISION_BASIS; | ||
return hashInt < greenbidsConfig.getExplorationRate() * RANGE_16_BIT_INTEGER_DIVISION_BASIS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as I can see it's never checked that properties of configs are required or can't be null, so this is a NPE potentially
check other properties as well and handle them if it's necessary
final GreenbidsConfig greenbidsConfig = Optional.ofNullable(parseBidRequestExt(auctionContext)) | ||
.orElse(parseAccountConfig(auctionContext.getAccount())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the execution shouldn't proceed of the config is null
yes, it shouldn't be the problem if the account config is required to invoke the module, but I guess it's still better to return the failed future in the null case
@@ -131,7 +134,7 @@ public <T> Future<Void> processEvent(T event) { | |||
|
|||
final String greenbidsId = greenbidsId(analyticsResultFromAnalyticsTag); | |||
|
|||
if (!isSampled(greenbidsBidRequestExt.getGreenbidsSampling(), greenbidsId)) { | |||
if (!isSampled(greenbidsConfig.getGreenbidsSampling(), greenbidsId)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure the nullable properties won't cause NPE if they're underconfigured
🔧 Type of changes
✨ What's the context?
As discussed with @bretg and @jbogp we need to add extraction of modules params from account level config for both RTD module and analytics reporter. At the same time if the params are defined in
BidRequestExt
it should take precedent before account level config. This makes modules integration more publisher friendly🧠 Rationale behind the change
account/id
identifies account for specific publisher -> so if we define a config for a specific account it means it should correspond to the unique publisher id = pbuid.Setup of
default-account-config
for Greenbids example inprebid-config-with-module.yaml
should look like thisThe modules can extract fields of Account class from AuctionContext at hook call (not on spring boot)
Then depending on the calling module we get analytics or RTD
Map[String, ObjectNode] modules
and parse it from json.🔎 New Bid Adapter Checklist
🧪 Test plan
I have introduced a specific test case in Greenbids analytics reporter test to fallback to account level config if bid request ext config is not defined:
shouldReceiveValidResponseAndFallbackToAccountLevelConfigWhenPartnerNotActivatedInBidRequest
For RTD module have modified the existing test case when partner not activated on bid request ext -> then fallback to account level config and proceed with the filtering
callShouldFilterBiddersAndFallbackToAccountLevelConfigWhenPartnerNotActivatedInBidRequest
🏎 Quality check