Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/java/org/prebid/server/auction/BidResponseCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,15 @@ private Bid toBid(BidInfo bidInfo,
final String categoryDuration = bidInfo.getCategory();
targetingKeywords = keywordsCreator != null
? keywordsCreator.makeFor(
bid, seat, isWinningBid, cacheId, bidType.getName(), videoCacheId, categoryDuration, account)
bid,
seat,
isWinningBid,
cacheId,
bidType.getName(),
videoCacheId,
categoryDuration,
account,
bidWarnings)
: null;
} else {
targetingKeywords = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.iab.openrtb.response.Bid;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.bidder.model.BidderError;
import org.prebid.server.proto.openrtb.ext.request.ExtPriceGranularity;
import org.prebid.server.proto.openrtb.ext.response.ExtBidderError;
import org.prebid.server.settings.model.Account;

import java.math.BigDecimal;
Expand All @@ -12,7 +14,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Used throughout Prebid to create targeting keys as keys which can be used in an ad server like DFP.
Expand Down Expand Up @@ -154,7 +155,8 @@ Map<String, String> makeFor(Bid bid,
String format,
String vastCacheId,
String categoryDuration,
Account account) {
Account account,
Map<String, List<ExtBidderError>> bidWarnings) {

final Map<String, String> keywords = makeFor(
bidder,
Expand All @@ -170,13 +172,13 @@ Map<String, String> makeFor(Bid bid,
account);

if (resolver == null) {
return truncateKeys(keywords);
return truncateKeys(keywords, bidWarnings);
}

final Map<String, String> augmentedKeywords = new HashMap<>(keywords);
augmentedKeywords.putAll(resolver.resolve(bid, bidder));

return truncateKeys(augmentedKeywords);
return truncateKeys(augmentedKeywords, bidWarnings);
}

/**
Expand Down Expand Up @@ -261,12 +263,33 @@ private static String sizeFrom(Integer width, Integer height) {
: null;
}

private Map<String, String> truncateKeys(Map<String, String> keyValues) {
return truncateAttrChars > 0
? keyValues.entrySet().stream()
.collect(Collectors
.toMap(keyValue -> truncateKey(keyValue.getKey()), Map.Entry::getValue, (key1, key2) -> key1))
: keyValues;
private Map<String, String> truncateKeys(Map<String, String> keyValues,
Map<String, List<ExtBidderError>> bidWarnings) {

if (truncateAttrChars <= 0) {
return keyValues;
}

final Map<String, String> keys = new HashMap<>();
final List<String> truncatedKeys = new ArrayList<>();
for (Map.Entry<String, String> entry : keyValues.entrySet()) {
final String key = entry.getKey();
final String truncatedKey = truncateKey(key);
keys.putIfAbsent(truncatedKey, entry.getValue());

if (truncatedKey.length() != key.length()) {
truncatedKeys.add(key);
}
}

if (!truncatedKeys.isEmpty()) {
final String errorMessage = "The following keys have been truncated: %s"
.formatted(String.join(", ", truncatedKeys));
bidWarnings.computeIfAbsent("targeting", ignored -> new ArrayList<>())
.add(ExtBidderError.of(BidderError.Type.bad_input.getCode(), errorMessage));
}

return keys;
}

private String truncateKey(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,9 @@ LIMIT 1
"currency-converter.external-rates.refresh-period-ms" : "900000"]
}

static Map<String,String> getTargetingConfig() {
["settings.targeting.truncate-attr-chars": '255']
}

private PbsConfig() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PrebidServerContainer extends GenericContainer<PrebidServerContainer> {
<< PbsConfig.bidderAliasConfig
<< PbsConfig.prebidCacheConfig
<< PbsConfig.mySqlConfig
<< PbsConfig.targetingConfig
withConfig(commonConfig)
withConfig(customConfig)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class CacheSpec extends BaseSpec {
private static final String PBS_API_HEADER = 'x-pbc-api-key'
private static final Integer MAX_DATACENTER_REGION_LENGTH = 4
private static final Integer DEFAULT_UUID_LENGTH = 36
private static final Integer TARGETING_PARAM_NAME_MAX_LENGTH = 20

private static final String XML_CREATIVE_SIZE_ACCOUNT_METRIC = "account.%s.prebid_cache.creative_size.xml"
private static final String JSON_CREATIVE_SIZE_ACCOUNT_METRIC = "account.%s.prebid_cache.creative_size.json"
Expand Down Expand Up @@ -612,8 +611,8 @@ class CacheSpec extends BaseSpec {
it.get("hb_cache_id_generic")
it.get("hb_cache_path") == CACHE_PATH
it.get("hb_cache_host") == CACHE_HOST
it.get("hb_cache_path_generic".substring(0, TARGETING_PARAM_NAME_MAX_LENGTH)) == CACHE_PATH
it.get("hb_cache_host_generic".substring(0, TARGETING_PARAM_NAME_MAX_LENGTH)) == CACHE_HOST
it.get("hb_cache_path_generic") == CACHE_PATH
it.get("hb_cache_host_generic") == CACHE_HOST
}

and: "Debug should contain http call"
Expand Down Expand Up @@ -648,8 +647,8 @@ class CacheSpec extends BaseSpec {
it.get("hb_cache_id_generic")
it.get("hb_cache_path") == INTERNAL_CACHE_PATH
it.get("hb_cache_host") == networkServiceContainer.hostAndPort.toString()
it.get("hb_cache_path_generic".substring(0, TARGETING_PARAM_NAME_MAX_LENGTH)) == INTERNAL_CACHE_PATH
it.get("hb_cache_host_generic".substring(0, TARGETING_PARAM_NAME_MAX_LENGTH)) == networkServiceContainer.hostAndPort.toString()
it.get("hb_cache_path_generic") == INTERNAL_CACHE_PATH
it.get("hb_cache_host_generic") == networkServiceContainer.hostAndPort.toString()
}

and: "Debug should contain http call"
Expand Down
Loading
Loading