Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Greenbids Real Time Data Module #3242

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
45487f5
Add Greenbids RTD Module
Jun 13, 2024
fdf1675
fix module pom.xml
Jun 13, 2024
12d3a38
removed checkstyle for debug
Jun 13, 2024
aacfc75
extract features to throttling msg
Jun 17, 2024
a6e186c
enable module
Jun 17, 2024
1129f54
add onnx fetch predictor + inference
Jun 18, 2024
98072d7
check inference time
Jun 19, 2024
6337038
update impExt.prebid.bidder from filtering
Jun 24, 2024
c1fe21c
invocation result: update bid request
Jun 26, 2024
a1b1053
filtering: fix update imp ext
Jun 26, 2024
00bf68a
transfer greenbidsId in ATag between RTD and analytics adapter
Jul 1, 2024
506b543
add exploration
Jul 11, 2024
58194f3
add exploration
EvgeniiMunin Jul 12, 2024
b54e110
add exploration ortb2imp
EvgeniiMunin Jul 12, 2024
1b3b345
user agent features: browser, device, country
EvgeniiMunin Jul 17, 2024
13172eb
push artefacts
EvgeniiMunin Jul 29, 2024
1ad610b
model per publisher + model cache
Jul 31, 2024
be35b90
fetch gcs + model cache + auth partners
Aug 1, 2024
efa7884
mutex reentrantlock
EvgeniiMunin Aug 2, 2024
c088214
fixes comments JB
Aug 8, 2024
6aba91f
UT RTD
Aug 19, 2024
65e84a7
refacto
Aug 20, 2024
cc7bd72
refacto after rebase
Aug 20, 2024
ea4cae1
pbrichmedia remove changes
Aug 20, 2024
4dee3a4
refactos
Aug 21, 2024
4f493fc
analytics delegator privacy action
Aug 21, 2024
efb7a85
remove checkstyle from rtd module pom.xml
Aug 21, 2024
2be5c45
modif prebid exception on geolite
Aug 21, 2024
c203581
remove debug changes
Aug 22, 2024
b4d799a
refactos code style
Aug 22, 2024
f11746c
refacto codestyle
Aug 22, 2024
2f31de6
refacto: reorder methods in call order
Aug 22, 2024
a6e3575
fix review
Aug 26, 2024
7ae32c3
fix review1: pom 3.11.0
Aug 26, 2024
50bfa42
fix review1: cache remove lock + async
Aug 27, 2024
afdd329
fix review1: refacto hook call
Aug 28, 2024
ed0ec21
fix review1: config + cache atomic bool flag
Aug 28, 2024
4d26883
fix review1: partner/ throttling thrs constructors
Aug 29, 2024
51d5a3a
fix review2: refactos
Aug 30, 2024
61eccd9
fix review2: classes to beans + codestyle
Sep 2, 2024
3b9cf17
fix review2: vertx executeBlocking
Sep 3, 2024
2c4c8cd
fix review2: handle bucket null
Sep 3, 2024
746be10
fix review3: chain vertx + refacto
Sep 5, 2024
a3213b1
fix review3: refactos
Sep 6, 2024
7fb5141
fix review3: refactos
Sep 6, 2024
1084568
pbs 3.12
Sep 6, 2024
c651bfe
fix review4: refactos
EvgeniiMunin Sep 9, 2024
e64154c
fix review4: inferenceData to Bean
EvgeniiMunin Sep 10, 2024
8bfea6b
fix review4: fmt
EvgeniiMunin Sep 10, 2024
f8cd600
fix review4: modelcache thrcache as bean
EvgeniiMunin Sep 11, 2024
992b6a4
fix review4: fmt get methods
EvgeniiMunin Sep 11, 2024
8a3284d
fix review4: checkstyle
EvgeniiMunin Sep 12, 2024
6c9f0ab
fix review4: dbreader to bean
EvgeniiMunin Sep 14, 2024
09fc5b5
fix review4: autowired dbReader bean
EvgeniiMunin Sep 16, 2024
6a5c816
fix review4: remove service annotation on greenbidsInfData
EvgeniiMunin Sep 16, 2024
f7dea5b
fix review5: refactos
EvgeniiMunin Sep 17, 2024
6cfed69
fix review5: refactos fields non null check
EvgeniiMunin Sep 17, 2024
bfe17db
fix review5: GreenbidsInvocationService + to bean
EvgeniiMunin Sep 17, 2024
1578264
fix review6: ObjectMapperProvider
EvgeniiMunin Sep 20, 2024
a417de5
fix review6: refactos
EvgeniiMunin Sep 20, 2024
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
5 changes: 5 additions & 0 deletions extra/bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<artifactId>pb-richmedia-filter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.prebid.server.hooks.modules</groupId>
<artifactId>greenbids-real-time-data</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
37 changes: 37 additions & 0 deletions extra/modules/greenbids-real-time-data/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.prebid.server.hooks.modules</groupId>
<artifactId>all-modules</artifactId>
<version>3.12.0-SNAPSHOT</version>
</parent>

