Skip to content

Commit

Permalink
Merge branch 'master' into remove-pg
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/org/prebid/server/auction/requestfactory/Ortb2RequestFactory.java
#	src/test/groovy/org/prebid/server/functional/service/PrebidServerService.groovy
#	src/test/groovy/org/prebid/server/functional/tests/privacy/PrivacyBaseSpec.groovy
#	src/test/java/org/prebid/server/auction/requestfactory/AmpRequestFactoryTest.java
#	src/test/java/org/prebid/server/auction/requestfactory/AuctionRequestFactoryTest.java
#	src/test/java/org/prebid/server/auction/requestfactory/Ortb2RequestFactoryTest.java
#	src/test/java/org/prebid/server/auction/requestfactory/VideoRequestFactoryTest.java
#	src/test/java/org/prebid/server/vast/VastModifierTest.java
  • Loading branch information
And1sS committed Apr 4, 2024
2 parents 7ce8520 + 37753fe commit f4b7b01
Show file tree
Hide file tree
Showing 139 changed files with 4,855 additions and 2,283 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ target/

.DS_Store

.allure/
src/main/proto/
3 changes: 3 additions & 0 deletions docs/application-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ Keep in mind following restrictions:
to `sfN.enforce` value.
- `privacy.gdpr.purpose-one-treatment-interpretation` - option that allows to skip the Purpose one enforcement workflow.
Values: ignore, no-access-allowed, access-allowed.
- `privacy.gdpr.purposes.p4.eid.require_consent` - if equals to `true`, transmitting EIDs require P4 legal basis unless excepted.
- `privacy.gdpr.purposes.p4.eid.exceptions` - list of EID sources that are excepted from P4 enforcement and will be transmitted if any P2-P10 is consented.
- `privacy.gdpr.purposes.p4.eid.activity_transition` - defaults to `true`. If `true` and transmitEids is not specified, but transmitUfpd is specified, then the logic of transmitUfpd is used. This is to avoid breaking changes to existing configurations. The default value of the flag will be changed in a future release.
- `metrics.verbosity-level` - defines verbosity level of metrics for this account, overrides `metrics.accounts` application settings configuration.
- `analytics.auction-events.<channel>` - defines which channels are supported by analytics for this account
- `analytics.modules.<module-name>.*` - space for `module-name` analytics module specific configuration, may be of any shape
Expand Down
2 changes: 1 addition & 1 deletion extra/bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.prebid</groupId>
<artifactId>prebid-server-aggregator</artifactId>
<version>2.12.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../../extra/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion extra/modules/confiant-ad-quality/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.prebid.server.hooks.modules</groupId>
<artifactId>all-modules</artifactId>
<version>2.12.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</parent>

<artifactId>confiant-ad-quality</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion extra/modules/ortb2-blocking/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.prebid.server.hooks.modules</groupId>
<artifactId>all-modules</artifactId>
<version>2.12.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</parent>

<artifactId>ortb2-blocking</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion extra/modules/pb-richmedia-filter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.prebid.server.hooks.modules</groupId>
<artifactId>all-modules</artifactId>
<version>2.12.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</parent>

<artifactId>pb-richmedia-filter</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions extra/modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.prebid</groupId>
<artifactId>prebid-server-aggregator</artifactId>
<version>2.12.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../../extra/pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -43,7 +43,7 @@
<dependency>
<groupId>org.prebid</groupId>
<artifactId>prebid-server</artifactId>
<version>2.12.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
2 changes: 1 addition & 1 deletion extra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.prebid</groupId>
<artifactId>prebid-server-aggregator</artifactId>
<version>2.12.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<scm>
Expand Down
34 changes: 7 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.prebid</groupId>
<artifactId>prebid-server-aggregator</artifactId>
<version>2.12.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath>extra/pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -57,7 +57,7 @@

<!-- test dependencies versions -->
<junit.version>4.13.2</junit.version>
<junit-jupiter.version>5.9.2</junit-jupiter.version>
<junit-jupiter.version>5.10.2</junit-jupiter.version>
<mockito.version>4.11.0</mockito.version>
<assertj.version>3.24.2</assertj.version>
<wiremock.version>2.35.1</wiremock.version>
Expand All @@ -69,7 +69,6 @@
<groovy.version>3.0.14</groovy.version>
<testcontainers.version>1.17.4</testcontainers.version>
<mockserver.version>5.14.0</mockserver.version>
<allure.version>2.19.0</allure.version>
<aspectj.version>1.9.9.1</aspectj.version>
<bytebuddy.version>1.12.14</bytebuddy.version>

