Skip to content
Open
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
7 changes: 5 additions & 2 deletions src/main/java/org/prebid/server/cache/CoreCacheService.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,12 @@ public Future<BidCacheResponse> cachePutObjects(List<BidPutObject> bidPutObjects
Boolean isEventsEnabled,
Set<String> biddersAllowingVastUpdate,
String accountId,
Integer accountTtl,
String integration,
Timeout timeout) {

final List<CachedCreative> cachedCreatives =
updatePutObjects(bidPutObjects, isEventsEnabled, biddersAllowingVastUpdate, accountId, integration);
final List<CachedCreative> cachedCreatives = updatePutObjects(
bidPutObjects, isEventsEnabled, biddersAllowingVastUpdate, accountId, accountTtl, integration);

updateCreativeMetrics(accountId, cachedCreatives);

Expand All @@ -226,6 +227,7 @@ private List<CachedCreative> updatePutObjects(List<BidPutObject> bidPutObjects,
Boolean isEventsEnabled,
Set<String> allowedBidders,
String accountId,
Integer accountTtl,
String integration) {

return bidPutObjects.stream()
Expand All @@ -240,6 +242,7 @@ private List<CachedCreative> updatePutObjects(List<BidPutObject> bidPutObjects,
putObject,
accountId,
integration))
.ttlseconds(ObjectUtils.min(putObject.getTtlseconds(), accountTtl))
.build())
.map(payload -> CachedCreative.of(payload, creativeSizeFromTextNode(payload.getValue())))
.toList();
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/prebid/server/handler/PostVtrackHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
import org.prebid.server.settings.model.Account;
import org.prebid.server.settings.model.AccountAuctionConfig;
import org.prebid.server.settings.model.AccountEventsConfig;
import org.prebid.server.settings.model.AccountVtrackConfig;
import org.prebid.server.util.HttpUtil;
import org.prebid.server.vertx.verticles.server.HttpEndpoint;
import org.prebid.server.vertx.verticles.server.application.ApplicationResource;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -180,10 +182,12 @@ private void handleAccountResult(AsyncResult<Account> asyncAccount,
respondWithServerError(routingContext, "Error occurred while fetching account", asyncAccount.cause());
} else {
// insert impression tracking if account allows events and bidder allows VAST modification
final Boolean isEventEnabled = accountEventsEnabled(asyncAccount.result());
final Account account = asyncAccount.result();
final Boolean isEventEnabled = accountEventsEnabled(account);
final Integer accountTtl = accountVtrackTtl(account);
final Set<String> allowedBidders = biddersAllowingVastUpdate(vtrackPuts);
coreCacheService.cachePutObjects(
vtrackPuts, isEventEnabled, allowedBidders, accountId, integration, timeout)
vtrackPuts, isEventEnabled, allowedBidders, accountId, accountTtl, integration, timeout)
.onComplete(asyncCache -> handleCacheResult(asyncCache, routingContext));
}
}
Expand All @@ -196,6 +200,12 @@ private static Boolean accountEventsEnabled(Account account) {
return accountEventsConfig != null ? accountEventsConfig.getEnabled() : null;
}

private static Integer accountVtrackTtl(Account account) {
return Optional.ofNullable(account.getVtrack())
.map(AccountVtrackConfig::getTtl)
.orElse(null);
}