<artifactId>greenbids-real-time-data</artifactId>

<name>greenbids-real-time-data</name>
<description>Greenbids Real Time Data</description>

<dependencies>
<dependency>
<groupId>com.github.ua-parser</groupId>
<artifactId>uap-java</artifactId>
<version>1.6.1</version>
</dependency>

<dependency>
<groupId>com.microsoft.onnxruntime</groupId>
<artifactId>onnxruntime</artifactId>
<version>1.16.1</version> <!-- Use the latest available version -->
</dependency>

<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.41.0</version>
</dependency>
</dependencies>

</project>
1 change: 1 addition & 0 deletions extra/modules/greenbids-real-time-data/src/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.anyConstructor.addConstructorProperties = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import com.maxmind.geoip2.DatabaseReader;
import io.vertx.core.Vertx;
import org.prebid.server.exception.PreBidException;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.ThrottlingThresholds;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.config.GreenbidsRealTimeDataProperties;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.data.GreenbidsInferenceDataService;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.predictor.FilterService;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.predictor.ModelCache;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.predictor.OnnxModelRunner;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.predictor.OnnxModelRunnerWithThresholds;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.predictor.ThresholdCache;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.result.GreenbidsInvocationService;
import org.prebid.server.hooks.modules.greenbids.real.time.data.v1.GreenbidsRealTimeDataModule;
import org.prebid.server.hooks.modules.greenbids.real.time.data.v1.GreenbidsRealTimeDataProcessedAuctionRequestHook;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;

