Skip to content

Commit

Permalink
Module Execution: Add Property to Require Account Config (#3525)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoxaAntoxic authored Nov 12, 2024
1 parent 84b3a70 commit 6af31f5
Show file tree
Hide file tree
Showing 46 changed files with 552 additions and 307 deletions.
12 changes: 12 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,15 @@ Following metrics are collected and submitted if account is configured with `det
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).timeout` - number of event requests, failed with timeout cause
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).err` - number of event requests, failed with errors
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).badinput` - number of event requests, rejected with bad input cause

## Modules metrics
- `modules.module.<module>.stage.<stage>.hook.<hook>.call` - number of times the hook is called
- `modules.module.<module>.stage.<stage>.hook.<hook>.duration` - timer tracking the called hook execution time
- `modules.module.<module>.stage.<stage>.hook.<hook>.success.(noop|update|reject|no-invocation)` - number of times the hook is called successfully with the action applied
- `modules.module.<module>.stage.<stage>.hook.<hook>.(failure|timeout|execution-error)` - number of times the hook execution is failed

## Modules per-account metrics
- `account.<account-id>.modules.module.<module>.call` - number of times the module is called
- `account.<account-id>.modules.module.<module>.duration` - timer tracking the called module execution time
- `account.<account-id>.modules.module.<module>.success.(noop|update|reject|no-invocation)` - number of times the module is called successfully with the action applied
- `account.<account-id>.modules.module.<module>.failure` - number of times the module execution is failed
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import org.prebid.server.hooks.modules.com.confiant.adquality.core.BidsScanResult;
import org.prebid.server.hooks.modules.com.confiant.adquality.core.BidsScanner;
import org.prebid.server.hooks.modules.com.confiant.adquality.model.GroupByIssues;
import org.prebid.server.hooks.modules.com.confiant.adquality.v1.model.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationAction;
import org.prebid.server.hooks.v1.InvocationResult;
import org.prebid.server.hooks.v1.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationStatus;
import org.prebid.server.hooks.v1.auction.AuctionInvocationContext;
import org.prebid.server.hooks.v1.bidder.AllProcessedBidResponsesHook;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import org.prebid.server.hooks.modules.fiftyone.devicedetection.model.boundary.CollectedEvidence;
import org.prebid.server.hooks.modules.fiftyone.devicedetection.v1.model.ModuleContext;
import org.prebid.server.hooks.modules.fiftyone.devicedetection.v1.model.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationAction;
import org.prebid.server.hooks.v1.InvocationContext;
import org.prebid.server.hooks.v1.InvocationResult;
import org.prebid.server.hooks.v1.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationStatus;
import org.prebid.server.hooks.v1.entrypoint.EntrypointHook;
import org.prebid.server.hooks.v1.entrypoint.EntrypointPayload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import org.prebid.server.hooks.modules.fiftyone.devicedetection.v1.core.EnrichmentResult;
import org.prebid.server.hooks.modules.fiftyone.devicedetection.v1.core.SecureHeadersRetriever;
import org.prebid.server.hooks.modules.fiftyone.devicedetection.v1.model.ModuleContext;
import org.prebid.server.hooks.modules.fiftyone.devicedetection.v1.model.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationAction;
import org.prebid.server.hooks.v1.InvocationResult;
import org.prebid.server.hooks.v1.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationStatus;
import org.prebid.server.hooks.v1.auction.AuctionInvocationContext;
import org.prebid.server.hooks.v1.auction.AuctionRequestPayload;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import org.prebid.server.hooks.modules.ortb2.blocking.core.model.ExecutionResult;
import org.prebid.server.hooks.modules.ortb2.blocking.model.ModuleContext;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.BidderRequestPayloadImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationAction;
import org.prebid.server.hooks.v1.InvocationResult;
import org.prebid.server.hooks.v1.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationStatus;
import org.prebid.server.hooks.v1.bidder.BidderInvocationContext;
import org.prebid.server.hooks.v1.bidder.BidderRequestHook;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import org.prebid.server.hooks.modules.ortb2.blocking.core.model.ExecutionResult;
import org.prebid.server.hooks.modules.ortb2.blocking.model.ModuleContext;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.BidderResponsePayloadImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.InvocationResultImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.analytics.ActivityImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.analytics.AppliedToImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.analytics.ResultImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.analytics.TagsImpl;
import org.prebid.server.hooks.v1.InvocationAction;
import org.prebid.server.hooks.v1.InvocationResult;
import org.prebid.server.hooks.v1.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationStatus;
import org.prebid.server.hooks.v1.analytics.Result;
import org.prebid.server.hooks.v1.analytics.Tags;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import org.prebid.server.hooks.modules.ortb2.blocking.model.ModuleContext;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.BidderInvocationContextImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.BidderRequestPayloadImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationAction;
import org.prebid.server.hooks.v1.InvocationResult;
import org.prebid.server.hooks.v1.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationStatus;
import org.prebid.server.hooks.v1.PayloadUpdate;
import org.prebid.server.hooks.v1.bidder.BidderRequestPayload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import org.prebid.server.hooks.modules.ortb2.blocking.model.ModuleContext;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.BidderInvocationContextImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.BidderResponsePayloadImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.InvocationResultImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.analytics.ActivityImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.analytics.AppliedToImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.analytics.ResultImpl;
import org.prebid.server.hooks.modules.ortb2.blocking.v1.model.analytics.TagsImpl;
import org.prebid.server.hooks.v1.InvocationAction;
import org.prebid.server.hooks.v1.InvocationResult;
import org.prebid.server.hooks.v1.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationStatus;
import org.prebid.server.hooks.v1.PayloadUpdate;
import org.prebid.server.hooks.v1.bidder.BidderResponsePayload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import org.prebid.server.hooks.modules.pb.response.correction.core.ResponseCorrectionProvider;
import org.prebid.server.hooks.modules.pb.response.correction.core.config.model.Config;
import org.prebid.server.hooks.modules.pb.response.correction.core.correction.Correction;
import org.prebid.server.hooks.modules.pb.response.correction.v1.model.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationAction;
import org.prebid.server.hooks.v1.InvocationResult;
import org.prebid.server.hooks.v1.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationStatus;
import org.prebid.server.hooks.v1.auction.AuctionInvocationContext;
import org.prebid.server.hooks.v1.bidder.AllProcessedBidResponsesHook;
Expand Down Expand Up @@ -57,7 +57,7 @@ public Future<InvocationResult<AllProcessedBidResponsesPayload>> call(AllProcess
return noAction();
}