/**
* Returns list of bidders that allow VAST XML modification.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/prebid/server/settings/model/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class Account {
@JsonAlias("alternate-bidder-codes")
AccountAlternateBidderCodes alternateBidderCodes;

AccountVtrackConfig vtrack;

public static Account empty(String id) {
return Account.builder().id(id).build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.prebid.server.settings.model;

import lombok.Builder;
import lombok.Value;

@Builder(toBuilder = true)
@Value
public class AccountVtrackConfig {

Integer ttl;
}
102 changes: 99 additions & 3 deletions src/test/java/org/prebid/server/cache/CoreCacheServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ public void cacheBidsOpenrtbShouldRemoveCatDurPrefixFromVideoUuidFromResponse()
public void cachePutObjectsShouldTolerateGlobalTimeoutAlreadyExpired() {
// when
final Future<BidCacheResponse> future = target.cachePutObjects(
singletonList(BidPutObject.builder().build()), true, emptySet(), "", "",
singletonList(BidPutObject.builder().build()), true, emptySet(), "", 100, "",
expiredTimeout);

// then
Expand All @@ -797,7 +797,7 @@ public void cachePutObjectsShouldTolerateGlobalTimeoutAlreadyExpired() {
public void cachePutObjectsShouldReturnResultWithEmptyListWhenPutObjectsIsEmpty() {
// when
final Future<BidCacheResponse> result = target.cachePutObjects(emptyList(), true,
emptySet(), null, null, null);
emptySet(), null, 100, null, null);

// then
verifyNoInteractions(httpClient);
Expand Down Expand Up @@ -847,6 +847,7 @@ public void cachePutObjectsShouldCacheObjects() throws IOException {
true,
singleton("bidder1"),
"account",
null,
"pbjs",
timeout);

Expand Down Expand Up @@ -888,6 +889,94 @@ public void cachePutObjectsShouldCacheObjects() throws IOException {
.containsExactly(modifiedFirstBidPutObject, modifiedSecondBidPutObject, modifiedThirdBidPutObject);
}

@Test
public void cachePutObjectsShouldCacheObjectsWithTtlDefinedAsMinBetweenRequestAndAccountTtl() throws IOException {
// given
final BidPutObject firstBidPutObject = BidPutObject.builder()
.type("json")
.bidid("bidId1")
.bidder("bidder1")
.timestamp(1L)
.value(new TextNode("vast"))
.ttlseconds(99)
.build();
final BidPutObject secondBidPutObject = BidPutObject.builder()
.type("xml")
.bidid("bidId2")
.bidder("bidder2")
.timestamp(1L)
.value(new TextNode("VAST"))
.ttlseconds(null)
.build();
final BidPutObject thirdBidPutObject = BidPutObject.builder()
.type("text")
.bidid("bidId3")
.bidder("bidder3")
.timestamp(1L)
.value(new TextNode("VAST"))
.ttlseconds(101)
.build();

given(vastModifier.modifyVastXml(any(), any(), any(), any(), anyString()))
.willReturn(new TextNode("modifiedVast"))
.willReturn(new TextNode("VAST"))
.willReturn(new TextNode("updatedVast"));

given(httpClient.post(anyString(), any(), any(), anyLong())).willReturn(Future.succeededFuture(
HttpClientResponse.of(200, null, mapper.writeValueAsString(BidCacheResponse.of(
List.of(CacheObject.of("uuid1"), CacheObject.of("uuid2"), CacheObject.of("uuid3")))))));

// when
target.cachePutObjects(
asList(firstBidPutObject, secondBidPutObject, thirdBidPutObject),
true,
singleton("bidder1"),
"account",
100,
"pbjs",
timeout);

// then
verify(httpClient).post(eq("http://cache-service/cache"), any(), any(), anyLong());

verify(metrics).updateCacheCreativeSize(eq("account"), eq(12), eq(MetricName.json));
verify(metrics).updateCacheCreativeSize(eq("account"), eq(4), eq(MetricName.xml));
verify(metrics).updateCacheCreativeSize(eq("account"), eq(11), eq(MetricName.unknown));

verify(metrics).updateCacheCreativeTtl(eq("account"), eq(99), eq(MetricName.json));
verify(metrics).updateCacheCreativeTtl(eq("account"), eq(100), eq(MetricName.xml));
verify(metrics).updateCacheCreativeTtl(eq("account"), eq(100), eq(MetricName.unknown));

verify(metrics).updateVtrackCacheWriteRequestTime(eq("account"), anyLong(), eq(MetricName.ok));

verify(vastModifier).modifyVastXml(true, singleton("bidder1"), firstBidPutObject, "account", "pbjs");
verify(vastModifier).modifyVastXml(true, singleton("bidder1"), secondBidPutObject, "account", "pbjs");

final BidPutObject modifiedFirstBidPutObject = firstBidPutObject.toBuilder()
.bidid(null)
.bidder(null)
.timestamp(null)
.value(new TextNode("modifiedVast"))
.ttlseconds(99)
.build();
final BidPutObject modifiedSecondBidPutObject = secondBidPutObject.toBuilder()
.bidid(null)
.bidder(null)
.timestamp(null)
.ttlseconds(100)
.build();
final BidPutObject modifiedThirdBidPutObject = thirdBidPutObject.toBuilder()
.bidid(null)
.bidder(null)
.timestamp(null)
.value(new TextNode("updatedVast"))
.ttlseconds(100)
.build();

assertThat(captureBidCacheRequest().getPuts())
.containsExactly(modifiedFirstBidPutObject, modifiedSecondBidPutObject, modifiedThirdBidPutObject);
}

@Test
public void cachePutObjectsShouldLogErrorMetricsWhenStatusCodeIsNotOk() {
// given
Expand All @@ -914,6 +1003,7 @@ public void cachePutObjectsShouldLogErrorMetricsWhenStatusCodeIsNotOk() {
true,
singleton("bidder1"),
"account",
100,
"pbjs",
timeout);

Expand Down Expand Up @@ -950,6 +1040,7 @@ public void cachePutObjectsShouldNotLogErrorMetricsWhenCacheServiceIsNotConnecte
true,
singleton("bidder1"),
"account",
100,
"pbjs",
timeout);

Expand Down Expand Up @@ -993,7 +1084,7 @@ public void cachePutObjectsShouldCallInternalCacheEndpointWhenProvided() throws
.willReturn(new TextNode("modifiedVast"));

// when
target.cachePutObjects(asList(firstBidPutObject), true, singleton("bidder1"), "account", "pbjs", timeout);
target.cachePutObjects(asList(firstBidPutObject), true, singleton("bidder1"), "account", 100, "pbjs", timeout);

// then
verify(httpClient).post(eq("http://cache-service-internal/cache"), any(), any(), anyLong());
Expand Down Expand Up @@ -1046,6 +1137,7 @@ public void cachePutObjectsShouldUseApiKeyWhenProvided() throws MalformedURLExce
true,
singleton("bidder1"),
"account",
100,
"pbjs",
timeout);

Expand Down Expand Up @@ -1281,6 +1373,7 @@ public void cachePutObjectsShouldPrependTraceInfoWhenEnabled() throws IOExceptio
true,
singleton("bidder1"),
"account",
null,
"pbjs",
timeout);

Expand Down Expand Up @@ -1329,6 +1422,7 @@ public void cachePutObjectsShouldPrependTraceInfoWithDatacenterWhenEnabled() thr
true,
singleton("bidder1"),
"account",
null,
"pbjs",
timeout);

Expand Down Expand Up @@ -1376,6 +1470,7 @@ public void cachePutObjectsShouldNotPrependTraceInfoToPassedInKey() throws IOExc
true,
singleton("bidder1"),
"account",
null,
"pbjs",
timeout);

Expand Down Expand Up @@ -1435,6 +1530,7 @@ public void cachePutObjectsShouldNotEmitEmptyTtlMetrics() {
true,
singleton("bidder1"),
"account",
null,
"pbjs",
timeout);

Expand Down
Loading