Skip to content

Commit

Permalink
Core: Additional metric for account fetch failed case (#2792)
Browse files Browse the repository at this point in the history
  • Loading branch information
VeryExtraordinaryUsername authored Dec 15, 2023
1 parent 0b51bbf commit d59b4e0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ private Future<Account> accountFallback(Throwable exception,
if (exception instanceof PreBidException) {
UNKNOWN_ACCOUNT_LOGGER.warn(accountErrorMessage(exception.getMessage(), httpRequest), 100);
} else {
metrics.updateAccountRequestRejectedByFailedFetch(accountId);
logger.warn("Error occurred while fetching account: {0}", exception.getMessage());
logger.debug("Error occurred while fetching account", exception);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/prebid/server/metric/MetricName.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public enum MetricName {
rejected_by_invalid_account("rejected.invalid-account"),
rejected_by_invalid_stored_impr("rejected.invalid-stored-impr"),
rejected_by_invalid_stored_request("rejected.invalid-stored-request"),
rejected_by_account_fetch_failed("rejected.account-fetch-failed"),

// currency rates
stale,
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/prebid/server/metric/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ public void updateAccountRequestRejectedByInvalidStoredRequestMetrics(String acc
updateAccountRequestsMetrics(accountId, MetricName.rejected_by_invalid_stored_request);
}

public void updateAccountRequestRejectedByFailedFetch(String accountId) {
updateAccountRequestsMetrics(accountId, MetricName.rejected_by_account_fetch_failed);
}

private void updateAccountRequestsMetrics(String accountId, MetricName metricName) {
forAccount(accountId).requests().incCounter(metricName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ public void fetchAccountShouldReturnEmptyAccountIfExceptionOccurred() {
AuctionContext.builder().bidRequest(bidRequest).build());

// then
verify(metrics).updateAccountRequestRejectedByFailedFetch(accountId);
verify(applicationSettings).getAccountById(eq(accountId), any());

assertThat(result.result()).isEqualTo(Account.empty(accountId));
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/prebid/server/metric/MetricsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,16 @@ public void shouldIncrementUpdateAccountActivityProcessedRulesCount() {
.isEqualTo(1);
}

@Test
public void shouldIncrementUpdateAccountRequestRejectedByFailedFetchCount() {
// when
metrics.updateAccountRequestRejectedByFailedFetch("account_id");

// then
assertThat(metricRegistry.counter("account.account_id.requests.rejected.account-fetch-failed").getCount())
.isEqualTo(1);
}

private void verifyCreatesConfiguredCounterType(Consumer<Metrics> metricsConsumer) {
final EnumMap<CounterType, Class<? extends Metric>> counterTypeClasses = new EnumMap<>(CounterType.class);
counterTypeClasses.put(CounterType.counter, Counter.class);
Expand Down

0 comments on commit d59b4e0

Please sign in to comment.