-
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
Open
EvgeniiMunin
wants to merge
9
commits into
prebid:master
Choose a base branch
from
EvgeniiMunin:greenbids-rtd-account-level-config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+306
−188
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
84f6236
Greenbids RTD Accoung level config
EvgeniiMunin c666a67
keep account level config + bid request ext config
EvgeniiMunin ab5309c
default account config json debug + TU
EvgeniiMunin 9020f18
empty commit
EvgeniiMunin 7d8cf9e
default account config + account config from auctioncontext
EvgeniiMunin 09cc765
analytics report remove bid req config
EvgeniiMunin 3827dfa
extrequest -> accountconfig: analytics and rtd + TU
EvgeniiMunin 5247534
fix review
EvgeniiMunin f155ee3
rebase master
EvgeniiMunin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.GreenbidsInvocationService; | ||
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.OnnxModelRunner; | ||
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.OnnxModelRunnerWithThresholds; | ||
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.data.Partner; | ||
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.data.GreenbidsConfig; | ||
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.data.ThrottlingMessage; | ||
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.result.AnalyticsResult; | ||
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.result.GreenbidsInvocationResult; | ||
|
@@ -35,6 +35,8 @@ | |
import org.prebid.server.hooks.v1.auction.ProcessedAuctionRequestHook; | ||
import org.prebid.server.proto.openrtb.ext.request.ExtRequest; | ||
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid; | ||
import org.prebid.server.settings.model.Account; | ||
import org.prebid.server.settings.model.AccountHooksConfiguration; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
@@ -44,10 +46,10 @@ | |
|
||
public class GreenbidsRealTimeDataProcessedAuctionRequestHook implements ProcessedAuctionRequestHook { | ||
|
||
private static final String BID_REQUEST_ANALYTICS_EXTENSION_NAME = "greenbids-rtd"; | ||
private static final String CODE = "greenbids-real-time-data-processed-auction-request"; | ||
private static final String ACTIVITY = "greenbids-filter"; | ||
private static final String SUCCESS_STATUS = "success"; | ||
private static final String BID_REQUEST_ANALYTICS_EXTENSION_NAME = "greenbids-rtd"; | ||
|
||
private final ObjectMapper mapper; | ||
private final FilterService filterService; | ||
|
@@ -75,51 +77,57 @@ public Future<InvocationResult<AuctionRequestPayload>> call( | |
|
||
final AuctionContext auctionContext = invocationContext.auctionContext(); | ||
final BidRequest bidRequest = auctionContext.getBidRequest(); | ||
final Partner partner = parseBidRequestExt(bidRequest); | ||
|
||
if (partner == null) { | ||
return Future.succeededFuture(toInvocationResult( | ||
bidRequest, null, InvocationAction.no_action)); | ||
} | ||
final GreenbidsConfig greenbidsConfig = Optional.ofNullable(parseBidRequestExt(auctionContext)) | ||
.orElse(parseAccountConfig(auctionContext.getAccount())); | ||
Comment on lines
+80
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
return Future.all( | ||
onnxModelRunnerWithThresholds.retrieveOnnxModelRunner(partner), | ||
onnxModelRunnerWithThresholds.retrieveThreshold(partner)) | ||
onnxModelRunnerWithThresholds.retrieveOnnxModelRunner(greenbidsConfig), | ||
onnxModelRunnerWithThresholds.retrieveThreshold(greenbidsConfig)) | ||
.compose(compositeFuture -> toInvocationResult( | ||
bidRequest, | ||
partner, | ||
greenbidsConfig, | ||
compositeFuture.resultAt(0), | ||
compositeFuture.resultAt(1))) | ||
.recover(throwable -> Future.succeededFuture(toInvocationResult( | ||
bidRequest, null, InvocationAction.no_action))); | ||
} | ||
|
||
private Partner parseBidRequestExt(BidRequest bidRequest) { | ||
return Optional.ofNullable(bidRequest) | ||
private GreenbidsConfig parseBidRequestExt(AuctionContext auctionContext) { | ||
return Optional.ofNullable(auctionContext) | ||
.map(AuctionContext::getBidRequest) | ||
.map(BidRequest::getExt) | ||
.map(ExtRequest::getPrebid) | ||
.map(ExtRequestPrebid::getAnalytics) | ||
.filter(this::isNotEmptyObjectNode) | ||
.map(analytics -> (ObjectNode) analytics.get(BID_REQUEST_ANALYTICS_EXTENSION_NAME)) | ||
.map(this::toPartner) | ||
.map(this::toGreenbidsConfig) | ||
.orElse(null); | ||
} | ||
|
||
private boolean isNotEmptyObjectNode(JsonNode analytics) { | ||
return analytics != null && analytics.isObject() && !analytics.isEmpty(); | ||
} | ||
|
||
private Partner toPartner(ObjectNode adapterNode) { | ||
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, Partner.class); | ||
return mapper.treeToValue(adapterNode, GreenbidsConfig.class); | ||
} catch (JsonProcessingException e) { | ||
return null; | ||
} | ||
} | ||
|
||
private Future<InvocationResult<AuctionRequestPayload>> toInvocationResult( | ||
BidRequest bidRequest, | ||
Partner partner, | ||
GreenbidsConfig greenbidsConfig, | ||
OnnxModelRunner onnxModelRunner, | ||
Double threshold) { | ||
|
||
|
@@ -138,7 +146,7 @@ private Future<InvocationResult<AuctionRequestPayload>> toInvocationResult( | |
} | ||
|
||
final GreenbidsInvocationResult greenbidsInvocationResult = greenbidsInvocationService | ||
.createGreenbidsInvocationResult(partner, bidRequest, impsBiddersFilterMap); | ||
.createGreenbidsInvocationResult(greenbidsConfig, bidRequest, impsBiddersFilterMap); | ||
|
||
return Future.succeededFuture(toInvocationResult( | ||
greenbidsInvocationResult.getUpdatedBidRequest(), | ||
|
@@ -207,4 +215,8 @@ private ObjectNode toObjectNode(Map<String, Ortb2ImpExtResult> values) { | |
public String code() { | ||
return CODE; | ||
} | ||
|
||
public String name() { | ||
return "greenbids"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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