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

Merged
merged 104 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
9b1ad18
Add Greenbids RTD Module
Jun 13, 2024
365ffe6
fix module pom.xml
Jun 13, 2024
c50cdf9
removed checkstyle for debug
Jun 13, 2024
2330cc2
extract features to throttling msg
Jun 17, 2024
6ecf56e
enable module
Jun 17, 2024
2f0dfbd
add onnx fetch predictor + inference
Jun 18, 2024
9fec373
check inference time
Jun 19, 2024
9f3ae93
update impExt.prebid.bidder from filtering
Jun 24, 2024
cc06cfb
invocation result: update bid request
Jun 26, 2024
14b5584
filtering: fix update imp ext
Jun 26, 2024
2ba7148
transfer greenbidsId in ATag between RTD and analytics adapter
Jul 1, 2024
bf49512
add exploration
Jul 11, 2024
5c6cc54
add exploration
EvgeniiMunin Jul 12, 2024
c1eff9f
add exploration ortb2imp
EvgeniiMunin Jul 12, 2024
e62d8f7
user agent features: browser, device, country
EvgeniiMunin Jul 17, 2024
fa04b81
push artefacts
EvgeniiMunin Jul 29, 2024
5998ea8
model per publisher + model cache
Jul 31, 2024
3258a4b
fetch gcs + model cache + auth partners
Aug 1, 2024
54207fd
mutex reentrantlock
EvgeniiMunin Aug 2, 2024
73ad272
fixes comments JB
Aug 8, 2024
59fdd98
UT RTD
Aug 19, 2024
5b00be1
refacto
Aug 20, 2024
734cb48
refacto after rebase
Aug 20, 2024
21a7617
pbrichmedia remove changes
Aug 20, 2024
07f4274
refactos
Aug 21, 2024
6b89c6a
analytics delegator privacy action
Aug 21, 2024
49d5772
remove checkstyle from rtd module pom.xml
Aug 21, 2024
eaf9f34
modif prebid exception on geolite
Aug 21, 2024
4e09bc6
remove debug changes
Aug 22, 2024
28b9374
refactos code style
Aug 22, 2024
164509f
refacto codestyle
Aug 22, 2024
863fe0f
refacto: reorder methods in call order
Aug 22, 2024
d0ebb33
fix review
Aug 26, 2024
5d026ca
fix review1: pom 3.11.0
Aug 26, 2024
12b19d9
fix review1: cache remove lock + async
Aug 27, 2024
f56c33f
fix review1: refacto hook call
Aug 28, 2024
35ab867
fix review1: config + cache atomic bool flag
Aug 28, 2024
66216ef
fix review1: partner/ throttling thrs constructors
Aug 29, 2024
27036d5
fix review2: refactos
Aug 30, 2024
9be6a49
fix review2: classes to beans + codestyle
Sep 2, 2024
70f1e4e
fix review2: vertx executeBlocking
Sep 3, 2024
f6b3e91
fix review2: handle bucket null
Sep 3, 2024
5ebb019
fix review3: chain vertx + refacto
Sep 5, 2024
715b702
fix review3: refactos
Sep 6, 2024
e68294c
fix review3: refactos
Sep 6, 2024
5d17552
pbs 3.12
Sep 6, 2024
9b1a40e
fix review4: refactos
EvgeniiMunin Sep 9, 2024
993edf1
fix review4: inferenceData to Bean
EvgeniiMunin Sep 10, 2024
4f64452
fix review4: fmt
EvgeniiMunin Sep 10, 2024
51a59da
fix review4: modelcache thrcache as bean
EvgeniiMunin Sep 11, 2024
4ac7823
fix review4: fmt get methods
EvgeniiMunin Sep 11, 2024
b56ddc6
fix review4: checkstyle
EvgeniiMunin Sep 12, 2024
c1e96e0
fix review4: dbreader to bean
EvgeniiMunin Sep 14, 2024
a58650f
fix review4: autowired dbReader bean
EvgeniiMunin Sep 16, 2024
f737c57
fix review4: remove service annotation on greenbidsInfData
EvgeniiMunin Sep 16, 2024
b7daae2
fix review5: refactos
EvgeniiMunin Sep 17, 2024
d5eadb1
fix review5: refactos fields non null check
EvgeniiMunin Sep 17, 2024
d764274
fix review5: GreenbidsInvocationService + to bean
EvgeniiMunin Sep 17, 2024
37ed2c4
fix review6: ObjectMapperProvider
EvgeniiMunin Sep 20, 2024
827b8d6
fix review6: refactos
EvgeniiMunin Sep 20, 2024
bebabc5
fix review6: private final fields in services
EvgeniiMunin Sep 23, 2024
2a589be
fix review6: refactos
EvgeniiMunin Sep 23, 2024
e47f5a6
fix review6: refactos
EvgeniiMunin Sep 23, 2024
e17f623
fix review6: mapper dbReader field access
EvgeniiMunin Sep 23, 2024
d1a4c4a
fix review6: validate OnnxTensor ThrMsgs
EvgeniiMunin Sep 24, 2024
10f2c99
fix review6: pom 3.13.0
EvgeniiMunin Sep 24, 2024
474c137
fix review6: remove checkstyle from module pom
EvgeniiMunin Sep 24, 2024
04558a3
fix review7: refactos
EvgeniiMunin Sep 25, 2024
ccc4ea2
fix review7: refactos analytics
EvgeniiMunin Sep 25, 2024
2a4fa0e
fix review7: refactor extractAnalyticsResultFromAnalyticsTag
EvgeniiMunin Sep 25, 2024
6b5c83d
fix review7: add new unit tests
EvgeniiMunin Oct 3, 2024
f6fce9f
fix review8: refactos
EvgeniiMunin Oct 3, 2024
abc6ac9
fix review8: ExtendWith annotation UT
EvgeniiMunin Oct 3, 2024
bd1326e
fix review8: refacto methods to TestBidRequestProvider
EvgeniiMunin Oct 3, 2024
4517c8b
fix review8: refactos
EvgeniiMunin Oct 3, 2024
83fd05e
fix review9: refactos
EvgeniiMunin Oct 7, 2024
1da4995
fix review9: refactos
EvgeniiMunin Oct 7, 2024
d63f44f
fix review9: ModelCacheTest debug
EvgeniiMunin Oct 8, 2024
a8c5c5e
fix review9: refactos
EvgeniiMunin Oct 8, 2024
632573b
fix review9: add test on validateOnnxTensor
EvgeniiMunin Oct 8, 2024
03923d3
fix review9: fix UT
EvgeniiMunin Oct 9, 2024
571669b
fix review9: fix/ debug ModelCacheTest
EvgeniiMunin Oct 9, 2024
eb14cab
fix review9: Model/ThresholdCacheTest debug
EvgeniiMunin Oct 14, 2024
f6e2314
fix review9: OnnxModelRunnerTest
EvgeniiMunin Oct 14, 2024
0557452
fix review9: fmt ThresholdCacheTest
EvgeniiMunin Oct 15, 2024
311cf5d
fix review9: rebase pom 3.14.0
EvgeniiMunin Oct 15, 2024
d62a195
fix review10: TU lenient storage bucket blob factory
EvgeniiMunin Oct 15, 2024
40e6f4e
fix review10: refactos
EvgeniiMunin Oct 15, 2024
c7f2398
fix review10: move tests
EvgeniiMunin Oct 15, 2024
3a237e3
fix review10: refacto mapper
EvgeniiMunin Oct 15, 2024
981564d
fix review10: refacto mapper TestBidRequestProvider
EvgeniiMunin Oct 16, 2024
7f69965
fix review10: rearrange classes
EvgeniiMunin Oct 16, 2024
196065b
fix review10: fix test device w/o user agent
EvgeniiMunin Oct 16, 2024
bcb7d72
fix review10: move classes packaging
EvgeniiMunin Oct 16, 2024
c0320b9
fix review11: refactos
EvgeniiMunin Oct 24, 2024
43fd9f3
fix review11: rebase master pom 3.15.0
EvgeniiMunin Oct 24, 2024
9fb28a5
fix review11: future.all
EvgeniiMunin Oct 24, 2024
75ddb9b
fix review11: remove local geolite mmdb
EvgeniiMunin Oct 25, 2024
fe102c8
fix review11: no changes prebid-config
EvgeniiMunin Oct 25, 2024
3ae2516
fix review12: analytics reporter fix
EvgeniiMunin Nov 5, 2024
8dfdcdb
fix review12: dbReaderFactory
EvgeniiMunin Nov 5, 2024
4850c60
fix review12: dbReaderFactory
EvgeniiMunin Nov 5, 2024
d4c22a5
fix review12: hookExecutionOutcome
EvgeniiMunin Nov 7, 2024
703010e
fix review12: fmt
EvgeniiMunin Nov 7, 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 @@ -45,6 +45,11 @@
<artifactId>pb-response-correction</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.15.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,55 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.config;

