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 adapter prefix to bidder specific metrics #973

Merged
merged 2 commits into from
Jan 15, 2021
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
6 changes: 3 additions & 3 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ 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>.<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>`
- `account.<account-id>.<bidder-name>.bids_received` - number of bids received from `<bidder-name>` when incoming request was from `<account-id>`
- `account.<account-id>.<bidder-name>.requests.(gotbids|nobid)` - number of requests made to `<bidder-name>` broken down by result status when incoming request was from `<account-id>`
- `account.<account-id>.requests.rejected` - number of rejected requests caused by incorrect `accountId`
- `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>`
- `account.<account-id>.adapter.<bidder-name>.bids_received` - number of bids received from `<bidder-name>` when incoming request was from `<account-id>`
- `account.<account-id>.adapter.<bidder-name>.requests.(gotbids|nobid)` - number of requests made to `<bidder-name>` broken down by result status when incoming request was from `<account-id>`

## General Prebid Cache metrics
- `prebid_cache.requests.ok` - timer tracking how long did successful cache requests take
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/org/prebid/server/metric/AccountMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,22 @@
*/
class AccountMetrics extends UpdatableMetrics {

private final Function<String, AdapterMetrics> adapterMetricsCreator;
// not thread-safe maps are intentionally used here because it's harmless in this particular case - eventually
// this all boils down to metrics lookup by underlying metric registry and that operation is guaranteed to be
// thread-safe
private final Map<String, AdapterMetrics> adapterMetrics;
private final Function<MetricName, RequestTypeMetrics> requestTypeMetricsCreator;
private final Map<MetricName, RequestTypeMetrics> requestTypeMetrics;
private final AdapterMetrics adapterMetrics;
private final RequestMetrics requestsMetrics;
private final CacheMetrics cacheMetrics;
private final ResponseMetrics responseMetrics;

AccountMetrics(MetricRegistry metricRegistry, CounterType counterType, String account) {
super(Objects.requireNonNull(metricRegistry), Objects.requireNonNull(counterType),
nameCreator(createPrefix(Objects.requireNonNull(account))));
adapterMetricsCreator = adapterType -> new AdapterMetrics(metricRegistry, counterType, account, adapterType);
adapterMetrics = new HashMap<>();
requestTypeMetricsCreator = requestType ->
new RequestTypeMetrics(metricRegistry, counterType, createPrefix(account), requestType);
adapterMetrics = new AdapterMetrics(metricRegistry, counterType, createPrefix(account));
requestTypeMetrics = new HashMap<>();
requestsMetrics = new RequestMetrics(metricRegistry, counterType, createPrefix(account));
cacheMetrics = new CacheMetrics(metricRegistry, counterType, createPrefix(account));
Expand All @@ -44,8 +42,8 @@ private static Function<MetricName, String> nameCreator(String prefix) {
return metricName -> String.format("%s.%s", prefix, metricName.toString());
}

AdapterMetrics forAdapter(String adapterType) {
return adapterMetrics.computeIfAbsent(adapterType, adapterMetricsCreator);
AdapterMetrics adapter() {
return adapterMetrics;
}

RequestTypeMetrics requestType(MetricName requestType) {
Expand Down
63 changes: 11 additions & 52 deletions src/main/java/org/prebid/server/metric/AdapterMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,27 @@
*/
class AdapterMetrics extends UpdatableMetrics {

private final Function<MetricName, RequestTypeMetrics> requestTypeMetricsCreator;
private final Map<MetricName, RequestTypeMetrics> requestTypeMetrics;
private final RequestMetrics requestMetrics;
private final Function<String, BidTypeMetrics> bidTypeMetricsCreator;
private final Map<String, BidTypeMetrics> bidTypeMetrics;
private final ResponseMetrics responseMetrics;
private final Function<String, AdapterTypeMetrics> adapterMetricsCreator;
private final Map<String, AdapterTypeMetrics> adapterMetrics;

AdapterMetrics(MetricRegistry metricRegistry, CounterType counterType, String adapterType) {
AdapterMetrics(MetricRegistry metricRegistry, CounterType counterType, String accountPrefix) {
super(Objects.requireNonNull(metricRegistry), Objects.requireNonNull(counterType),
nameCreator(createAdapterPrefix(Objects.requireNonNull(adapterType))));
nameCreator(createAdapterSuffix(Objects.requireNonNull(accountPrefix))));

bidTypeMetricsCreator = bidType ->
new BidTypeMetrics(metricRegistry, counterType, createAdapterPrefix(adapterType), bidType);
requestTypeMetricsCreator = requestType ->
new RequestTypeMetrics(metricRegistry, counterType, createAdapterPrefix(adapterType), requestType);
requestTypeMetrics = new HashMap<>();
requestMetrics = new RequestMetrics(metricRegistry, counterType, createAdapterPrefix(adapterType));
bidTypeMetrics = new HashMap<>();
responseMetrics = new ResponseMetrics(metricRegistry, counterType, createAdapterPrefix(adapterType));
adapterMetrics = new HashMap<>();
adapterMetricsCreator = adapterType -> new AdapterTypeMetrics(metricRegistry, counterType,
createAdapterSuffix(Objects.requireNonNull(accountPrefix)), adapterType);
}

AdapterMetrics(MetricRegistry metricRegistry, CounterType counterType, String account, String adapterType) {
super(Objects.requireNonNull(metricRegistry), Objects.requireNonNull(counterType),
nameCreator(createAccountAdapterPrefix(Objects.requireNonNull(account),
Objects.requireNonNull(adapterType))));

requestMetrics = new RequestMetrics(metricRegistry, counterType,
createAccountAdapterPrefix(account, adapterType));

// not used for account.adapter metrics
requestTypeMetricsCreator = null;
requestTypeMetrics = null;
bidTypeMetricsCreator = null;
bidTypeMetrics = null;
responseMetrics = null;
}

private static String createAdapterPrefix(String adapterType) {
return String.format("adapter.%s", adapterType);
}

private static String createAccountAdapterPrefix(String account, String adapterType) {
return String.format("account.%s.%s", account, adapterType);
private static String createAdapterSuffix(String prefix) {
return String.format("%s.adapter", prefix);
}

private static Function<MetricName, String> nameCreator(String prefix) {
return metricName -> String.format("%s.%s", prefix, metricName.toString());
}

RequestTypeMetrics requestType(MetricName requestType) {
return requestTypeMetrics.computeIfAbsent(requestType, requestTypeMetricsCreator);
}

RequestMetrics request() {
return requestMetrics;
}

BidTypeMetrics forBidType(String bidType) {
return bidTypeMetrics.computeIfAbsent(bidType, bidTypeMetricsCreator);
}

ResponseMetrics response() {
return responseMetrics;
AdapterTypeMetrics forAdapter(String adapterType) {
return adapterMetrics.computeIfAbsent(adapterType, adapterMetricsCreator);
}
}
82 changes: 82 additions & 0 deletions src/main/java/org/prebid/server/metric/AdapterTypeMetrics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.prebid.server.metric;

import com.codahale.metrics.MetricRegistry;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

/**
* AdapterType metrics support.
*/
class AdapterTypeMetrics extends UpdatableMetrics {

private final Function<MetricName, RequestTypeMetrics> requestTypeMetricsCreator;
private final Map<MetricName, RequestTypeMetrics> requestTypeMetrics;
private final RequestMetrics requestMetrics;
private final Function<String, BidTypeMetrics> bidTypeMetricsCreator;
private final Map<String, BidTypeMetrics> bidTypeMetrics;
private final ResponseMetrics responseMetrics;

AdapterTypeMetrics(MetricRegistry metricRegistry, CounterType counterType, String adapterType) {
super(Objects.requireNonNull(metricRegistry), Objects.requireNonNull(counterType),
nameCreator(createAdapterPrefix(Objects.requireNonNull(adapterType))));

bidTypeMetricsCreator = bidType ->
new BidTypeMetrics(metricRegistry, counterType, createAdapterPrefix(adapterType), bidType);
requestTypeMetricsCreator = requestType ->
new RequestTypeMetrics(metricRegistry, counterType, createAdapterPrefix(adapterType), requestType);
requestTypeMetrics = new HashMap<>();
requestMetrics = new RequestMetrics(metricRegistry, counterType, createAdapterPrefix(adapterType));
bidTypeMetrics = new HashMap<>();
responseMetrics = new ResponseMetrics(metricRegistry, counterType, createAdapterPrefix(adapterType));
}

AdapterTypeMetrics(MetricRegistry metricRegistry,
CounterType counterType,
String accountAdapterPrefix,
String adapterType) {
super(Objects.requireNonNull(metricRegistry), Objects.requireNonNull(counterType),
nameCreator(createAdapterPrefix(Objects.requireNonNull(accountAdapterPrefix),
Objects.requireNonNull(adapterType))));

requestMetrics = new RequestMetrics(metricRegistry, counterType,
createAdapterPrefix(accountAdapterPrefix, adapterType));

// not used for account.adapter.adapters metrics
requestTypeMetricsCreator = null;
requestTypeMetrics = null;
bidTypeMetricsCreator = null;
bidTypeMetrics = null;
responseMetrics = null;
}

private static String createAdapterPrefix(String adapterType) {
return String.format("adapter.%s", adapterType);
}

private static String createAdapterPrefix(String adapterPrefix, String adapterType) {
return String.format("%s.%s", adapterPrefix, adapterType);
}

private static Function<MetricName, String> nameCreator(String prefix) {
return metricName -> String.format("%s.%s", prefix, metricName.toString());
}

RequestTypeMetrics requestType(MetricName requestType) {
return requestTypeMetrics.computeIfAbsent(requestType, requestTypeMetricsCreator);
}

RequestMetrics request() {
return requestMetrics;
}

BidTypeMetrics forBidType(String bidType) {
return bidTypeMetrics.computeIfAbsent(bidType, bidTypeMetricsCreator);
}

ResponseMetrics response() {
return responseMetrics;
}
}
36 changes: 19 additions & 17 deletions src/main/java/org/prebid/server/metric/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Metrics extends UpdatableMetrics {

private final Function<MetricName, RequestStatusMetrics> requestMetricsCreator;
private final Function<String, AccountMetrics> accountMetricsCreator;
private final Function<String, AdapterMetrics> adapterMetricsCreator;
private final Function<String, AdapterTypeMetrics> adapterMetricsCreator;
private final Function<Integer, BidderCardinalityMetrics> bidderCardinalityMetricsCreator;
private final Function<MetricName, CircuitBreakerMetrics> circuitBreakerMetricsCreator;
private final Function<MetricName, SettingsCacheMetrics> settingsCacheMetricsCreator;
Expand All @@ -38,7 +38,7 @@ public class Metrics extends UpdatableMetrics {
// thread-safe
private final Map<MetricName, RequestStatusMetrics> requestMetrics;
private final Map<String, AccountMetrics> accountMetrics;
private final Map<String, AdapterMetrics> adapterMetrics;
private final Map<String, AdapterTypeMetrics> adapterMetrics;
private final Map<Integer, BidderCardinalityMetrics> bidderCardinailtyMetrics;
private final UserSyncMetrics userSyncMetrics;
private final CookieSyncMetrics cookieSyncMetrics;
Expand All @@ -58,7 +58,7 @@ public Metrics(MetricRegistry metricRegistry, CounterType counterType, AccountMe

requestMetricsCreator = requestType -> new RequestStatusMetrics(metricRegistry, counterType, requestType);
accountMetricsCreator = account -> new AccountMetrics(metricRegistry, counterType, account);
adapterMetricsCreator = adapterType -> new AdapterMetrics(metricRegistry, counterType, adapterType);
adapterMetricsCreator = adapterType -> new AdapterTypeMetrics(metricRegistry, counterType, adapterType);
bidderCardinalityMetricsCreator = cardinality -> new BidderCardinalityMetrics(
metricRegistry, counterType, cardinality);
circuitBreakerMetricsCreator = type -> new CircuitBreakerMetrics(metricRegistry, counterType, type);
Expand Down Expand Up @@ -89,7 +89,7 @@ AccountMetrics forAccount(String account) {
return accountMetrics.computeIfAbsent(account, accountMetricsCreator);
}

AdapterMetrics forAdapter(String adapterType) {
AdapterTypeMetrics forAdapter(String adapterType) {
return adapterMetrics.computeIfAbsent(adapterType, adapterMetricsCreator);
}

Expand Down Expand Up @@ -211,22 +211,23 @@ public void updateAccountRequestRejectedMetrics(String accountId) {
}

public void updateAdapterRequestTypeAndNoCookieMetrics(String bidder, MetricName requestType, boolean noCookie) {
final AdapterMetrics adapterMetrics = forAdapter(resolveMetricsBidderName(bidder));
final AdapterTypeMetrics adapterTypeMetrics = forAdapter(resolveMetricsBidderName(bidder));

adapterMetrics.requestType(requestType).incCounter(MetricName.requests);
adapterTypeMetrics.requestType(requestType).incCounter(MetricName.requests);

if (noCookie) {
adapterMetrics.incCounter(MetricName.no_cookie_requests);
adapterTypeMetrics.incCounter(MetricName.no_cookie_requests);
}
}

public void updateAdapterResponseTime(String bidder, String accountId, int responseTime) {
final String metricsBidderName = resolveMetricsBidderName(bidder);
final AdapterMetrics adapterMetrics = forAdapter(metricsBidderName);
adapterMetrics.updateTimer(MetricName.request_time, responseTime);
final AdapterTypeMetrics adapterTypeMetrics = forAdapter(metricsBidderName);
adapterTypeMetrics.updateTimer(MetricName.request_time, responseTime);

if (accountMetricsVerbosity.forAccount(accountId).isAtLeast(AccountMetricsVerbosityLevel.detailed)) {
final AdapterMetrics accountAdapterMetrics = forAccount(accountId).forAdapter(metricsBidderName);
final AdapterTypeMetrics accountAdapterMetrics =
forAccount(accountId).adapter().forAdapter(metricsBidderName);
accountAdapterMetrics.updateTimer(MetricName.request_time, responseTime);
}
}
Expand All @@ -235,28 +236,29 @@ public void updateAdapterRequestNobidMetrics(String bidder, String accountId) {
final String metricsBidderName = resolveMetricsBidderName(bidder);
forAdapter(metricsBidderName).request().incCounter(MetricName.nobid);
if (accountMetricsVerbosity.forAccount(accountId).isAtLeast(AccountMetricsVerbosityLevel.detailed)) {
forAccount(accountId).forAdapter(metricsBidderName).request().incCounter(MetricName.nobid);
forAccount(accountId).adapter().forAdapter(metricsBidderName).request().incCounter(MetricName.nobid);
}
}

public void updateAdapterRequestGotbidsMetrics(String bidder, String accountId) {
final String metricsBidderName = resolveMetricsBidderName(bidder);
forAdapter(metricsBidderName).request().incCounter(MetricName.gotbids);
if (accountMetricsVerbosity.forAccount(accountId).isAtLeast(AccountMetricsVerbosityLevel.detailed)) {
forAccount(accountId).forAdapter(metricsBidderName).request().incCounter(MetricName.gotbids);
forAccount(accountId).adapter().forAdapter(metricsBidderName).request().incCounter(MetricName.gotbids);
}
}

public void updateAdapterBidMetrics(String bidder, String accountId, long cpm, boolean isAdm, String bidType) {
final String metricsBidderName = resolveMetricsBidderName(bidder);
final AdapterMetrics adapterMetrics = forAdapter(metricsBidderName);
adapterMetrics.updateHistogram(MetricName.prices, cpm);
adapterMetrics.incCounter(MetricName.bids_received);
adapterMetrics.forBidType(bidType)
final AdapterTypeMetrics adapterTypeMetrics = forAdapter(metricsBidderName);
adapterTypeMetrics.updateHistogram(MetricName.prices, cpm);
adapterTypeMetrics.incCounter(MetricName.bids_received);
adapterTypeMetrics.forBidType(bidType)
.incCounter(isAdm ? MetricName.adm_bids_received : MetricName.nurl_bids_received);

if (accountMetricsVerbosity.forAccount(accountId).isAtLeast(AccountMetricsVerbosityLevel.detailed)) {
final AdapterMetrics accountAdapterMetrics = forAccount(accountId).forAdapter(metricsBidderName);
final AdapterTypeMetrics accountAdapterMetrics =
forAccount(accountId).adapter().forAdapter(metricsBidderName);
accountAdapterMetrics.updateHistogram(MetricName.prices, cpm);
accountAdapterMetrics.incCounter(MetricName.bids_received);
}
Expand Down
Loading