Skip to content

Commit

Permalink
Core: Transition PAAPI parameters (#3670)
Browse files Browse the repository at this point in the history
  • Loading branch information
And1sS authored Jan 28, 2025
1 parent 9e04626 commit 02ab379
Show file tree
Hide file tree
Showing 57 changed files with 1,847 additions and 410 deletions.
201 changes: 185 additions & 16 deletions src/main/java/org/prebid/server/auction/BidResponseCreator.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private Future<AuctionContext> runAuction(AuctionContext receivedContext) {
.map(auctionParticipations -> updateResponsesMetrics(auctionParticipations, account, aliases))
.map(context::with))
// produce response from bidder results
.compose(context -> bidResponseCreator.create(context, cacheInfo, bidderToMultiBid)
.compose(context -> bidResponseCreator.create(context, cacheInfo, aliases, bidderToMultiBid)
.map(bidResponse -> criteriaLogManager.traceResponse(
logger,
bidResponse,
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/org/prebid/server/auction/ImpAdjuster.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.prebid.server.auction;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.IntNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.iab.openrtb.request.Imp;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.json.JsonMerger;
import org.prebid.server.util.StreamUtil;
import org.prebid.server.validation.ImpValidator;

import java.util.Iterator;
Expand All @@ -15,6 +18,8 @@
public class ImpAdjuster {

private static final String IMP_EXT = "ext";
private static final String EXT_AE = "ae";
private static final String EXT_IGS = "igs";
private static final String EXT_PREBID = "prebid";
private static final String EXT_PREBID_BIDDER = "bidder";
private static final String EXT_PREBID_IMP = "imp";
Expand All @@ -33,6 +38,8 @@ public ImpAdjuster(JacksonMapper jacksonMapper,
}

public Imp adjust(Imp originalImp, String bidder, BidderAliases bidderAliases, List<String> debugMessages) {
setAeParams(originalImp.getExt());

final JsonNode impExtPrebidImp = bidderParamsFromImpExtPrebidImp(originalImp.getExt());
if (impExtPrebidImp == null) {
return originalImp;
Expand Down Expand Up @@ -65,6 +72,28 @@ public Imp adjust(Imp originalImp, String bidder, BidderAliases bidderAliases, L
}
}

private void setAeParams(ObjectNode ext) {
final int extAe = Optional.ofNullable(ext)
.map(extNode -> extNode.get(EXT_AE))
.filter(JsonNode::isInt)
.map(JsonNode::asInt)
.orElse(-1);

final boolean extIgsAePresent = Optional.ofNullable(ext)
.map(extNode -> extNode.get(EXT_IGS))
.filter(JsonNode::isArray)
.stream()
.flatMap(extNode -> StreamUtil.asStream(extNode.spliterator()))
.filter(Objects::nonNull)
.anyMatch(igsElementNode -> igsElementNode.has(EXT_AE));

if (!extIgsAePresent && (extAe == 0 || extAe == 1)) {
final ArrayNode extIgs = jacksonMapper.mapper().createArrayNode();
extIgs.add(jacksonMapper.mapper().createObjectNode().set(EXT_AE, IntNode.valueOf(extAe)));
ext.set(EXT_IGS, extIgs);
}
}

private static JsonNode bidderParamsFromImpExtPrebidImp(ObjectNode ext) {
return Optional.ofNullable(ext)
.map(extNode -> extNode.get(EXT_PREBID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public BidRejectionTracker(String bidder, Set<String> involvedImpIds, double log
rejectedBids = new HashMap<>();
}

/**
* Restores ONLY imps from rejection, rejected bids are preserved for analytics.
* A bid can be rejected only once.
*/
public void succeed(Collection<BidderBid> bids) {
bids.stream()
.map(BidderBid::getBid)
Expand Down Expand Up @@ -124,10 +120,6 @@ public void rejectAllImps(BidRejectionReason reason) {
involvedImpIds.forEach(impId -> rejectImp(impId, reason));
}

/**
* If an impression has at least one valid bid, it's not considered rejected.
* If no valid bids are returned for the impression, only the first one rejected reason will be returned
*/
public Map<String, BidRejectionReason> getRejectedImps() {
final Map<String, BidRejectionReason> rejectedImpIds = new HashMap<>();
for (String impId : involvedImpIds) {
Expand All @@ -144,9 +136,6 @@ public Map<String, BidRejectionReason> getRejectedImps() {
return rejectedImpIds;
}

/**
* Bid is absent for the non-bid code from 0 to 299
*/
public Map<String, List<Pair<BidderBid, BidRejectionReason>>> getRejectedBids() {
final Map<String, List<Pair<BidderBid, BidRejectionReason>>> missingImpIds = new HashMap<>();
for (String impId : involvedImpIds) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/prebid/server/auction/model/PaaFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.prebid.server.auction.model;

import com.fasterxml.jackson.annotation.JsonProperty;

public enum PaaFormat {

@JsonProperty("original")
ORIGINAL,

@JsonProperty("iab")
IAB
}
12 changes: 11 additions & 1 deletion src/main/java/org/prebid/server/bidder/HttpBidderRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.prebid.server.log.LoggerFactory;
import org.prebid.server.model.CaseInsensitiveMultiMap;
import org.prebid.server.proto.openrtb.ext.response.ExtHttpCall;
import org.prebid.server.proto.openrtb.ext.response.ExtIgi;
import org.prebid.server.proto.openrtb.ext.response.FledgeAuctionConfig;
import org.prebid.server.util.HttpUtil;
import org.prebid.server.vertx.httpclient.HttpClient;
Expand Down Expand Up @@ -248,7 +249,7 @@ private static byte[] gzip(byte[] value) {
*/
private <T> Future<BidderCall<T>> failResponse(Throwable exception, HttpRequest<T> httpRequest) {
conditionalLogger.warn("Error occurred while sending HTTP request to a bidder url: %s with message: %s"
.formatted(httpRequest.getUri(), exception.getMessage()), logSamplingRate);
.formatted(httpRequest.getUri(), exception.getMessage()), logSamplingRate);
logger.debug("Error occurred while sending HTTP request to a bidder url: {}",
exception, httpRequest.getUri());

Expand Down Expand Up @@ -346,6 +347,7 @@ private static class ResultBuilder<T> {
private final Map<HttpRequest<T>, BidderCall<T>> bidderCallsRecorded = new HashMap<>();
private final List<BidderBid> bidsRecorded = new ArrayList<>();
private final List<BidderError> errorsRecorded = new ArrayList<>();
private final List<ExtIgi> igiRecorded = new ArrayList<>();
private final List<FledgeAuctionConfig> fledgeRecorded = new ArrayList<>();

ResultBuilder(List<HttpRequest<T>> httpRequests,
Expand All @@ -366,6 +368,7 @@ void addHttpCall(BidderCall<T> bidderCall, CompositeBidderResponse bidderRespons
handleBids(bidderResponse);
handleBidderErrors(bidderResponse);
handleBidderCallError(bidderCall);
handleIgis(bidderResponse);
handleFledgeAuctionConfigs(bidderResponse);
}

Expand Down Expand Up @@ -429,6 +432,12 @@ private void handleFledgeAuctionConfigs(CompositeBidderResponse bidderResponse)
.ifPresent(fledgeRecorded::addAll);
}

private void handleIgis(CompositeBidderResponse bidderResponse) {
Optional.ofNullable(bidderResponse)
.map(CompositeBidderResponse::getIgi)
.ifPresent(igiRecorded::addAll);
}

BidderSeatBid toBidderSeatBid(boolean debugEnabled) {
final List<BidderCall<T>> httpCalls = new ArrayList<>(bidderCallsRecorded.values());
httpRequests.stream()
Expand All @@ -446,6 +455,7 @@ BidderSeatBid toBidderSeatBid(boolean debugEnabled) {
.bids(bidsRecorded)
.httpCalls(extHttpCalls)
.errors(errors)
.igi(igiRecorded)
.fledgeAuctionConfigs(fledgeRecorded)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequ
public CompositeBidderResponse makeBidderResponse(BidderCall<BidRequest> httpCall, BidRequest bidRequest) {
try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
final List<BidderError> bidderErrors = new ArrayList<>();
return CompositeBidderResponse.builder().bids(extractConsumableBids(bidRequest, bidResponse, bidderErrors))
.errors(bidderErrors).build();
final List<BidderError> errors = new ArrayList<>();

return CompositeBidderResponse.builder()
.bids(extractConsumableBids(bidRequest, bidResponse, errors))
.errors(errors)
.build();
} catch (DecodeException e) {
return CompositeBidderResponse.withError(BidderError.badServerResponse(e.getMessage()));
}
Expand Down
28 changes: 10 additions & 18 deletions src/main/java/org/prebid/server/bidder/criteo/CriteoBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebid;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidMeta;
import org.prebid.server.proto.openrtb.ext.response.FledgeAuctionConfig;
import org.prebid.server.proto.openrtb.ext.response.ExtIgi;
import org.prebid.server.util.BidderUtil;
import org.prebid.server.util.HttpUtil;

Expand All @@ -31,7 +31,6 @@

public class CriteoBidder implements Bidder<BidRequest> {

private static final String BIDDER_NAME = "criteo";
private final String endpointUrl;
private final JacksonMapper mapper;

Expand All @@ -55,9 +54,12 @@ public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequ
public CompositeBidderResponse makeBidderResponse(BidderCall<BidRequest> httpCall, BidRequest bidRequest) {
try {
final CriteoBidResponse bidResponse = mapper.decodeValue(
httpCall.getResponse().getBody(),
CriteoBidResponse.class);
return CompositeBidderResponse.withBids(extractBids(bidResponse), extractFledge(bidResponse));
httpCall.getResponse().getBody(), CriteoBidResponse.class);

return CompositeBidderResponse.builder()
.bids(extractBids(bidResponse))
.igi(extractIgi(bidResponse))
.build();
} catch (DecodeException | PreBidException e) {
return CompositeBidderResponse.withError(BidderError.badServerResponse(e.getMessage()));
}
Expand Down Expand Up @@ -105,21 +107,11 @@ private ObjectNode makeExt(String networkName) {
.build());
}

private static List<FledgeAuctionConfig> extractFledge(CriteoBidResponse bidResponse) {
final List<FledgeAuctionConfig> fledgeConfigs = Optional.ofNullable(bidResponse)
private static List<ExtIgi> extractIgi(CriteoBidResponse bidResponse) {
return Optional.ofNullable(bidResponse)
.map(CriteoBidResponse::getExt)
.map(CriteoExtBidResponse::getIgi)
.filter(CollectionUtils::isNotEmpty)
.orElse(Collections.emptyList())
.stream()
.filter(igi -> CollectionUtils.isNotEmpty(igi.getIgs()) && igi.getIgs().getFirst() != null)
.map(igi -> FledgeAuctionConfig.builder()
.impId(igi.getImpId())
.bidder(BIDDER_NAME)
.config(igi.getIgs().getFirst().getConfig())
.build())
.toList();

return CollectionUtils.isEmpty(fledgeConfigs) ? null : fledgeConfigs;
.orElse(Collections.emptyList());
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.prebid.server.bidder.criteo;

import lombok.Value;
import org.prebid.server.proto.openrtb.ext.response.ExtIgi;

import java.util.List;

@Value(staticConstructor = "of")
public class CriteoExtBidResponse {

List<CriteoIgiExtBidResponse> igi;
List<ExtIgi> igi;
}

This file was deleted.

This file was deleted.

23 changes: 12 additions & 11 deletions src/main/java/org/prebid/server/bidder/ix/IxBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
import org.prebid.server.proto.openrtb.ext.request.ix.ExtImpIx;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidVideo;
import org.prebid.server.proto.openrtb.ext.response.FledgeAuctionConfig;
import org.prebid.server.proto.openrtb.ext.response.ExtIgi;
import org.prebid.server.proto.openrtb.ext.response.ExtIgiIgs;
import org.prebid.server.util.BidderUtil;
import org.prebid.server.util.HttpUtil;
import org.prebid.server.util.ObjectUtil;
Expand Down Expand Up @@ -233,11 +234,12 @@ public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequ
public CompositeBidderResponse makeBidderResponse(BidderCall<BidRequest> httpCall, BidRequest bidRequest) {
try {
final IxBidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), IxBidResponse.class);
final List<BidderError> bidderErrors = new ArrayList<>();
final List<BidderError> errors = new ArrayList<>();

return CompositeBidderResponse.builder()
.bids(extractBids(bidRequest, bidResponse, bidderErrors))
.fledgeAuctionConfigs(extractFledge(bidResponse))
.errors(bidderErrors)
.bids(extractBids(bidRequest, bidResponse, errors))
.igi(extractIgi(bidResponse))
.errors(errors)
.build();
} catch (DecodeException e) {
return CompositeBidderResponse.withError(BidderError.badServerResponse(e.getMessage()));
Expand Down Expand Up @@ -406,17 +408,16 @@ private static ExtBidPrebidVideo videoInfo(ExtBidPrebidVideo extBidPrebidVideo)
: null;
}

private List<FledgeAuctionConfig> extractFledge(IxBidResponse bidResponse) {
return Optional.ofNullable(bidResponse)
private List<ExtIgi> extractIgi(IxBidResponse bidResponse) {
final List<ExtIgiIgs> igs = Optional.ofNullable(bidResponse)
.map(IxBidResponse::getExt)
.map(IxExtBidResponse::getProtectedAudienceAuctionConfigs)
.orElse(Collections.emptyList())
.stream()
.filter(Objects::nonNull)
.map(ixAuctionConfig -> FledgeAuctionConfig.builder()
.impId(ixAuctionConfig.getBidId())
.config(ixAuctionConfig.getConfig())
.build())
.map(config -> ExtIgiIgs.builder().impId(config.getBidId()).config(config.getConfig()).build())
.toList();

return igs.isEmpty() ? null : Collections.singletonList(ExtIgi.builder().igs(igs).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import org.prebid.server.json.DecodeException;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.proto.openrtb.ext.response.FledgeAuctionConfig;
import org.prebid.server.proto.openrtb.ext.response.ExtIgi;
import org.prebid.server.proto.openrtb.ext.response.ExtIgiIgs;
import org.prebid.server.util.BidderUtil;
import org.prebid.server.util.HttpUtil;

Expand Down Expand Up @@ -64,12 +65,9 @@ public final CompositeBidderResponse makeBidderResponse(BidderCall<BidRequest> h
}

final List<BidderError> errors = new ArrayList<>();
final List<BidderBid> bids = extractBids(httpCall.getRequest().getPayload(), bidResponse, errors);
final List<FledgeAuctionConfig> fledgeAuctionConfigs = extractFledge(bidResponse);

return CompositeBidderResponse.builder()
.bids(bids)
.fledgeAuctionConfigs(fledgeAuctionConfigs)
.bids(extractBids(httpCall.getRequest().getPayload(), bidResponse, errors))
.igi(extractIgi(bidResponse))
.errors(errors)
.build();
}
Expand Down Expand Up @@ -138,15 +136,17 @@ private static BidType resolveBidTypeFromImpId(String impId, List<Imp> imps) {
return BidType.banner;
}

private static List<FledgeAuctionConfig> extractFledge(MedianetBidResponse bidResponse) {
return Optional.ofNullable(bidResponse)
private static List<ExtIgi> extractIgi(MedianetBidResponse bidResponse) {
final List<ExtIgiIgs> igs = Optional.ofNullable(bidResponse)
.map(MedianetBidResponse::getExt)
.map(MedianetBidResponseExt::getIgi)
.orElse(Collections.emptyList())
.stream()
.map(InterestGroupAuctionIntent::getIgs)
.flatMap(Collection::stream)
.map(e -> FledgeAuctionConfig.builder().impId(e.getImpId()).config(e.getConfig()).build())
.map(igiIgs -> ExtIgiIgs.builder().impId(igiIgs.getImpId()).config(igiIgs.getConfig()).build())
.toList();

return igs.isEmpty() ? null : Collections.singletonList(ExtIgi.builder().igs(igs).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Value;
import org.prebid.server.bidder.Bidder;
import org.prebid.server.proto.openrtb.ext.response.ExtHttpCall;
import org.prebid.server.proto.openrtb.ext.response.ExtIgi;
import org.prebid.server.proto.openrtb.ext.response.FledgeAuctionConfig;

import java.util.Collections;
Expand Down Expand Up @@ -53,9 +54,13 @@ public class BidderSeatBid {
@Builder.Default
List<BidderError> warnings = Collections.emptyList();

@Deprecated
@Builder.Default
List<FledgeAuctionConfig> fledgeAuctionConfigs = Collections.emptyList();

@Builder.Default
List<ExtIgi> igi = Collections.emptyList();

public BidderSeatBid with(List<BidderBid> bids) {
return toBuilder().bids(bids).build();
}
Expand Down
Loading

0 comments on commit 02ab379

Please sign in to comment.