@ConditionalOnProperty(prefix = "hooks." + GreenbidsRealTimeDataModule.CODE, name = "enabled", havingValue = "true")
@Configuration
@EnableConfigurationProperties(GreenbidsRealTimeDataProperties.class)
public class GreenbidsRealTimeDataConfiguration {

@Bean
public DatabaseReader dbReader(GreenbidsRealTimeDataProperties properties) {
final File database = new File(properties.getGeoLiteCountryPath());
try {
return new DatabaseReader.Builder(database).build();
} catch (IOException e) {
throw new PreBidException("Failed build DatabaseReader from DB", e);
}
}

@Bean
public GreenbidsInferenceDataService greenbidsInferenceDataService(
DatabaseReader dbReader,
ObjectMapper mapper) {
EvgeniiMunin marked this conversation as resolved.
Show resolved Hide resolved
return new GreenbidsInferenceDataService(dbReader, mapper);
}

@Bean
GreenbidsRealTimeDataModule greenbidsRealTimeDataModule(
FilterService filterService,
OnnxModelRunnerWithThresholds onnxModelRunnerWithThresholds,
GreenbidsInferenceDataService greenbidsInferenceDataService,
ObjectMapper mapper,
GreenbidsInvocationService greenbidsInvocationService) {

return new GreenbidsRealTimeDataModule(List.of(
new GreenbidsRealTimeDataProcessedAuctionRequestHook(
mapper,
filterService,
onnxModelRunnerWithThresholds,
greenbidsInferenceDataService,
greenbidsInvocationService)));
}

@Bean
public FilterService filterService() {
return new FilterService();
}

@Bean
public Storage storage(GreenbidsRealTimeDataProperties properties) {
return StorageOptions.newBuilder()
.setProjectId(properties.getGoogleCloudGreenbidsProject()).build().getService();
}

@Bean
public ModelCache modelCache(GreenbidsRealTimeDataProperties properties, Vertx vertx, Storage storage) {
final Cache<String, OnnxModelRunner> modelCacheWithExpiration = Caffeine.newBuilder()
.expireAfterWrite(properties.getCacheExpirationMinutes(), TimeUnit.MINUTES)
.build();

return new ModelCache(
storage,
properties.getGcsBucketName(),
modelCacheWithExpiration,
properties.getOnnxModelCacheKeyPrefix(),
vertx);
}

@Bean
public ThresholdCache thresholdCache(
GreenbidsRealTimeDataProperties properties,
Vertx vertx,
Storage storage,
ObjectMapper mapper) {

final Cache<String, ThrottlingThresholds> thresholdsCacheWithExpiration = Caffeine.newBuilder()
.expireAfterWrite(properties.getCacheExpirationMinutes(), TimeUnit.MINUTES)
.build();

return new ThresholdCache(
storage,
properties.getGcsBucketName(),
mapper,
thresholdsCacheWithExpiration,
properties.getThresholdsCacheKeyPrefix(),
vertx);
}

@Bean
public OnnxModelRunnerWithThresholds onnxModelRunnerWithThresholds(
ModelCache modelCache,
ThresholdCache thresholdCache) {

return new OnnxModelRunnerWithThresholds(modelCache, thresholdCache);
}

@Bean
public GreenbidsInvocationService greenbidsInvocationService() {
return new GreenbidsInvocationService();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.core;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Value;

import java.util.Comparator;
import java.util.List;

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

String pbuid;

@JsonProperty("targetTpr")
Double targetTpr;

@JsonProperty("explorationRate")
Double explorationRate;

public Double getThreshold(ThrottlingThresholds throttlingThresholds) {
final List<Double> truePositiveRates = throttlingThresholds.getTpr();
final List<Double> thresholds = throttlingThresholds.getThresholds();

return truePositiveRates.stream()
.filter(truePositiveRate -> truePositiveRate >= targetTpr)
.map(truePositiveRate -> thresholds.get(truePositiveRates.indexOf(truePositiveRate)))
.max(Comparator.naturalOrder())
.orElse(0.0);
Comment on lines +24 to +28
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            return IntStream.range(0, truePositiveRates.size())
                    .filter(i -> truePositiveRates.get(i) >= targetTpr)
                    .mapToObj(thresholds::get)
                    .max(Comparator.naturalOrder())
                    .orElse(0.0);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is IndexOutOfBound possible there?

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.core;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Value;

import java.util.List;

@Value(staticConstructor = "of")
@JsonIgnoreProperties(ignoreUnknown = true)
EvgeniiMunin marked this conversation as resolved.
Show resolved Hide resolved
public class ThrottlingThresholds {

List<Double> thresholds;

List<Double> tpr;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.model.config;

import lombok.Data;
import org.prebid.server.hooks.modules.greenbids.real.time.data.v1.GreenbidsRealTimeDataModule;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "hooks.modules." + GreenbidsRealTimeDataModule.CODE)
@Data
public class GreenbidsRealTimeDataProperties {

String googleCloudGreenbidsProject;

String geoLiteCountryPath;

String gcsBucketName;

Integer cacheExpirationMinutes;

String onnxModelCacheKeyPrefix;

String thresholdsCacheKeyPrefix;
}
Loading
Loading