import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import com.maxmind.geoip2.DatabaseReader;
import org.prebid.server.exception.PreBidException;
import org.prebid.server.vertx.Initializable;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicReference;

public class DatabaseReaderFactory implements Initializable {

private final String geoLiteCountryUrl;

private final Vertx vertx;

private final AtomicReference<DatabaseReader> databaseReaderRef = new AtomicReference<>();

public DatabaseReaderFactory(String geoLitCountryUrl, Vertx vertx) {
this.geoLiteCountryUrl = geoLitCountryUrl;
this.vertx = vertx;
}

@Override
public void initialize(Promise<Void> initializePromise) {

vertx.executeBlocking(() -> {
try {
final URL url = new URL(geoLiteCountryUrl);
final Path databasePath = Files.createTempFile("GeoLite2-Country", ".mmdb");

try (InputStream inputStream = url.openStream();
FileOutputStream outputStream = new FileOutputStream(databasePath.toFile())) {
inputStream.transferTo(outputStream);
}

databaseReaderRef.set(new DatabaseReader.Builder(databasePath.toFile()).build());
} catch (IOException e) {
throw new PreBidException("Failed to initialize DatabaseReader from URL", e);
}
return null;
}).<Void>mapEmpty()
.onComplete(initializePromise);
}

public DatabaseReader getDatabaseReader() {
return databaseReaderRef.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.config;

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 io.vertx.core.Vertx;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.filter.ThrottlingThresholds;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.ThrottlingThresholdsFactory;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.GreenbidsInferenceDataService;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.FilterService;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.ModelCache;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.OnnxModelRunner;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.OnnxModelRunnerFactory;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.OnnxModelRunnerWithThresholds;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.ThresholdCache;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.GreenbidsInvocationService;
import org.prebid.server.hooks.modules.greenbids.real.time.data.v1.GreenbidsRealTimeDataProcessedAuctionRequestHook;
import org.prebid.server.json.ObjectMapperProvider;
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.util.List;
import java.util.concurrent.TimeUnit;

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

@Bean
DatabaseReaderFactory databaseReaderFactory(GreenbidsRealTimeDataProperties properties, Vertx vertx) {
return new DatabaseReaderFactory(properties.getGeoLiteCountryPath(), vertx);
}

@Bean
GreenbidsInferenceDataService greenbidsInferenceDataService(DatabaseReaderFactory databaseReaderFactory) {
return new GreenbidsInferenceDataService(
databaseReaderFactory, ObjectMapperProvider.mapper());
}

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

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

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

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

@Bean
OnnxModelRunnerFactory onnxModelRunnerFactory() {
return new OnnxModelRunnerFactory();
}

@Bean
ThrottlingThresholdsFactory throttlingThresholdsFactory() {
return new ThrottlingThresholdsFactory();
}

@Bean
ModelCache modelCache(
GreenbidsRealTimeDataProperties properties,
Vertx vertx,
Storage storage,
OnnxModelRunnerFactory onnxModelRunnerFactory) {

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

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

@Bean
ThresholdCache thresholdCache(
GreenbidsRealTimeDataProperties properties,
Vertx vertx,
Storage storage,
ThrottlingThresholdsFactory throttlingThresholdsFactory) {

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

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

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

return new OnnxModelRunnerWithThresholds(modelCache, thresholdCache);
}

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

import org.prebid.server.hooks.v1.Hook;
import org.prebid.server.hooks.v1.InvocationContext;
import org.prebid.server.hooks.v1.Module;

import java.util.Collection;
import java.util.List;

public class GreenbidsRealTimeDataModule implements Module {

public static final String CODE = "greenbids-real-time-data";

private final List<? extends Hook<?, ? extends InvocationContext>> hooks;

public GreenbidsRealTimeDataModule(List<? extends Hook<?, ? extends InvocationContext>> hooks) {
this.hooks = hooks;
}

@Override
public String code() {
return CODE;
}

@Override
public Collection<? extends Hook<?, ? extends InvocationContext>> hooks() {
return hooks;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.config;

import lombok.Data;
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