Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/config-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ For HTTP data source available next options:
- `settings.http.rfc3986-compatible` - if equals to `true` the url will be build according to RFC 3986, `false` by default

For account processing rules available next options:
- `settings.enforce-valid-account` - if equals to `true` then request without account id will be rejected with 401.
- `settings.enforce-valid-account` - if equals to `true` then request without account id will be rejection with 401.
- `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.

It is possible to specify default account configuration values that will be assumed if account config have them
Expand Down
4 changes: 2 additions & 2 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Following metrics are collected and submitted if account is configured with `bas
Following metrics are collected and submitted if account is configured with `detailed` verbosity:
- `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
- `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)
- `account.<account-id>.requests.rejected` - number of rejected requests caused by incorrect `accountId`
- `account.<account-id>.requests.rejection` - number of rejection requests caused by incorrect `accountId`
- `account.<account-id>.requests.disabled_bidder` - number of disabled bidders received within requests from account with `<account-id>`
- `account.<account-id>.requests.unknown_bidder` - number of unknown bidder names received within requests from account with `<account-id>`
- `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>`
Expand Down Expand Up @@ -140,7 +140,7 @@ Following metrics are collected and submitted if account is configured with `det
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).ok` - number of succeeded processed event requests
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).timeout` - number of event requests, failed with timeout cause
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).err` - number of event requests, failed with errors
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).badinput` - number of event requests, rejected with bad input cause
- `analytics.<reporter-name>.(auction|amp|video|cookie_sync|event|setuid).badinput` - number of event requests, rejection with bad input cause

## Modules metrics
- `modules.module.<module>.stage.<stage>.hook.<hook>.call` - number of times the hook is called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.prebid.server.geolocation.CountryCodeMapper;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.FilterService;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.GreenbidsInferenceDataService;
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.GreenbidsInvocationService;
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;
Expand Down Expand Up @@ -48,16 +47,14 @@ GreenbidsInferenceDataService greenbidsInferenceDataService(DatabaseReaderFactor
GreenbidsRealTimeDataModule greenbidsRealTimeDataModule(
FilterService filterService,
OnnxModelRunnerWithThresholds onnxModelRunnerWithThresholds,
GreenbidsInferenceDataService greenbidsInferenceDataService,
GreenbidsInvocationService greenbidsInvocationService) {
GreenbidsInferenceDataService greenbidsInferenceDataService) {

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

@Bean
Expand Down Expand Up @@ -123,15 +120,7 @@ ThresholdCache thresholdCache(
}

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

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,86 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.core;

import com.fasterxml.jackson.databind.JsonNode;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.analytics.reporter.greenbids.model.ExplorationResult;
import org.prebid.server.analytics.reporter.greenbids.model.Ortb2ImpExtResult;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.data.GreenbidsConfig;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.result.AnalyticsResult;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.result.GreenbidsInvocationResult;
import org.prebid.server.hooks.v1.InvocationAction;

import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

public class GreenbidsInvocationResultCreator {

private static final int RANGE_16_BIT_INTEGER_DIVISION_BASIS = 0x10000;
private static final double DEFAULT_EXPLORATION_RATE = 1.0;

private GreenbidsInvocationResultCreator() {

}

public static GreenbidsInvocationResult create(GreenbidsConfig greenbidsConfig,
BidRequest bidRequest,
Map<String, Map<String, Boolean>> impsBiddersFilterMap) {

final String greenbidsId = UUID.randomUUID().toString();
final boolean isExploration = isExploration(greenbidsConfig, greenbidsId);

final boolean allRejected = bidRequest.getImp().stream()
.noneMatch(imp -> impsBiddersFilterMap.get(imp.getId()).values().stream().anyMatch(isKept -> isKept));

final InvocationAction invocationAction = isExploration
? InvocationAction.no_action
: allRejected
? InvocationAction.reject
: InvocationAction.update;

final Map<String, Ortb2ImpExtResult> ort2ImpExtResultMap = createOrtb2ImpExtForImps(
bidRequest, impsBiddersFilterMap, greenbidsId, isExploration);
final AnalyticsResult analyticsResult = AnalyticsResult.of("success", ort2ImpExtResultMap);
return GreenbidsInvocationResult.of(invocationAction, analyticsResult);
}

private static boolean isExploration(GreenbidsConfig greenbidsConfig, String greenbidsId) {
final double explorationRate = ObjectUtils.defaultIfNull(
greenbidsConfig.getExplorationRate(),
DEFAULT_EXPLORATION_RATE);
final int hashInt = Integer.parseInt(greenbidsId.substring(greenbidsId.length() - 4), 16);
return hashInt < explorationRate * RANGE_16_BIT_INTEGER_DIVISION_BASIS;
}

private static Map<String, Ortb2ImpExtResult> createOrtb2ImpExtForImps(
BidRequest bidRequest,
Map<String, Map<String, Boolean>> impsBiddersFilterMap,
String greenbidsId,
boolean isExploration) {

return bidRequest.getImp().stream()
.collect(Collectors.toMap(
Imp::getId,
imp -> createOrtb2ImpExt(imp, impsBiddersFilterMap, greenbidsId, isExploration)));
}

private static Ortb2ImpExtResult createOrtb2ImpExt(Imp imp,
Map<String, Map<String, Boolean>> impsBiddersFilterMap,
String greenbidsId,
boolean isExploration) {

final String tid = Optional.ofNullable(imp)
.map(Imp::getExt)
.map(impExt -> impExt.get("tid"))
.map(JsonNode::asText)
.orElse(StringUtils.EMPTY);
final Map<String, Boolean> impBiddersFilterMap = impsBiddersFilterMap.get(imp.getId());
final ExplorationResult explorationResult = ExplorationResult.of(
greenbidsId, impBiddersFilterMap, isExploration);
return Ortb2ImpExtResult.of(explorationResult, tid);
}
}

This file was deleted.

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

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;

import java.util.List;
import java.util.Map;
import java.util.Optional;

public class GreenbidsPayloadUpdater {

private GreenbidsPayloadUpdater() {

}

public static BidRequest update(BidRequest bidRequest, Map<String, Map<String, Boolean>> impsBiddersFilterMap) {
return bidRequest.toBuilder()
.imp(updateImps(bidRequest, impsBiddersFilterMap))
.build();
}

private static List<Imp> updateImps(BidRequest bidRequest, Map<String, Map<String, Boolean>> impsBiddersFilterMap) {
return bidRequest.getImp().stream()
.filter(imp -> isImpKept(impsBiddersFilterMap.get(imp.getId())))
.map(imp -> updateImp(imp, impsBiddersFilterMap.get(imp.getId())))
.toList();
}

private static boolean isImpKept(Map<String, Boolean> bidderFilterMap) {
return bidderFilterMap.values().stream().anyMatch(isKept -> isKept);
}

private static Imp updateImp(Imp imp, Map<String, Boolean> bidderFilterMap) {
return imp.toBuilder()
.ext(updateImpExt(imp.getExt(), bidderFilterMap))
.build();
}

private static ObjectNode updateImpExt(ObjectNode impExt, Map<String, Boolean> bidderFilterMap) {
final ObjectNode updatedExt = impExt.deepCopy();
Optional.ofNullable((ObjectNode) updatedExt.get("prebid"))
.map(prebidNode -> (ObjectNode) prebidNode.get("bidder"))
.ifPresent(bidderNode ->
bidderFilterMap.entrySet().stream()
.filter(entry -> !entry.getValue())
.map(Map.Entry::getKey)
.forEach(bidderNode::remove));
return updatedExt;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.model.result;

import com.iab.openrtb.request.BidRequest;
import lombok.Value;
import org.prebid.server.hooks.v1.InvocationAction;

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

BidRequest updatedBidRequest;

InvocationAction invocationAction;

AnalyticsResult analyticsResult;
Expand Down
Loading
Loading