Expand All @@ -84,7 +83,6 @@
<maven-failsafe-plugin.version>${maven-surefire-plugin.version}</maven-failsafe-plugin.version>
<docker-maven-plugin.version>0.40.2</docker-maven-plugin.version>
<gmavenplus-plugin.version>1.13.1</gmavenplus-plugin.version>
<allure-maven.version>2.10.0</allure-maven.version>
<skipFunctionalTests>false</skipFunctionalTests>
<skipModuleFunctionalTests>true</skipModuleFunctionalTests>
<skipUnitTests>false</skipUnitTests>
Expand Down Expand Up @@ -189,6 +187,11 @@
<artifactId>netty-transport-native-epoll</artifactId>
<classifier>linux-x86_64</classifier>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<classifier>linux-aarch_64</classifier>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down Expand Up @@ -587,12 +590,6 @@
<version>${mockserver.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-java-commons</artifactId>
<version>${allure.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -912,7 +909,6 @@
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<systemPropertyVariables>
<allure.results.directory>target/allure-results</allure.results.directory>
<mockserver.version>${mockserver.version}</mockserver.version>
<pbs.version>${project.version}</pbs.version>
<tests.max-container-count>2</tests.max-container-count>
Expand Down Expand Up @@ -956,11 +952,6 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>${allure-maven.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -985,17 +976,6 @@
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.activity.utils;
package org.prebid.server.activity;

import org.prebid.server.activity.Activity;
import io.vertx.core.logging.LoggerFactory;
import org.prebid.server.log.ConditionalLogger;
import org.prebid.server.settings.model.Account;
import org.prebid.server.settings.model.AccountPrivacyConfig;
import org.prebid.server.settings.model.activity.AccountActivityConfiguration;
Expand All @@ -14,27 +15,51 @@
import java.util.Optional;
import java.util.stream.Collectors;

public class AccountActivitiesConfigurationUtils {
public class ActivitiesConfigResolver {

private AccountActivitiesConfigurationUtils() {
private static final ConditionalLogger conditionalLogger =
new ConditionalLogger(LoggerFactory.getLogger(ActivitiesConfigResolver.class));

private final double logSamplingRate;

public ActivitiesConfigResolver(double logSamplingRate) {
this.logSamplingRate = logSamplingRate;
}

public Account resolve(Account account) {
if (!isInvalidActivitiesConfiguration(account)) {
return account;
}

conditionalLogger.warn(
"Activity configuration for account %s contains conditional rule with empty array."
.formatted(account.getId()),
logSamplingRate);

final AccountPrivacyConfig accountPrivacyConfig = account.getPrivacy();
return account.toBuilder()
.privacy(accountPrivacyConfig.toBuilder()
.activities(removeInvalidRules(accountPrivacyConfig.getActivities()))
.build())
.build();
}

public static boolean isInvalidActivitiesConfiguration(Account account) {
private static boolean isInvalidActivitiesConfiguration(Account account) {
return Optional.ofNullable(account)
.map(Account::getPrivacy)
.map(AccountPrivacyConfig::getActivities)
.stream()
.map(Map::values)
.flatMap(Collection::stream)
.anyMatch(AccountActivitiesConfigurationUtils::containsInvalidRule);
.anyMatch(ActivitiesConfigResolver::containsInvalidRule);
}

private static boolean containsInvalidRule(AccountActivityConfiguration accountActivityConfiguration) {
return Optional.ofNullable(accountActivityConfiguration)
.map(AccountActivityConfiguration::getRules)
.stream()
.flatMap(Collection::stream)
.anyMatch(AccountActivitiesConfigurationUtils::isInvalidConditionRule);
.anyMatch(ActivitiesConfigResolver::isInvalidConditionRule);
}

private static boolean isInvalidConditionRule(AccountActivityRuleConfig rule) {
Expand Down Expand Up @@ -63,13 +88,13 @@ private static <E> boolean isEmptyNotNull(Collection<E> collection) {
return collection != null && collection.isEmpty();
}

public static Map<Activity, AccountActivityConfiguration> removeInvalidRules(
private static Map<Activity, AccountActivityConfiguration> removeInvalidRules(
Map<Activity, AccountActivityConfiguration> activitiesConfiguration) {

return activitiesConfiguration.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> AccountActivitiesConfigurationUtils.removeInvalidRules(entry.getValue())));
entry -> removeInvalidRules(entry.getValue())));
}

private static AccountActivityConfiguration removeInvalidRules(AccountActivityConfiguration activityConfiguration) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.prebid.server.auction;

import com.iab.openrtb.request.Device;
import com.iab.openrtb.request.Geo;
import io.vertx.core.Future;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.auction.model.AuctionContext;
import org.prebid.server.auction.model.IpAddress;
import org.prebid.server.auction.requestfactory.Ortb2ImplicitParametersResolver;
import org.prebid.server.execution.Timeout;
import org.prebid.server.geolocation.GeoLocationService;
import org.prebid.server.geolocation.model.GeoInfo;
import org.prebid.server.metric.Metrics;
import org.prebid.server.model.HttpRequestContext;
import org.prebid.server.settings.model.Account;
import org.prebid.server.settings.model.AccountSettings;

import java.util.Objects;
import java.util.Optional;

public class GeoLocationServiceWrapper {

private static final Logger logger = LoggerFactory.getLogger(GeoLocationServiceWrapper.class);

private final GeoLocationService geoLocationService;
private final Ortb2ImplicitParametersResolver implicitParametersResolver;
private final Metrics metrics;

public GeoLocationServiceWrapper(GeoLocationService geoLocationService,
Ortb2ImplicitParametersResolver implicitParametersResolver,
Metrics metrics) {

this.geoLocationService = geoLocationService;
this.implicitParametersResolver = Objects.requireNonNull(implicitParametersResolver);
this.metrics = Objects.requireNonNull(metrics);
}

//todo: account settings will work as expected if the default account resolving refactoring is done
public Future<GeoInfo> lookup(AuctionContext auctionContext) {
final Account account = auctionContext.getAccount();
final Device device = auctionContext.getBidRequest().getDevice();
final HttpRequestContext requestContext = auctionContext.getHttpRequest();
final Timeout timeout = auctionContext.getTimeoutContext().getTimeout();

final boolean isGeoLookupEnabled = Optional.ofNullable(account.getSettings())
.map(AccountSettings::getGeoLookup)
.map(BooleanUtils::isTrue)
.orElse(false);

return isGeoLookupEnabled
? doLookup(getIpAddress(device, requestContext), getCountry(device), timeout).otherwiseEmpty()
: Future.succeededFuture();
}

public Future<GeoInfo> doLookup(String ipAddress, String requestCountry, Timeout timeout) {
if (geoLocationService == null || ipAddress == null || StringUtils.isNotBlank(requestCountry)) {
return Future.failedFuture("Geolocation lookup is skipped");
}
return geoLocationService.lookup(ipAddress, timeout)
.onSuccess(geoInfo -> metrics.updateGeoLocationMetric(true))
.onFailure(this::logError);
}

private String getCountry(Device device) {
return Optional.ofNullable(device)
.map(Device::getGeo)
.map(Geo::getCountry)
.filter(StringUtils::isNotBlank)
.orElse(null);
}

private String getIpAddress(Device device, HttpRequestContext request) {
final Optional<Device> optionalDevice = Optional.ofNullable(device);
return optionalDevice.map(Device::getIp)
.filter(StringUtils::isNotBlank)
.or(() -> optionalDevice
.map(Device::getIpv6)
.filter(StringUtils::isNotBlank))
.or(() -> ipFromHeader(request))
.orElse(null);
}

private Optional<String> ipFromHeader(HttpRequestContext request) {
final IpAddress headerIp = implicitParametersResolver.findIpFromRequest(request);
return Optional.ofNullable(headerIp)
.map(IpAddress::getIp);
}

private void logError(Throwable error) {
final String message = "Geolocation lookup failed: " + error.getMessage();
logger.warn(message);
logger.debug(message, error);

metrics.updateGeoLocationMetric(false);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.auction.gpp;

import io.vertx.core.Future;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.auction.gpp.model.GppContext;
import org.prebid.server.auction.gpp.model.GppContextCreator;
import org.prebid.server.auction.gpp.model.GppContextWrapper;
Expand Down Expand Up @@ -44,7 +45,7 @@ private static GppContextWrapper contextFrom(PrivacyContext privacyContext) {

private static Integer toInt(String string) {
try {
return string != null ? Integer.parseInt(string) : null;
return StringUtils.isNotBlank(string) ? Integer.parseInt(string) : null;
} catch (NumberFormatException e) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class AuctionContext {

ActivityInfrastructure activityInfrastructure;

@JsonIgnore
GeoInfo geoInfo;

HookExecutionContext hookExecutionContext;
Expand Down Expand Up @@ -115,6 +116,12 @@ public AuctionContext with(DebugContext debugContext) {
.build();
}

public AuctionContext with(GeoInfo geoInfo) {
return this.toBuilder()
.geoInfo(geoInfo)
.build();
}

public AuctionContext withRequestRejected() {
return this.toBuilder()
.requestRejected(true)
Expand Down
Loading

0 comments on commit f4b7b01

Please sign in to comment.