Skip to content

Commit 9a1f926

Browse files
Add module-execution config on the host level (#3594)
1 parent ae475a5 commit 9a1f926

7 files changed

Lines changed: 141 additions & 26 deletions

File tree

docs/config-app.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,6 @@ contain 'WHERE last_updated > ?' for MySQL and 'WHERE last_updated > $1' for Pos
370370
For targeting available next options:
371371
- `settings.targeting.truncate-attr-chars` - set the max length for names of targeting keywords (0 means no truncation).
372372

373-
For modules:
374-
- `settings.modules.require-config-to-invoke` - when enabled it requires a runtime config to exist for a module.
375-
376373
## Host Cookie
377374
- `host-cookie.optout-cookie.name` - set the cookie name for optout checking.
378375
- `host-cookie.optout-cookie.value` - set the cookie value for optout checking.
@@ -443,6 +440,10 @@ If not defined in config all other Health Checkers would be disabled and endpoin
443440
- `analytics.pubstack.buffers.count` - threshold in events count for buffer to send events
444441
- `analytics.pubstack.buffers.report-ttl-ms` - max period between two reports.
445442

443+
## Modules
444+
- `hooks.admin.module-execution` - a key-value map, where a key is a module name and a value is a boolean, that defines whether modules hooks should/should not be always executed; if the module is not specified it is executed by default when it's present in the execution plan
445+
- `settings.modules.require-config-to-invoke` - when enabled it requires a runtime config to exist for a module.
446+
446447
## Debugging
447448
- `debug.override-token` - special string token for overriding Prebid Server account and/or adapter debug information presence in the auction response.
448449

src/main/java/org/prebid/server/hooks/execution/GroupExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public Future<GroupResult<PAYLOAD>> execute() {
8181
Future<GroupResult<PAYLOAD>> groupFuture = Future.succeededFuture(initialGroupResult);
8282

8383
for (final HookId hookId : group.getHookSequence()) {
84-
if (!modulesExecution.getOrDefault(hookId.getModuleCode(), true)) {
84+
if (!modulesExecution.get(hookId.getModuleCode())) {
8585
continue;
8686
}
8787

src/main/java/org/prebid/server/hooks/execution/HookStageExecutor.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public class HookStageExecutor {
8181

8282
private final ExecutionPlan hostExecutionPlan;
8383
private final ExecutionPlan defaultAccountExecutionPlan;
84+
private final Map<String, Boolean> hostModuleExecution;
8485
private final HookCatalog hookCatalog;
8586
private final TimeoutFactory timeoutFactory;
8687
private final Vertx vertx;
@@ -90,6 +91,7 @@ public class HookStageExecutor {
9091

9192
private HookStageExecutor(ExecutionPlan hostExecutionPlan,
9293
ExecutionPlan defaultAccountExecutionPlan,
94+
Map<String, Boolean> hostModuleExecution,
9395
HookCatalog hookCatalog,
9496
TimeoutFactory timeoutFactory,
9597
Vertx vertx,
@@ -105,10 +107,12 @@ private HookStageExecutor(ExecutionPlan hostExecutionPlan,
105107
this.clock = clock;
106108
this.mapper = mapper;
107109
this.isConfigToInvokeRequired = isConfigToInvokeRequired;
110+
this.hostModuleExecution = hostModuleExecution;
108111
}
109112

110113
public static HookStageExecutor create(String hostExecutionPlan,
111114
String defaultAccountExecutionPlan,
115+
Map<String, Boolean> hostModuleExecution,
112116
HookCatalog hookCatalog,
113117
TimeoutFactory timeoutFactory,
114118
Vertx vertx,
@@ -122,6 +126,7 @@ public static HookStageExecutor create(String hostExecutionPlan,
122126
return new HookStageExecutor(
123127
parseAndValidateExecutionPlan(hostExecutionPlan, mapper, hookCatalog),
124128
parseAndValidateExecutionPlan(defaultAccountExecutionPlan, mapper, hookCatalog),
129+
hostModuleExecution,
125130
hookCatalog,
126131
Objects.requireNonNull(timeoutFactory),
127132
Objects.requireNonNull(vertx),
@@ -185,7 +190,7 @@ public Future<HookStageExecutionResult<EntrypointPayload>> executeEntrypointStag
185190
.withHookProvider(hookProviderForEntrypointStage(context))
186191
.withInitialPayload(EntrypointPayloadImpl.of(queryParams, headers, body))
187192
.withInvocationContextProvider(invocationContextProvider(endpoint))
188-
.withModulesExecution(Collections.emptyMap())
193+
.withModulesExecution(DefaultedMap.defaultedMap(hostModuleExecution, true))
189194
.withRejectAllowed(true)
190195
.execute();
191196
}
@@ -374,6 +379,7 @@ private Map<String, Boolean> modulesExecutionForAccount(Account account) {
374379
.forEach(module -> resultModulesExecution.computeIfAbsent(module, key -> true));
375380
}
376381

382+
resultModulesExecution.putAll(hostModuleExecution);
377383
return DefaultedMap.defaultedMap(resultModulesExecution, !isConfigToInvokeRequired);
378384
}
379385

src/main/java/org/prebid/server/spring/config/HooksConfiguration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.prebid.server.hooks.execution.HookStageExecutor;
99
import org.prebid.server.hooks.v1.Module;
1010
import org.prebid.server.json.JacksonMapper;
11+
import org.prebid.server.settings.model.HooksAdminConfig;
1112
import org.springframework.beans.factory.annotation.Value;
1213
import org.springframework.boot.context.properties.ConfigurationProperties;
1314
import org.springframework.context.annotation.Bean;
@@ -16,6 +17,8 @@
1617

1718
import java.time.Clock;
1819
import java.util.Collection;
20+
import java.util.Collections;
21+
import java.util.Optional;
1922

2023
@Configuration
2124
public class HooksConfiguration {
@@ -38,6 +41,9 @@ HookStageExecutor hookStageExecutor(HooksConfigurationProperties hooksConfigurat
3841
return HookStageExecutor.create(
3942
hooksConfiguration.getHostExecutionPlan(),
4043
hooksConfiguration.getDefaultAccountExecutionPlan(),
44+
Optional.ofNullable(hooksConfiguration.getAdmin())
45+
.map(HooksAdminConfig::getModuleExecution)
46+
.orElseGet(Collections::emptyMap),
4147
hookCatalog,
4248
timeoutFactory,
4349
vertx,
@@ -60,5 +66,7 @@ private static class HooksConfigurationProperties {
6066
String hostExecutionPlan;
6167

6268
String defaultAccountExecutionPlan;
69+
70+
HooksAdminConfig admin;
6371
}
6472
}

src/test/groovy/org/prebid/server/functional/testcontainers/container/PrebidServerContainer.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class PrebidServerContainer extends GenericContainer<PrebidServerContainer> {
9191

9292
private static String normalizeProperty(String property) {
9393
property.replace(".", "_")
94-
.replace("-", "")
9594
.replace("[", "_")
9695
.replace("]", "_")
9796
}

src/test/groovy/org/prebid/server/functional/tests/module/GeneralModuleSpec.groovy

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import org.prebid.server.functional.model.request.auction.TraceLevel
1515
import org.prebid.server.functional.model.response.auction.InvocationResult
1616
import org.prebid.server.functional.service.PrebidServerService
1717
import org.prebid.server.functional.util.PBSUtils
18-
import spock.lang.PendingFeature
1918

2019
import static org.prebid.server.functional.model.ModuleName.ORTB2_BLOCKING
2120
import static org.prebid.server.functional.model.ModuleName.PB_RICHMEDIA_FILTER
@@ -293,7 +292,6 @@ class GeneralModuleSpec extends ModuleBaseSpec {
293292
modulesConfig << [null, new PbsModulesConfig()]
294293
}
295294

296-
@PendingFeature
297295
def "PBS should call all modules without account config when modules enabled in module-execution host config"() {
298296
given: "PBS service with module-execution config"
299297
def pbsConfig = MULTI_MODULE_CONFIG + ENABLED_INVOKE_CONFIG +
@@ -333,6 +331,37 @@ class GeneralModuleSpec extends ModuleBaseSpec {
333331
pbsServiceFactory.removeContainer(pbsConfig)
334332
}
335333

334+
def "PBS shouldn't call any module without account config when modules disabled in module-execution host config"() {
335+
given: "PBS service with module-execution config"
336+
def pbsConfig = MULTI_MODULE_CONFIG + ENABLED_INVOKE_CONFIG +
337+
[("hooks.admin.module-execution.${ORTB2_BLOCKING.code}".toString()): 'false']
338+
def pbsServiceWithMultipleModules = pbsServiceFactory.getService(pbsConfig)
339+
340+
and: "Default bid request with verbose trace"
341+
def bidRequest = defaultBidRequest.tap {
342+
ext.prebid.trace = TraceLevel.VERBOSE
343+
}
344+
345+
and: "Flush metrics"
346+
flushMetrics(pbsServiceWithMultipleModules)
347+
348+
when: "PBS processes auction request"
349+
def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest)
350+
351+
then: "PBS response shouldn't include trace information about no-called modules"
352+
assert !response?.ext?.prebid?.modules?.trace?.stages?.outcomes?.groups?.invocationResults?.flatten()
353+
354+
and: "Ortb2blocking module call metrics shouldn't be updated"
355+
def metrics = pbsServiceWithMultipleModuleWithRequireInvoke.sendCollectedMetricsRequest()
356+
assert !metrics[CALL_METRIC.formatted(ORTB2_BLOCKING.code, BIDDER_REQUEST.metricValue, ORTB2_BLOCKING_BIDDER_REQUEST.code)]
357+
assert !metrics[CALL_METRIC.formatted(ORTB2_BLOCKING.code, RAW_BIDDER_RESPONSE.metricValue, ORTB2_BLOCKING_RAW_BIDDER_RESPONSE.code)]
358+
assert !metrics[NOOP_METRIC.formatted(ORTB2_BLOCKING.code, BIDDER_REQUEST.metricValue, ORTB2_BLOCKING_BIDDER_REQUEST.code)]
359+
assert !metrics[NOOP_METRIC.formatted(ORTB2_BLOCKING.code, RAW_BIDDER_RESPONSE.metricValue, ORTB2_BLOCKING_RAW_BIDDER_RESPONSE.code)]
360+
361+
cleanup: "Stop and remove pbs container"
362+
pbsServiceFactory.removeContainer(pbsConfig)
363+
}
364+
336365
def "PBS should call module without account config when default-account module-execution config enabled module"() {
337366
given: "PBS service with module-execution and default account configs"
338367
def defaultAccountConfigSettings = AccountConfig.defaultAccountConfig.tap {
@@ -358,19 +387,15 @@ class GeneralModuleSpec extends ModuleBaseSpec {
358387
when: "PBS processes auction request"
359388
def response = pbsServiceWithMultipleModules.sendAuctionRequest(bidRequest)
360389

361-
then: "PBS response should include trace information about called modules"
362-
verifyAll(response?.ext?.prebid?.modules?.trace?.stages?.outcomes?.groups?.invocationResults?.flatten() as List<InvocationResult>) {
363-
it.status == [SUCCESS, SUCCESS]
364-
it.action == [NO_ACTION, NO_ACTION]
365-
it.hookId.moduleCode.sort() == [ORTB2_BLOCKING, ORTB2_BLOCKING].code.sort()
366-
}
390+
then: "PBS response shouldn't include trace information about no-called modules"
391+
assert !response?.ext?.prebid?.modules?.trace?.stages?.outcomes?.groups?.invocationResults?.flatten()
367392

368-
and: "Ortb2blocking module call metrics should be updated"
369-
def metrics = pbsServiceWithMultipleModules.sendCollectedMetricsRequest()
370-
assert metrics[CALL_METRIC.formatted(ORTB2_BLOCKING.code, BIDDER_REQUEST.metricValue, ORTB2_BLOCKING_BIDDER_REQUEST.code)] == 1
371-
assert metrics[CALL_METRIC.formatted(ORTB2_BLOCKING.code, RAW_BIDDER_RESPONSE.metricValue, ORTB2_BLOCKING_RAW_BIDDER_RESPONSE.code)] == 1
372-
assert metrics[NOOP_METRIC.formatted(ORTB2_BLOCKING.code, BIDDER_REQUEST.metricValue, ORTB2_BLOCKING_BIDDER_REQUEST.code)] == 1
373-
assert metrics[NOOP_METRIC.formatted(ORTB2_BLOCKING.code, RAW_BIDDER_RESPONSE.metricValue, ORTB2_BLOCKING_RAW_BIDDER_RESPONSE.code)] == 1
393+
and: "Ortb2blocking module call metrics shouldn't be updated"
394+
def metrics = pbsServiceWithMultipleModuleWithRequireInvoke.sendCollectedMetricsRequest()
395+
assert !metrics[CALL_METRIC.formatted(ORTB2_BLOCKING.code, BIDDER_REQUEST.metricValue, ORTB2_BLOCKING_BIDDER_REQUEST.code)]
396+
assert !metrics[CALL_METRIC.formatted(ORTB2_BLOCKING.code, RAW_BIDDER_RESPONSE.metricValue, ORTB2_BLOCKING_RAW_BIDDER_RESPONSE.code)]
397+
assert !metrics[NOOP_METRIC.formatted(ORTB2_BLOCKING.code, BIDDER_REQUEST.metricValue, ORTB2_BLOCKING_BIDDER_REQUEST.code)]
398+
assert !metrics[NOOP_METRIC.formatted(ORTB2_BLOCKING.code, RAW_BIDDER_RESPONSE.metricValue, ORTB2_BLOCKING_RAW_BIDDER_RESPONSE.code)]
374399

375400
and: "RB-Richmedia-Filter module call metrics shouldn't be updated"
376401
assert !metrics[CALL_METRIC.formatted(PB_RICHMEDIA_FILTER.code, ALL_PROCESSED_BID_RESPONSES.metricValue, PB_RICHMEDIA_FILTER_ALL_PROCESSED_RESPONSES.code)]

0 commit comments

Comments
 (0)