Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -152,41 +152,17 @@ private PriceFloorRules resolveFloors(Account account, BidRequest bidRequest, Li
return createFloorsFrom(mergedFloors, fetchStatus, PriceFloorLocation.fetch);
}

final String fetchErrorMessage = resolveFetchErrorMessage(fetchResult, isUsingDynamicDataAllowed);
return requestFloors == null
? noPriceFloorData(fetchStatus, account.getId(), bidRequest.getId(), fetchErrorMessage, warnings)
: getPriceFloorRules(bidRequest, account, requestFloors, fetchStatus, fetchErrorMessage, warnings);
}

private static String resolveFetchErrorMessage(FetchResult fetchResult, boolean isUsingDynamicDataAllowed) {
return switch (fetchResult.getFetchStatus()) {
case inprogress -> null;
case error, timeout, none -> fetchResult.getErrorMessage();
case success -> isUsingDynamicDataAllowed ? null : "Using dynamic data is not allowed";
};
}

private PriceFloorRules noPriceFloorData(FetchStatus fetchStatus,
String accountId,
String requestId,
String errorMessage,
List<String> warnings) {

if (errorMessage != null) {
warnings.add(errorMessage);
conditionalLogger.error("No price floor data for account %s and request %s, reason: %s"
.formatted(accountId, requestId, errorMessage), logSamplingRate);
metrics.updateAlertsMetrics(MetricName.general);
}

return createFloorsFrom(null, fetchStatus, PriceFloorLocation.noData);
return requestFloors == null || BooleanUtils.isNotTrue(requestFloors.getEnabled())
? createFloorsFrom(null, fetchStatus, PriceFloorLocation.noData)
: getPriceFloorRules(
bidRequest, account, requestFloors, fetchResult, isUsingDynamicDataAllowed, warnings);
}

private PriceFloorRules getPriceFloorRules(BidRequest bidRequest,
Account account,
PriceFloorRules requestFloors,
FetchStatus fetchStatus,
String fetchErrorMessage,
FetchResult fetchResult,
boolean isUsingDynamicDataAllowed,
List<String> warnings) {

try {
Expand All @@ -203,13 +179,36 @@ private PriceFloorRules getPriceFloorRules(BidRequest bidRequest,
PriceFloorsConfigResolver.resolveMaxValue(maxRules),
PriceFloorsConfigResolver.resolveMaxValue(maxDimensions));

return createFloorsFrom(requestFloors, fetchStatus, PriceFloorLocation.request);
return createFloorsFrom(requestFloors, fetchResult.getFetchStatus(), PriceFloorLocation.request);
} catch (PreBidException e) {
final String errorMessage = fetchErrorMessage == null
logErrorMessage(fetchResult, isUsingDynamicDataAllowed, e, account.getId(), bidRequest.getId(), warnings);
return createFloorsFrom(null, fetchResult.getFetchStatus(), PriceFloorLocation.noData);
}
}

private void logErrorMessage(FetchResult fetchResult,
boolean isUsingDynamicDataAllowed,
PreBidException requestFloorsValidationException,
String accountId,
String requestId,
List<String> warnings) {

final String validationErrorMessage = requestFloorsValidationException.getMessage();
final String errorMessage = switch (fetchResult.getFetchStatus()) {
case inprogress -> null;
case error, timeout, none -> "%s. Following parsing of request price floors is failed: %s"
.formatted(fetchResult.getErrorMessage(), validationErrorMessage);
case success -> isUsingDynamicDataAllowed
? null
: "%s. Following parsing of request price floors is failed: %s"
.formatted(fetchErrorMessage, e.getMessage());
return noPriceFloorData(fetchStatus, account.getId(), bidRequest.getId(), errorMessage, warnings);
: "Using dynamic data is not allowed. Following parsing of request price floors is failed: %s"
.formatted(validationErrorMessage);
};

if (errorMessage != null) {
warnings.add(errorMessage);
conditionalLogger.error("No price floor data for account %s and request %s, reason: %s"
.formatted(accountId, requestId, errorMessage), logSamplingRate);
metrics.updateAlertsMetrics(MetricName.general);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ public void shouldNotUseFloorsFromProviderIfUseDynamicDataIsFalse() {
.skipped(false)
.location(PriceFloorLocation.noData)
.build());
verify(metrics).updateAlertsMetrics(MetricName.general);
assertThat(warnings).containsExactly("Using dynamic data is not allowed");
verifyNoInteractions(metrics);
assertThat(warnings).isEmpty();
}

@Test
Expand Down Expand Up @@ -366,8 +366,8 @@ public void shouldNotUseFloorsWhenProviderFetchingIsDisabled() {
.skipped(false)
.location(PriceFloorLocation.noData)
.build());
verify(metrics).updateAlertsMetrics(MetricName.general);
assertThat(warnings).containsExactly("errorMessage");
verifyNoInteractions(metrics);
assertThat(warnings).isEmpty();
}

@Test
Expand Down Expand Up @@ -417,8 +417,8 @@ public void shouldNotUseFloorsWhenProviderFetchingIsFailed() {
.skipped(false)
.location(PriceFloorLocation.noData)
.build());
verify(metrics).updateAlertsMetrics(MetricName.general);
assertThat(warnings).containsExactly("errorMessage");
verifyNoInteractions(metrics);
assertThat(warnings).isEmpty();
}

@Test
Expand Down Expand Up @@ -469,8 +469,8 @@ public void shouldNotUseFloorsWhenProviderFetchingIsFailedWithTimeout() {
.skipped(false)
.location(PriceFloorLocation.noData)
.build());
verify(metrics).updateAlertsMetrics(MetricName.general);
assertThat(warnings).containsExactly("errorMessage");
verifyNoInteractions(metrics);
assertThat(warnings).isEmpty();
}

@Test
Expand Down Expand Up @@ -1086,6 +1086,7 @@ private static PriceFloorRules givenFloors(
UnaryOperator<PriceFloorRules.PriceFloorRulesBuilder> floorsCustomizer) {

return floorsCustomizer.apply(PriceFloorRules.builder()
.enabled(true)
.data(PriceFloorData.builder()
.modelGroups(singletonList(PriceFloorModelGroup.builder()
.value("someKey", BigDecimal.ONE)
Expand Down
Loading