Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonValue
import groovy.transform.ToString

@ToString
enum FetchStatus {
enum AnalyticTagStatus {

NONE, SUCCESS, TIMEOUT, INPROGRESS, ERROR, SUCCESS_ALLOW, SUCCESS_BLOCK, SKIPPED, RUN

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ExtPrebidFloors {

Boolean enabled
Location location
FetchStatus fetchStatus
AnalyticTagStatus fetchStatus
Boolean skipped
Currency floorMinCur
BigDecimal floorMin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import org.prebid.server.functional.model.request.auction.FetchStatus
import org.prebid.server.functional.model.request.auction.AnalyticTagStatus
import org.prebid.server.functional.model.request.auction.Imp

import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS
import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS_BLOCK
import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS
import static org.prebid.server.functional.model.request.auction.AnalyticTagStatus.SUCCESS_BLOCK

@ToString(includeNames = true, ignoreNulls = true)
@JsonNaming(PropertyNamingStrategies.LowerCaseStrategy)
@EqualsAndHashCode
class AnalyticResult {

String name
FetchStatus status
AnalyticTagStatus status
List<ImpResult> results

static AnalyticResult buildFromImp(Imp imp) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.prebid.server.functional.model.response.auction

import com.fasterxml.jackson.annotation.JsonValue

enum AnalyticTagStatus {

NONE, LOOKUP, CONTROL, SUCCESS, ERROR, SUCCESS_ALLOW, SUCCESS_BLOCK, SKIPPED, RUN

@JsonValue
String getValue() {
name().toLowerCase().replace('_', '-')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package org.prebid.server.functional.model.response.auction
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.ToString
import org.prebid.server.functional.model.request.auction.FetchStatus
import org.prebid.server.functional.model.request.auction.AnalyticTagStatus

@ToString(includeNames = true, ignoreNulls = true)
@JsonNaming(PropertyNamingStrategies.LowerCaseStrategy)
class AnalyticsTagActivity {

ModuleActivityName name
FetchStatus status
AnalyticTagStatus status
List<AnalyticsTagActivityResult> results
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package org.prebid.server.functional.model.response.auction
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.ToString
import org.prebid.server.functional.model.request.auction.FetchStatus
import org.prebid.server.functional.model.request.auction.AnalyticTagStatus

@ToString(includeNames = true, ignoreNulls = true)
@JsonNaming(PropertyNamingStrategies.LowerCaseStrategy)
class AnalyticsTagActivityResult {

FetchStatus status
AnalyticTagStatus status
AnalyticsTagActivityValue values
AppliedTo appliedTo
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import org.prebid.server.functional.model.request.auction.FetchStatus
import org.prebid.server.functional.model.request.auction.AnalyticTagStatus

@ToString(includeNames = true, ignoreNulls = true)
@JsonNaming(PropertyNamingStrategies.LowerCaseStrategy)
@EqualsAndHashCode
class ImpResult {

FetchStatus status
AnalyticTagStatus status
ModuleValue values
AppliedTo appliedTo
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonValue

enum ModuleActivityName {

ORTB2_BLOCKING('enforce-blocking'),
PB_ORTB2_BLOCKING('enforce-blocking'),
REJECT_RICHMEDIA('reject-richmedia'),
AB_TESTING('core-module-abtests')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,84 @@ import org.prebid.server.functional.testcontainers.container.PrebidServerContain
import org.prebid.server.functional.util.SystemProperties
import org.testcontainers.images.builder.Transferable

import static org.prebid.server.functional.testcontainers.PbsServiceFactory.ContainerPolicy.GLOBAL
import static org.prebid.server.functional.testcontainers.PbsServiceFactory.ContainerPolicy.LRU
import static org.prebid.server.functional.util.SystemProperties.USE_FIXED_CONTAINER_PORTS

// TODO make container instance into a POGO and add the ability for any given container to live through stopContainers()
class PbsServiceFactory {

private static final Map<Map<String, String>, PrebidServerContainer> containers = [:]
private static final Map<Map<String, String>, PrebidServerContainer> globalContainers = [:]
private static final LinkedHashMap<Map<String, String>, PrebidServerContainer> containers = new LinkedHashMap<>(16, 0.75f, true)
private static final int MAX_CONTAINER_COUNT = maxContainerCount
private static int created
private static int reused
private static int evicted
private static final Map<Object, Integer> hits = [:].withDefault { 0 }
private static final Map<String, Integer> keyFrequency = [:].withDefault { 0 }


private final NetworkServiceContainer networkServiceContainer

PbsServiceFactory(NetworkServiceContainer networkServiceContainer) {
this.networkServiceContainer = networkServiceContainer
}

static PrebidServerService getService(Map<String, String> config, Map<String, Transferable> additionalFiles = [:]) {
if (containers.containsKey(config)) {
def container = containers.get(config)
container.refresh()
return new PrebidServerService(container)
} else {
if (containers.size() == 1 && MAX_CONTAINER_COUNT == 1) {
def container = containers.entrySet().first()
remove([(container.key): container.value])
} else if (containers.size() >= MAX_CONTAINER_COUNT) {
def container = containers.find { !it.key.isEmpty() }
remove([(container.key): container.value])
}
def pbsContainer = new PrebidServerContainer(config)
if (!additionalFiles.isEmpty()) {
additionalFiles.each { k, v -> pbsContainer.withCopyToContainer(v, k) }
}
pbsContainer.start()
containers.put(config, pbsContainer)
return new PrebidServerService(pbsContainer)
}
static {
Runtime.runtime.addShutdownHook(new Thread({
println """
PBS container stats
+++++
created = $created
reused = $reused
evicted = $evicted
cacheSize = ${containers.size()}
top containers = ${hits.sort { -it.value }.take(20)}
key frequency = ${keyFrequency.sort { -it.value }}
+++++
"""
}))
}

private static PrebidServerContainer getContainer(Map<String, String> config) {
containers.get(config)
static PrebidServerService getService(Map<String, String> config,
Map<String, Transferable> additionalFiles = [:],
ContainerPolicy policy = LRU) {
hits[config] = (hits[config] ?: 0) + 1
def existingContainer = containers.get(config) ?: globalContainers.get(config)
if (existingContainer) {
reused++
existingContainer.refresh()
return new PrebidServerService(existingContainer)
}
created++
evictIfNeeded()
def newContainer = new PrebidServerContainer(config)
additionalFiles.each { k, v ->
newContainer.withCopyToContainer(v, k)
}
newContainer.start()
if (policy == GLOBAL) {
if (globalContainers.size() < MAX_CONTAINER_COUNT) {
globalContainers.put(config, newContainer)
} else {
throw new IllegalStateException("Number of global containers is overloaded")
}
} else {
containers.put(config, newContainer)
}
config.keySet().each { key ->
keyFrequency[key] = (keyFrequency[key] ?: 0) + 1
}
return new PrebidServerService(newContainer)
}

static void stopContainers() {
def containers = containers.findAll { it.key != [:] }
remove(containers)
private static void evictIfNeeded() {
while ((containers.size() + globalContainers.size() >= MAX_CONTAINER_COUNT) && !containers.isEmpty()) {
def eldest = containers.entrySet().iterator().next()
eldest.value.stop()
containers.remove(eldest.key)
evicted ++
}
}

static void removeContainer(Map<String, String> config) {
Expand All @@ -70,4 +104,9 @@ class PbsServiceFactory {
? 1
: SystemProperties.getPropertyOrDefault("tests.max-container-count", 5)
}

enum ContainerPolicy {
GLOBAL,
LRU
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1159,9 +1159,6 @@ class AlternateBidderCodeSpec extends BaseSpec {
and: "Alert.general metric shouldn't be updated"
def metrics = pbsService.sendCollectedMetricsRequest()
assert !metrics[ADAPTER_RESPONSE_VALIDATION_METRICS.formatted(AMX)]

cleanup: "Stop and remove pbs container"
pbsServiceFactory.removeContainer(config)
}

def "PBS should discard the bid and emit a response warning when request alternate bidder codes are enabled and the allowed bidder codes doesn't match the bidder's request"() {
Expand Down Expand Up @@ -1330,9 +1327,6 @@ class AlternateBidderCodeSpec extends BaseSpec {
and: "Bidder request should be valid"
assert bidder.getBidderRequests(bidRequest.id)

cleanup: "Stop and remove pbs container"
pbsServiceFactory.removeContainer(pbsConfig)

where:
allowedBidderCodes << [BOGUS, UNKNOWN]
}
Expand Down Expand Up @@ -1387,9 +1381,6 @@ class AlternateBidderCodeSpec extends BaseSpec {
and: "PBS shouldn't emit validation metrics"
def metrics = defaultPbsService.sendCollectedMetricsRequest()
assert !metrics[ADAPTER_RESPONSE_VALIDATION_METRICS.formatted(GENERIC)]

cleanup: "Stop and remove pbs container"
pbsServiceFactory.removeContainer(pbsConfig)
}

def "PBS shouldn't discard bid when alternate bidder code allow and soft alias with case"() {
Expand Down Expand Up @@ -1574,9 +1565,6 @@ class AlternateBidderCodeSpec extends BaseSpec {
and: "PBS shouldn't emit validation metrics"
def metrics = defaultPbsService.sendCollectedMetricsRequest()
assert !metrics[ADAPTER_RESPONSE_VALIDATION_METRICS.formatted(GENERIC)]

cleanup: "Stop and remove pbs container"
pbsServiceFactory.removeContainer(pbsConfig)
}

def "PBS should populate two seat bid when different bidder response with same seat"() {
Expand Down
Loading
Loading