forked from prebid/prebid-server-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b25cd09
commit b3f0c02
Showing
31 changed files
with
2,122 additions
and
371 deletions.
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
81 changes: 81 additions & 0 deletions
81
src/main/java/org/prebid/server/auction/HooksMetricsService.java
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.prebid.server.auction; | ||
|
||
import org.prebid.server.auction.model.AuctionContext; | ||
import org.prebid.server.hooks.execution.model.ExecutionAction; | ||
import org.prebid.server.hooks.execution.model.ExecutionStatus; | ||
import org.prebid.server.hooks.execution.model.GroupExecutionOutcome; | ||
import org.prebid.server.hooks.execution.model.HookExecutionOutcome; | ||
import org.prebid.server.hooks.execution.model.HookId; | ||
import org.prebid.server.hooks.execution.model.Stage; | ||
import org.prebid.server.hooks.execution.model.StageExecutionOutcome; | ||
import org.prebid.server.metric.Metrics; | ||
import org.prebid.server.settings.model.Account; | ||
|
||
import java.util.Collection; | ||
import java.util.EnumMap; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public class HooksMetricsService { | ||
|
||
private final Metrics metrics; | ||
|
||
public HooksMetricsService(Metrics metrics) { | ||
this.metrics = Objects.requireNonNull(metrics); | ||
} | ||
|
||
public AuctionContext updateHooksMetrics(AuctionContext context) { | ||
final EnumMap<Stage, List<StageExecutionOutcome>> stageOutcomes = | ||
context.getHookExecutionContext().getStageOutcomes(); | ||
|
||
final Account account = context.getAccount(); | ||
|
||
stageOutcomes.forEach((stage, outcomes) -> updateHooksStageMetrics(account, stage, outcomes)); | ||
|
||
// account might be null if request is rejected by the entrypoint hook | ||
if (account != null) { | ||
stageOutcomes.values().stream() | ||
.flatMap(Collection::stream) | ||
.map(StageExecutionOutcome::getGroups) | ||
.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))) | ||
.forEach((moduleCode, executionTime) -> | ||
metrics.updateAccountModuleDurationMetric(account, moduleCode, executionTime)); | ||
} | ||
|
||
return context; | ||
} | ||
|
||
private void updateHooksStageMetrics(Account account, Stage stage, List<StageExecutionOutcome> stageOutcomes) { | ||
stageOutcomes.stream() | ||
.flatMap(stageOutcome -> stageOutcome.getGroups().stream()) | ||
.flatMap(groupOutcome -> groupOutcome.getHooks().stream()) | ||
.forEach(hookOutcome -> updateHookInvocationMetrics(account, stage, hookOutcome)); | ||
} | ||
|
||
private void updateHookInvocationMetrics(Account account, Stage stage, HookExecutionOutcome hookOutcome) { | ||
final HookId hookId = hookOutcome.getHookId(); | ||
final ExecutionStatus status = hookOutcome.getStatus(); | ||
final ExecutionAction action = hookOutcome.getAction(); | ||
final String moduleCode = hookId.getModuleCode(); | ||
|
||
metrics.updateHooksMetrics( | ||
moduleCode, | ||
stage, | ||
hookId.getHookImplCode(), | ||
status, | ||
hookOutcome.getExecutionTime(), | ||
action); | ||
|
||
// account might be null if request is rejected by the entrypoint hook | ||
if (account != null) { | ||
metrics.updateAccountHooksMetrics(account, moduleCode, status, action); | ||
} | ||
} | ||
} |
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.