Skip to content

Commit ae10a63

Browse files
Core: Support seatnonbid Codes in Modules (prebid#3762)
1 parent b890fef commit ae10a63

62 files changed

Lines changed: 1538 additions & 1385 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/config-app.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ For HTTP data source available next options:
349349
- `settings.http.rfc3986-compatible` - if equals to `true` the url will be build according to RFC 3986, `false` by default
350350

351351
For account processing rules available next options:
352-
- `settings.enforce-valid-account` - if equals to `true` then request without account id will be rejected with 401.
352+
- `settings.enforce-valid-account` - if equals to `true` then request without account id will be rejection with 401.
353353
- `settings.generate-storedrequest-bidrequest-id` - overrides `bidrequest.id` in amp or app stored request with generated UUID if true. Default value is false. This flag can be overridden by setting `bidrequest.id` as `{{UUID}}` placeholder directly in stored request.
354354

355355
It is possible to specify default account configuration values that will be assumed if account config have them

docs/metrics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Following metrics are collected and submitted if account is configured with `bas
9393
Following metrics are collected and submitted if account is configured with `detailed` verbosity:
9494
- `account.<account-id>.requests.type.(openrtb2-web,openrtb-app,amp,legacy)` - number of requests received from account with `<account-id>` broken down by type of incoming request
9595
- `account.<account-id>.debug_requests` - number of requests received from account with `<account-id>` broken down by type of incoming request (when debug mode is enabled)
96-
- `account.<account-id>.requests.rejected` - number of rejected requests caused by incorrect `accountId`
96+
- `account.<account-id>.requests.rejection` - number of rejection requests caused by incorrect `accountId`
9797
- `account.<account-id>.requests.disabled_bidder` - number of disabled bidders received within requests from account with `<account-id>`
9898
- `account.<account-id>.requests.unknown_bidder` - number of unknown bidder names received within requests from account with `<account-id>`
9999
- `account.<account-id>.adapter.<bidder-name>.request_time` - timer tracking how long did it take to make a request to `<bidder-name>` when incoming request was from `<account-id>`
@@ -140,7 +140,7 @@ Following metrics are collected and submitted if account is configured with `det
140140
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).ok` - number of succeeded processed event requests
141141
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).timeout` - number of event requests, failed with timeout cause
142142
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).err` - number of event requests, failed with errors
143-
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).badinput` - number of event requests, rejected with bad input cause
143+
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).badinput` - number of event requests, rejection with bad input cause
144144

145145
## Modules metrics
146146
- `modules.module.<module>.stage.<stage>.hook.<hook>.call` - number of times the hook is called

extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/config/GreenbidsRealTimeDataConfiguration.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.prebid.server.geolocation.CountryCodeMapper;
99
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.FilterService;
1010
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.GreenbidsInferenceDataService;
11-
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.GreenbidsInvocationService;
1211
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.ModelCache;
1312
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.OnnxModelRunner;
1413
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.OnnxModelRunnerFactory;
@@ -48,16 +47,14 @@ GreenbidsInferenceDataService greenbidsInferenceDataService(DatabaseReaderFactor
4847
GreenbidsRealTimeDataModule greenbidsRealTimeDataModule(
4948
FilterService filterService,
5049
OnnxModelRunnerWithThresholds onnxModelRunnerWithThresholds,
51-
GreenbidsInferenceDataService greenbidsInferenceDataService,
52-
GreenbidsInvocationService greenbidsInvocationService) {
50+
GreenbidsInferenceDataService greenbidsInferenceDataService) {
5351

5452
return new GreenbidsRealTimeDataModule(List.of(
5553
new GreenbidsRealTimeDataProcessedAuctionRequestHook(
5654
ObjectMapperProvider.mapper(),
5755
filterService,
5856
onnxModelRunnerWithThresholds,
59-
greenbidsInferenceDataService,
60-
greenbidsInvocationService)));
57+
greenbidsInferenceDataService)));
6158
}
6259

6360
@Bean
@@ -123,15 +120,7 @@ ThresholdCache thresholdCache(
123120
}
124121

125122
@Bean
126-
OnnxModelRunnerWithThresholds onnxModelRunnerWithThresholds(
127-
ModelCache modelCache,
128-
ThresholdCache thresholdCache) {
129-
123+
OnnxModelRunnerWithThresholds onnxModelRunnerWithThresholds(ModelCache modelCache, ThresholdCache thresholdCache) {
130124
return new OnnxModelRunnerWithThresholds(modelCache, thresholdCache);
131125
}
132-
133-
@Bean
134-
GreenbidsInvocationService greenbidsInvocationService() {
135-
return new GreenbidsInvocationService();
136-
}
137126
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.prebid.server.hooks.modules.greenbids.real.time.data.core;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.iab.openrtb.request.BidRequest;
5+
import com.iab.openrtb.request.Imp;
6+
import org.apache.commons.lang3.ObjectUtils;
7+
import org.apache.commons.lang3.StringUtils;
8+
import org.prebid.server.analytics.reporter.greenbids.model.ExplorationResult;
9+
import org.prebid.server.analytics.reporter.greenbids.model.Ortb2ImpExtResult;
10+
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.data.GreenbidsConfig;
11+
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.result.AnalyticsResult;
12+
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.result.GreenbidsInvocationResult;
13+
import org.prebid.server.hooks.v1.InvocationAction;
14+
15+
import java.util.Map;
16+
import java.util.Optional;
17+
import java.util.UUID;
18+
import java.util.stream.Collectors;
19+
20+
public class GreenbidsInvocationResultCreator {
21+
22+
private static final int RANGE_16_BIT_INTEGER_DIVISION_BASIS = 0x10000;
23+
private static final double DEFAULT_EXPLORATION_RATE = 1.0;
24+
25+
private GreenbidsInvocationResultCreator() {
26+
27+
}
28+
29+
public static GreenbidsInvocationResult create(GreenbidsConfig greenbidsConfig,
30+
BidRequest bidRequest,
31+
Map<String, Map<String, Boolean>> impsBiddersFilterMap) {
32+
33+
final String greenbidsId = UUID.randomUUID().toString();
34+
final boolean isExploration = isExploration(greenbidsConfig, greenbidsId);
35+
36+
final boolean allRejected = bidRequest.getImp().stream()
37+
.noneMatch(imp -> impsBiddersFilterMap.get(imp.getId()).values().stream().anyMatch(isKept -> isKept));
38+
39+
final InvocationAction invocationAction = isExploration
40+
? InvocationAction.no_action
41+
: allRejected
42+
? InvocationAction.reject
43+
: InvocationAction.update;
44+
45+
final Map<String, Ortb2ImpExtResult> ort2ImpExtResultMap = createOrtb2ImpExtForImps(
46+
bidRequest, impsBiddersFilterMap, greenbidsId, isExploration);
47+
final AnalyticsResult analyticsResult = AnalyticsResult.of("success", ort2ImpExtResultMap);
48+
return GreenbidsInvocationResult.of(invocationAction, analyticsResult);
49+
}
50+
51+
private static boolean isExploration(GreenbidsConfig greenbidsConfig, String greenbidsId) {
52+
final double explorationRate = ObjectUtils.defaultIfNull(
53+
greenbidsConfig.getExplorationRate(),
54+
DEFAULT_EXPLORATION_RATE);
55+
final int hashInt = Integer.parseInt(greenbidsId.substring(greenbidsId.length() - 4), 16);
56+
return hashInt < explorationRate * RANGE_16_BIT_INTEGER_DIVISION_BASIS;
57+
}
58+
59+
private static Map<String, Ortb2ImpExtResult> createOrtb2ImpExtForImps(
60+
BidRequest bidRequest,
61+
Map<String, Map<String, Boolean>> impsBiddersFilterMap,
62+
String greenbidsId,
63+
boolean isExploration) {
64+
65+
return bidRequest.getImp().stream()
66+
.collect(Collectors.toMap(
67+
Imp::getId,
68+
imp -> createOrtb2ImpExt(imp, impsBiddersFilterMap, greenbidsId, isExploration)));
69+
}
70+
71+
private static Ortb2ImpExtResult createOrtb2ImpExt(Imp imp,
72+
Map<String, Map<String, Boolean>> impsBiddersFilterMap,
73+
String greenbidsId,
74+
boolean isExploration) {
75+
76+
final String tid = Optional.ofNullable(imp)
77+
.map(Imp::getExt)
78+
.map(impExt -> impExt.get("tid"))
79+
.map(JsonNode::asText)
80+
.orElse(StringUtils.EMPTY);
81+
final Map<String, Boolean> impBiddersFilterMap = impsBiddersFilterMap.get(imp.getId());
82+
final ExplorationResult explorationResult = ExplorationResult.of(
83+
greenbidsId, impBiddersFilterMap, isExploration);
84+
return Ortb2ImpExtResult.of(explorationResult, tid);
85+
}
86+
}

extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/core/GreenbidsInvocationService.java

Lines changed: 0 additions & 122 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.prebid.server.hooks.modules.greenbids.real.time.data.core;
2+
3+
import com.fasterxml.jackson.databind.node.ObjectNode;
4+
import com.iab.openrtb.request.BidRequest;
5+
import com.iab.openrtb.request.Imp;
6+
7+
import java.util.List;
8+
import java.util.Map;
9+
import java.util.Optional;
10+
11+
public class GreenbidsPayloadUpdater {
12+
13+
private GreenbidsPayloadUpdater() {
14+
15+
}
16+
17+
public static BidRequest update(BidRequest bidRequest, Map<String, Map<String, Boolean>> impsBiddersFilterMap) {
18+
return bidRequest.toBuilder()
19+
.imp(updateImps(bidRequest, impsBiddersFilterMap))
20+
.build();
21+
}
22+
23+
private static List<Imp> updateImps(BidRequest bidRequest, Map<String, Map<String, Boolean>> impsBiddersFilterMap) {
24+
return bidRequest.getImp().stream()
25+
.filter(imp -> isImpKept(impsBiddersFilterMap.get(imp.getId())))
26+
.map(imp -> updateImp(imp, impsBiddersFilterMap.get(imp.getId())))
27+
.toList();
28+
}
29+
30+
private static boolean isImpKept(Map<String, Boolean> bidderFilterMap) {
31+
return bidderFilterMap.values().stream().anyMatch(isKept -> isKept);
32+
}
33+
34+
private static Imp updateImp(Imp imp, Map<String, Boolean> bidderFilterMap) {
35+
return imp.toBuilder()
36+
.ext(updateImpExt(imp.getExt(), bidderFilterMap))
37+
.build();
38+
}
39+
40+
private static ObjectNode updateImpExt(ObjectNode impExt, Map<String, Boolean> bidderFilterMap) {
41+
final ObjectNode updatedExt = impExt.deepCopy();
42+
Optional.ofNullable((ObjectNode) updatedExt.get("prebid"))
43+
.map(prebidNode -> (ObjectNode) prebidNode.get("bidder"))
44+
.ifPresent(bidderNode ->
45+
bidderFilterMap.entrySet().stream()
46+
.filter(entry -> !entry.getValue())
47+
.map(Map.Entry::getKey)
48+
.forEach(bidderNode::remove));
49+
return updatedExt;
50+
}
51+
}

extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/model/result/GreenbidsInvocationResult.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package org.prebid.server.hooks.modules.greenbids.real.time.data.model.result;
22

3-
import com.iab.openrtb.request.BidRequest;
43
import lombok.Value;
54
import org.prebid.server.hooks.v1.InvocationAction;
65

76
@Value(staticConstructor = "of")
87
public class GreenbidsInvocationResult {
98

10-
BidRequest updatedBidRequest;
11-
129
InvocationAction invocationAction;
1310

1411
AnalyticsResult analyticsResult;

0 commit comments

Comments
 (0)