Skip to content

Commit

Permalink
Merge branch 'master' into vidoomy/add_new_bidder
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Nahornyi committed Feb 11, 2022
2 parents c5d9f48 + 0207639 commit 697b230
Show file tree
Hide file tree
Showing 133 changed files with 5,354 additions and 367 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
<mockito-junit-jupiter.version>4.0.0</mockito-junit-jupiter.version>
<assertj.version>3.21.0</assertj.version>
<wiremock.version>2.31.0</wiremock.version>
<awaitility.version>4.1.0</awaitility.version>
<awaitility.version>4.1.1</awaitility.version>
<jetty.version>9.4.44.v20210927</jetty.version>
<restassured.version>4.4.0</restassured.version>
<h2.version>2.1.210</h2.version>
<spock.version>2.0-groovy-3.0</spock.version>
<testcontainers.version>1.16.2</testcontainers.version>
<testcontainers.version>1.16.3</testcontainers.version>
<mockserver-client.version>5.11.2</mockserver-client.version>
<allure.version>2.16.1</allure.version>
<allure.version>2.17.2</allure.version>
<aspectj.version>1.9.7</aspectj.version>
<h2.version>1.4.200</h2.version>
<bytebuddy.version>1.11.19</bytebuddy.version>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.prebid.server.analytics;
package org.prebid.server.analytics.reporter;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand All @@ -11,6 +11,7 @@
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import org.apache.commons.collections4.CollectionUtils;
import org.prebid.server.analytics.AnalyticsReporter;
import org.prebid.server.analytics.model.AmpEvent;
import org.prebid.server.analytics.model.AuctionEvent;
import org.prebid.server.analytics.model.CookieSyncEvent;
Expand Down Expand Up @@ -59,6 +60,7 @@ public AnalyticsReporterDelegator(List<AnalyticsReporter> delegates,
Vertx vertx,
PrivacyEnforcementService privacyEnforcementService,
Metrics metrics) {

this.delegates = Objects.requireNonNull(delegates);
this.vertx = Objects.requireNonNull(vertx);
this.privacyEnforcementService = Objects.requireNonNull(privacyEnforcementService);
Expand All @@ -82,6 +84,7 @@ public <T> void processEvent(T event, TcfContext tcfContext) {
private <T> void delegateEvent(T event,
TcfContext tcfContext,
AsyncResult<Map<Integer, PrivacyEnforcementAction>> privacyEnforcementMapResult) {

if (privacyEnforcementMapResult.succeeded()) {
final Map<Integer, PrivacyEnforcementAction> privacyEnforcementActionMap =
privacyEnforcementMapResult.result();
Expand Down Expand Up @@ -150,6 +153,7 @@ private static <T> T updateEvent(T event, String adapter) {
return event;
}

@SuppressWarnings("ConstantConditions")
private static AuctionContext updateAuctionContextAdapter(AuctionContext context, String adapter) {
final BidRequest bidRequest = context != null ? context.getBidRequest() : null;
final BidRequest updatedBidRequest = updateBidRequest(bidRequest, adapter);
Expand Down Expand Up @@ -215,21 +219,23 @@ private <T> Future<Void> processFail(Throwable exception, T event, String report

private <T> void updateMetricsByEventType(T event, String analyticsCode, MetricName result) {
final MetricName eventType;
if (event instanceof AuctionEvent) {
eventType = MetricName.event_auction;
} else if (event instanceof AmpEvent) {

if (event instanceof AmpEvent) {
eventType = MetricName.event_amp;
} else if (event instanceof VideoEvent) {
eventType = MetricName.event_video;
} else if (event instanceof SetuidEvent) {
eventType = MetricName.event_setuid;
} else if (event instanceof AuctionEvent) {
eventType = MetricName.event_auction;
} else if (event instanceof CookieSyncEvent) {
eventType = MetricName.event_cookie_sync;
} else if (event instanceof NotificationEvent) {
eventType = MetricName.event_notification;
} else if (event instanceof SetuidEvent) {
eventType = MetricName.event_setuid;
} else if (event instanceof VideoEvent) {
eventType = MetricName.event_video;
} else {
eventType = MetricName.event_unknown;
}

metrics.updateAnalyticEventMetric(analyticsCode, eventType, result);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.prebid.server.analytics;
package org.prebid.server.analytics.reporter.log;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import io.vertx.core.Future;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import lombok.AllArgsConstructor;
import lombok.Value;
import org.prebid.server.analytics.AnalyticsReporter;
import org.prebid.server.analytics.model.AmpEvent;
import org.prebid.server.analytics.model.AuctionEvent;
import org.prebid.server.analytics.model.CookieSyncEvent;
import org.prebid.server.analytics.model.NotificationEvent;
import org.prebid.server.analytics.model.SetuidEvent;
import org.prebid.server.analytics.model.VideoEvent;
import org.prebid.server.analytics.reporter.log.model.LogEvent;
import org.prebid.server.json.JacksonMapper;

import java.util.Objects;
Expand All @@ -32,21 +32,24 @@ public LogAnalyticsReporter(JacksonMapper mapper) {
public <T> Future<Void> processEvent(T event) {
final LogEvent<?> logEvent;

if (event instanceof AuctionEvent) {
logEvent = new LogEvent<>("/openrtb2/auction", ((AuctionEvent) event).getBidResponse());
} else if (event instanceof AmpEvent) {
logEvent = new LogEvent<>("/openrtb2/amp", ((AmpEvent) event).getBidResponse());
} else if (event instanceof VideoEvent) {
logEvent = new LogEvent<>("/openrtb2/video", ((VideoEvent) event).getBidResponse());
if (event instanceof AmpEvent) {
logEvent = LogEvent.of("/openrtb2/amp", ((AmpEvent) event).getBidResponse());
} else if (event instanceof AuctionEvent) {
logEvent = LogEvent.of("/openrtb2/auction", ((AuctionEvent) event).getBidResponse());
} else if (event instanceof CookieSyncEvent) {
logEvent = LogEvent.of("/cookie_sync", ((CookieSyncEvent) event).getBidderStatus());
} else if (event instanceof NotificationEvent) {
final NotificationEvent notificationEvent = (NotificationEvent) event;
logEvent = LogEvent.of("/event", notificationEvent.getType() + notificationEvent.getBidId());
} else if (event instanceof SetuidEvent) {
final SetuidEvent setuidEvent = (SetuidEvent) event;
logEvent = new LogEvent<>(
logEvent = LogEvent.of(
"/setuid",
setuidEvent.getBidder() + ":" + setuidEvent.getUid() + ":" + setuidEvent.getSuccess());
} else if (event instanceof CookieSyncEvent) {
logEvent = new LogEvent<>("/cookie_sync", ((CookieSyncEvent) event).getBidderStatus());
} else if (event instanceof VideoEvent) {
logEvent = LogEvent.of("/openrtb2/video", ((VideoEvent) event).getBidResponse());
} else {
logEvent = new LogEvent<>("unknown", null);
logEvent = LogEvent.of("unknown", null);
}

logger.debug(mapper.encodeToString(logEvent));
Expand All @@ -63,14 +66,4 @@ public int vendorId() {
public String name() {
return "logAnalytics";
}

@AllArgsConstructor
@Value
private static class LogEvent<T> {

String type;

@JsonUnwrapped
T event;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.prebid.server.analytics.reporter.log.model;

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

@Value(staticConstructor = "of")
public class LogEvent<T> {

String type;

@JsonUnwrapped
T event;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.prebid.server.analytics.pubstack;
package org.prebid.server.analytics.reporter.pubstack;

import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
Expand All @@ -11,11 +11,12 @@
import org.prebid.server.analytics.model.AmpEvent;
import org.prebid.server.analytics.model.AuctionEvent;
import org.prebid.server.analytics.model.CookieSyncEvent;
import org.prebid.server.analytics.model.NotificationEvent;
import org.prebid.server.analytics.model.SetuidEvent;
import org.prebid.server.analytics.model.VideoEvent;
import org.prebid.server.analytics.pubstack.model.EventType;
import org.prebid.server.analytics.pubstack.model.PubstackAnalyticsProperties;
import org.prebid.server.analytics.pubstack.model.PubstackConfig;
import org.prebid.server.analytics.reporter.pubstack.model.EventType;
import org.prebid.server.analytics.reporter.pubstack.model.PubstackAnalyticsProperties;
import org.prebid.server.analytics.reporter.pubstack.model.PubstackConfig;
import org.prebid.server.exception.PreBidException;
import org.prebid.server.json.DecodeException;
import org.prebid.server.json.JacksonMapper;
Expand All @@ -26,7 +27,6 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
Expand All @@ -38,16 +38,6 @@ public class PubstackAnalyticsReporter implements AnalyticsReporter, Initializab

private static final String EVENT_REPORT_ENDPOINT_PATH = "/intake";
private static final String CONFIG_URL_SUFFIX = "/bootstrap?scopeId=";
private static final Map<String, EventType> CLASS_TO_EVENT_TYPE;

static {
CLASS_TO_EVENT_TYPE = new HashMap<>();
CLASS_TO_EVENT_TYPE.put(AuctionEvent.class.getName(), EventType.auction);
CLASS_TO_EVENT_TYPE.put(AmpEvent.class.getName(), EventType.amp);
CLASS_TO_EVENT_TYPE.put(VideoEvent.class.getName(), EventType.video);
CLASS_TO_EVENT_TYPE.put(SetuidEvent.class.getName(), EventType.setuid);
CLASS_TO_EVENT_TYPE.put(CookieSyncEvent.class.getName(), EventType.cookiesync);
}

private final long configurationRefreshDelay;
private final long timeout;
Expand All @@ -62,6 +52,7 @@ public PubstackAnalyticsReporter(PubstackAnalyticsProperties pubstackAnalyticsPr
HttpClient httpClient,
JacksonMapper jacksonMapper,
Vertx vertx) {

this.configurationRefreshDelay =
Objects.requireNonNull(pubstackAnalyticsProperties.getConfigurationRefreshDelayMs());
this.timeout = Objects.requireNonNull(pubstackAnalyticsProperties.getTimeoutMs());
Expand All @@ -79,6 +70,7 @@ private static Map<EventType, PubstackEventHandler> createEventHandlers(
HttpClient httpClient,
JacksonMapper jacksonMapper,
Vertx vertx) {

return Arrays.stream(EventType.values())
.collect(Collectors.toMap(Function.identity(),
eventType -> new PubstackEventHandler(
Expand All @@ -94,11 +86,30 @@ private static String buildEventEndpointUrl(String endpoint, EventType eventType
return HttpUtil.validateUrl(endpoint + EVENT_REPORT_ENDPOINT_PATH + eventType.name());
}

@Override
public <T> Future<Void> processEvent(T event) {
final EventType eventType = CLASS_TO_EVENT_TYPE.get(event.getClass().getName());
final EventType eventType;

if (event instanceof AmpEvent) {
eventType = EventType.amp;
} else if (event instanceof AuctionEvent) {
eventType = EventType.auction;
} else if (event instanceof CookieSyncEvent) {
eventType = EventType.cookiesync;
} else if (event instanceof NotificationEvent) {
eventType = EventType.notification;
} else if (event instanceof SetuidEvent) {
eventType = EventType.setuid;
} else if (event instanceof VideoEvent) {
eventType = EventType.video;
} else {
eventType = null;
}

if (eventType != null) {
eventHandlers.get(eventType).handle(event);
}

return Future.succeededFuture();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.prebid.server.analytics.pubstack;
package org.prebid.server.analytics.reporter.pubstack;

import com.fasterxml.jackson.databind.node.ObjectNode;
import io.netty.handler.codec.http.HttpResponseStatus;
Expand All @@ -9,7 +9,7 @@
import io.vertx.core.http.HttpMethod;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import org.prebid.server.analytics.pubstack.model.PubstackAnalyticsProperties;
import org.prebid.server.analytics.reporter.pubstack.model.PubstackAnalyticsProperties;
import org.prebid.server.exception.PreBidException;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.util.HttpUtil;
Expand Down Expand Up @@ -148,8 +148,8 @@ private static byte[] toGzippedBytes(Queue<String> events) {
}

private static byte[] gzip(String value) {
try (ByteArrayOutputStream obj = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(
obj)) {
try (ByteArrayOutputStream obj = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(obj)) {

gzip.write(value.getBytes(StandardCharsets.UTF_8));
gzip.finish();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.prebid.server.analytics.reporter.pubstack.model;

public enum EventType {

amp, auction, cookiesync, notification, setuid, video
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.prebid.server.analytics.pubstack.model;
package org.prebid.server.analytics.reporter.pubstack.model;

import lombok.Builder;
import lombok.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.prebid.server.analytics.pubstack.model;
package org.prebid.server.analytics.reporter.pubstack.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
Expand Down
Loading

0 comments on commit 697b230

Please sign in to comment.