Skip to content
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

Exitpoint Stage #3564

Merged
merged 12 commits into from
Dec 4, 2024
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.prebid.server.activity.infrastructure.payload;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.prebid.server.activity.ComponentType;
import org.prebid.server.activity.infrastructure.payload.impl.BasicActivityInvocationPayload;

@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
@JsonSubTypes(@JsonSubTypes.Type(BasicActivityInvocationPayload.class))
public interface ActivityInvocationPayload {

@JsonProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package org.prebid.server.activity.infrastructure.payload;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.prebid.server.activity.infrastructure.payload.impl.BasicActivityInvocationPayload;

@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
@JsonSubTypes(@JsonSubTypes.Type(BasicActivityInvocationPayload.class))
public interface GeoActivityInvocationPayload extends ActivityInvocationPayload {

@JsonProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package org.prebid.server.activity.infrastructure.payload;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.prebid.server.activity.infrastructure.payload.impl.BasicActivityInvocationPayload;

@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
@JsonSubTypes(@JsonSubTypes.Type(BasicActivityInvocationPayload.class))
public interface GpcActivityInvocationPayload extends ActivityInvocationPayload {

@JsonProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.prebid.server.activity.infrastructure.payload.impl;

import lombok.Value;
import lombok.experimental.Accessors;
import org.prebid.server.activity.ComponentType;
import org.prebid.server.activity.infrastructure.payload.GeoActivityInvocationPayload;
import org.prebid.server.activity.infrastructure.payload.GpcActivityInvocationPayload;

@Accessors(fluent = true)
@Value(staticConstructor = "of")
public class BasicActivityInvocationPayload implements GeoActivityInvocationPayload, GpcActivityInvocationPayload {

ComponentType componentType;

String componentName;

String country;

String region;

String gpc;
}
65 changes: 1 addition & 64 deletions src/main/java/org/prebid/server/auction/ExchangeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,7 @@
import org.prebid.server.floors.PriceFloorAdjuster;
import org.prebid.server.floors.PriceFloorProcessor;
import org.prebid.server.hooks.execution.HookStageExecutor;
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.HookStageExecutionResult;
import org.prebid.server.hooks.execution.model.Stage;
import org.prebid.server.hooks.execution.model.StageExecutionOutcome;
import org.prebid.server.hooks.v1.bidder.BidderRequestPayload;
import org.prebid.server.hooks.v1.bidder.BidderResponsePayload;
import org.prebid.server.json.JacksonMapper;
Expand Down Expand Up @@ -110,7 +103,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -221,8 +213,7 @@ public Future<AuctionContext> holdAuction(AuctionContext context) {
return processAuctionRequest(context)
.compose(this::invokeResponseHooks)
.map(AnalyticsTagsEnricher::enrichWithAnalyticsTags)
.map(HookDebugInfoEnricher::enrichWithHooksDebugInfo)
.map(this::updateHooksMetrics);
.map(HookDebugInfoEnricher::enrichWithHooksDebugInfo);
CTMBNara marked this conversation as resolved.
Show resolved Hide resolved
}

private Future<AuctionContext> processAuctionRequest(AuctionContext context) {
Expand Down Expand Up @@ -1374,58 +1365,4 @@ private static MetricName bidderErrorTypeToMetric(BidderError.Type errorType) {
case rejected_ipf, generic -> MetricName.unknown_error;
};
}

private 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);
}
}
}
81 changes: 81 additions & 0 deletions src/main/java/org/prebid/server/auction/HooksMetricsService.java
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public class AuctionContext {
@Builder.Default
BidAdjustments bidAdjustments = BidAdjustments.of(Collections.emptyMap());

@JsonIgnore
RawAuctionResponse rawAuctionResponse;

public AuctionContext with(Account account) {
return this.toBuilder().account(account).build();
}
Expand Down Expand Up @@ -136,6 +139,10 @@ public AuctionContext with(BidAdjustments bidAdjustments) {
.build();
}

public AuctionContext with(RawAuctionResponse rawAuctionResponse) {
return this.toBuilder().rawAuctionResponse(rawAuctionResponse).build();
}

public AuctionContext withRequestRejected() {
return this.toBuilder()
.requestRejected(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.prebid.server.auction.model;

import io.vertx.core.MultiMap;
import lombok.Builder;
import lombok.Value;
import org.prebid.server.hooks.v1.exit.ExitpointPayload;

@Value(staticConstructor = "of")
@Builder(toBuilder = true)
public class RawAuctionResponse {

String responseBody;

MultiMap responseHeaders;

public RawAuctionResponse of(ExitpointPayload exitpointPayload) {
return this.toBuilder()
.responseHeaders(exitpointPayload.responseHeaders())
.responseBody(exitpointPayload.responseBody())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ private static HttpRequestContext toHttpRequest(HookStageExecutionResult<Entrypo
}

return HttpRequestContext.builder()
.httpMethod(routingContext.request().method())
.absoluteUri(routingContext.request().absoluteURI())
.queryParams(stageResult.getPayload().queryParams())
.headers(stageResult.getPayload().headers())
Expand Down
Loading
Loading