-
Notifications
You must be signed in to change notification settings - Fork 224
Support testing the USGen privacy module #3695
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ec774b
Support testing the USGen privacy module
AntoxaAntoxic 066e403
Fix
AntoxaAntoxic cd73b40
Merge remote-tracking branch 'refs/remotes/origin/master' into privca…
AntoxaAntoxic 190a070
Fix comments
AntoxaAntoxic f3cd04d
Tests: Support testing the USGen privacy module (#3722)
osulzhenko 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.ThreadLocalRandom; | ||
| import java.util.function.BinaryOperator; | ||
| import java.util.function.Function; | ||
| import java.util.function.Supplier; | ||
|
|
@@ -41,6 +42,8 @@ public class ActivityInfrastructureCreator { | |
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(ActivityInfrastructureCreator.class); | ||
|
|
||
| private static final int MODULE_MAX_SKIP_RATE = 100; | ||
|
|
||
| private final ActivityRuleFactory activityRuleFactory; | ||
| private final Purpose defaultPurpose4; | ||
| private final Metrics metrics; | ||
|
|
@@ -144,9 +147,13 @@ private ActivityController from(Activity activity, | |
| debug); | ||
| } | ||
|
|
||
| final Map<PrivacyModuleQualifier, Boolean> skipModulesConfigs = modulesConfigs.entrySet().stream() | ||
| .collect(Collectors.toMap(Map.Entry::getKey, entry -> shouldSkipAllActivities(entry.getValue()))); | ||
|
|
||
| final ActivityControllerCreationContext creationContext = ActivityControllerCreationContext.of( | ||
| activity, | ||
| modulesConfigs, | ||
| skipModulesConfigs, | ||
| gppContext); | ||
|
|
||
| final boolean allow = allowFromConfig(activityConfiguration.getAllow()); | ||
|
|
@@ -158,6 +165,13 @@ private ActivityController from(Activity activity, | |
| return ActivityController.of(allow, rules, debug); | ||
| } | ||
|
|
||
| private static boolean shouldSkipAllActivities(AccountPrivacyModuleConfig config) { | ||
|
||
| return Optional.ofNullable(config) | ||
AntoxaAntoxic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .map(AccountPrivacyModuleConfig::getSkipRate) | ||
| .map(skipRate -> ThreadLocalRandom.current().nextInt(MODULE_MAX_SKIP_RATE) < skipRate) | ||
| .orElse(false); | ||
| } | ||
|
|
||
| private static boolean allowFromConfig(Boolean configValue) { | ||
| return configValue != null ? configValue : ActivityInfrastructure.ALLOW_ACTIVITY_BY_DEFAULT; | ||
| } | ||
|
|
||
This file contains hidden or 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
30 changes: 30 additions & 0 deletions
30
src/main/java/org/prebid/server/activity/infrastructure/privacy/AbstainPrivacyModule.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package org.prebid.server.activity.infrastructure.privacy; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.prebid.server.activity.infrastructure.debug.Loggable; | ||
| import org.prebid.server.activity.infrastructure.payload.ActivityInvocationPayload; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class AbstainPrivacyModule implements PrivacyModule, Loggable { | ||
|
|
||
| private final PrivacyModuleQualifier privacyModuleQualifier; | ||
|
|
||
| public AbstainPrivacyModule(PrivacyModuleQualifier privacyModuleQualifier) { | ||
| this.privacyModuleQualifier = Objects.requireNonNull(privacyModuleQualifier); | ||
| } | ||
|
|
||
| @Override | ||
| public Result proceed(ActivityInvocationPayload activityInvocationPayload) { | ||
| return Result.ABSTAIN; | ||
| } | ||
|
|
||
| @Override | ||
| public JsonNode asLogEntry(ObjectMapper mapper) { | ||
| return mapper.createObjectNode() | ||
| .put("privacy_module", privacyModuleQualifier.moduleName()) | ||
| .put("skipped", true) | ||
| .put("result", Result.ABSTAIN.name()); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.