final InvocationResult<AllProcessedBidResponsesPayload> invocationResult = InvocationResultImpl.builder()
final InvocationResult<AllProcessedBidResponsesPayload> invocationResult = InvocationResultImpl.<AllProcessedBidResponsesPayload>builder()
.status(InvocationStatus.success)
.action(InvocationAction.update)
.payloadUpdate(initialPayload -> AllProcessedBidResponsesPayloadImpl.of(
Expand All @@ -84,15 +84,15 @@ private static List<BidderResponse> applyCorrections(List<BidderResponse> bidder
}

private Future<InvocationResult<AllProcessedBidResponsesPayload>> failure(String message) {
return Future.succeededFuture(InvocationResultImpl.builder()
return Future.succeededFuture(InvocationResultImpl.<AllProcessedBidResponsesPayload>builder()
.status(InvocationStatus.failure)
.message(message)
.action(InvocationAction.no_action)
.build());
}

private static Future<InvocationResult<AllProcessedBidResponsesPayload>> noAction() {
return Future.succeededFuture(InvocationResultImpl.builder()
return Future.succeededFuture(InvocationResultImpl.<AllProcessedBidResponsesPayload>builder()
.status(InvocationStatus.success)
.action(InvocationAction.no_action)
.build());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import org.prebid.server.hooks.modules.pb.richmedia.filter.model.AnalyticsResult;
import org.prebid.server.hooks.modules.pb.richmedia.filter.model.MraidFilterResult;
import org.prebid.server.hooks.modules.pb.richmedia.filter.model.PbRichMediaFilterProperties;
import org.prebid.server.hooks.modules.pb.richmedia.filter.v1.model.InvocationResultImpl;
import org.prebid.server.hooks.modules.pb.richmedia.filter.v1.model.analytics.ActivityImpl;
import org.prebid.server.hooks.modules.pb.richmedia.filter.v1.model.analytics.AppliedToImpl;
import org.prebid.server.hooks.modules.pb.richmedia.filter.v1.model.analytics.ResultImpl;
import org.prebid.server.hooks.modules.pb.richmedia.filter.v1.model.analytics.TagsImpl;
import org.prebid.server.hooks.v1.InvocationAction;
import org.prebid.server.hooks.v1.InvocationResult;
import org.prebid.server.hooks.v1.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationStatus;
import org.prebid.server.hooks.v1.analytics.Result;
import org.prebid.server.hooks.v1.analytics.Tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,7 @@ private AuctionContext updateHooksMetrics(AuctionContext context) {
.flatMap(Collection::stream)
.map(GroupExecutionOutcome::getHooks)
.flatMap(Collection::stream)
.filter(hookOutcome -> hookOutcome.getAction() != ExecutionAction.no_invocation)
.collect(Collectors.groupingBy(
outcome -> outcome.getHookId().getModuleCode(),
Collectors.summingLong(HookExecutionOutcome::getExecutionTime)))
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/org/prebid/server/hooks/execution/GroupExecutor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.prebid.server.hooks.execution;

import com.fasterxml.jackson.databind.node.ObjectNode;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Promise;
Expand All @@ -8,8 +9,12 @@
import org.prebid.server.hooks.execution.model.HookExecutionContext;
import org.prebid.server.hooks.execution.model.HookId;
import org.prebid.server.hooks.v1.Hook;
import org.prebid.server.hooks.v1.InvocationAction;
import org.prebid.server.hooks.v1.InvocationContext;
import org.prebid.server.hooks.v1.InvocationResult;
import org.prebid.server.hooks.v1.InvocationResultImpl;
import org.prebid.server.hooks.v1.InvocationStatus;
import org.prebid.server.hooks.v1.auction.AuctionInvocationContext;
import org.prebid.server.log.ConditionalLogger;
import org.prebid.server.log.LoggerFactory;

Expand All @@ -25,6 +30,7 @@ class GroupExecutor<PAYLOAD, CONTEXT extends InvocationContext> {

private final Vertx vertx;
private final Clock clock;
private final boolean isConfigToInvokeRequired;

private ExecutionGroup group;
private PAYLOAD initialPayload;
Expand All @@ -33,16 +39,18 @@ class GroupExecutor<PAYLOAD, CONTEXT extends InvocationContext> {
private HookExecutionContext hookExecutionContext;
private boolean rejectAllowed;

private GroupExecutor(Vertx vertx, Clock clock) {
private GroupExecutor(Vertx vertx, Clock clock, boolean isConfigToInvokeRequired) {
this.vertx = vertx;
this.clock = clock;
this.isConfigToInvokeRequired = isConfigToInvokeRequired;
}

public static <PAYLOAD, CONTEXT extends InvocationContext> GroupExecutor<PAYLOAD, CONTEXT> create(
Vertx vertx,
Clock clock) {
Clock clock,
boolean isConfigToInvokeRequired) {

return new GroupExecutor<>(vertx, clock);
return new GroupExecutor<>(vertx, clock, isConfigToInvokeRequired);
}

public GroupExecutor<PAYLOAD, CONTEXT> withGroup(ExecutionGroup group) {
Expand Down Expand Up @@ -107,11 +115,19 @@ private Future<InvocationResult<PAYLOAD>> executeHook(
return Future.failedFuture(new FailedException("Hook implementation does not exist or disabled"));
}

return executeWithTimeout(
() -> hook.call(
groupResult.payload(),
invocationContextProvider.apply(timeout, hookId, moduleContextFor(hookId))),
timeout);
final CONTEXT invocationContext = invocationContextProvider.apply(timeout, hookId, moduleContextFor(hookId));

if (isConfigToInvokeRequired && invocationContext instanceof AuctionInvocationContext) {
final ObjectNode accountConfig = ((AuctionInvocationContext) invocationContext).accountConfig();
if (accountConfig == null || accountConfig.isNull()) {
return Future.succeededFuture(InvocationResultImpl.<PAYLOAD>builder()
.status(InvocationStatus.success)
.action(InvocationAction.no_invocation)
.build());
}
}

return executeWithTimeout(() -> hook.call(groupResult.payload(), invocationContext), timeout);
}

private <T> Future<T> executeWithTimeout(Supplier<Future<T>> action, Long timeout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private static ExecutionAction toExecutionAction(InvocationAction action) {
case reject -> ExecutionAction.reject;
case update -> ExecutionAction.update;
case no_action -> ExecutionAction.no_action;
case no_invocation -> ExecutionAction.no_invocation;
};
}

Expand Down
Loading

0 comments on commit 6af31f5

Please sign in to comment.