Skip to content

Commit

Permalink
Core: Sample HttpBidderRequester Logs (prebid#3546)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoxaAntoxic authored Nov 13, 2024
1 parent d714f28 commit 0970699
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/main/java/org/prebid/server/bidder/HttpBidderRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.prebid.server.exception.PreBidException;
import org.prebid.server.execution.Timeout;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.log.ConditionalLogger;
import org.prebid.server.log.Logger;
import org.prebid.server.log.LoggerFactory;
import org.prebid.server.model.CaseInsensitiveMultiMap;
Expand Down Expand Up @@ -62,24 +63,28 @@
public class HttpBidderRequester {

private static final Logger logger = LoggerFactory.getLogger(HttpBidderRequester.class);
private static final ConditionalLogger conditionalLogger = new ConditionalLogger(logger);

private final HttpClient httpClient;
private final BidderRequestCompletionTrackerFactory completionTrackerFactory;
private final BidderErrorNotifier bidderErrorNotifier;
private final HttpBidderRequestEnricher requestEnricher;
private final JacksonMapper mapper;
private final double logSamplingRate;

public HttpBidderRequester(HttpClient httpClient,
BidderRequestCompletionTrackerFactory completionTrackerFactory,
BidderErrorNotifier bidderErrorNotifier,
HttpBidderRequestEnricher requestEnricher,
JacksonMapper mapper) {
JacksonMapper mapper,
double logSamplingRate) {

this.httpClient = Objects.requireNonNull(httpClient);
this.completionTrackerFactory = completionTrackerFactoryOrFallback(completionTrackerFactory);
this.bidderErrorNotifier = Objects.requireNonNull(bidderErrorNotifier);
this.requestEnricher = Objects.requireNonNull(requestEnricher);
this.mapper = Objects.requireNonNull(mapper);
this.logSamplingRate = logSamplingRate;
}

/**
Expand Down Expand Up @@ -241,9 +246,9 @@ private static byte[] gzip(byte[] value) {
/**
* Produces {@link Future} with {@link BidderCall} containing request and error description.
*/
private static <T> Future<BidderCall<T>> failResponse(Throwable exception, HttpRequest<T> httpRequest) {
logger.warn("Error occurred while sending HTTP request to a bidder url: {} with message: {}",
httpRequest.getUri(), exception.getMessage());
private <T> Future<BidderCall<T>> failResponse(Throwable exception, HttpRequest<T> httpRequest) {
conditionalLogger.warn("Error occurred while sending HTTP request to a bidder url: %s with message: %s"
.formatted(httpRequest.getUri(), exception.getMessage()), logSamplingRate);
logger.debug("Error occurred while sending HTTP request to a bidder url: {}",
exception, httpRequest.getUri());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,11 +752,13 @@ HttpBidderRequester httpBidderRequester(
HttpBidderRequestEnricher requestEnricher,
JacksonMapper mapper) {

return new HttpBidderRequester(httpClient,
return new HttpBidderRequester(
httpClient,
bidderRequestCompletionTrackerFactory,
bidderErrorNotifier,
requestEnricher,
mapper);
mapper,
logSamplingRate);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void setUp() {
expiredTimeout = timeoutFactory.create(clock.instant().minusMillis(1500L).toEpochMilli(), 1000L);

target = new HttpBidderRequester(
httpClient, null, bidderErrorNotifier, requestEnricher, jacksonMapper);
httpClient, null, bidderErrorNotifier, requestEnricher, jacksonMapper, 0.0);
given(bidder.makeBidderResponse(any(BidderCall.class), any(BidRequest.class))).willCallRealMethod();
}

Expand Down Expand Up @@ -506,7 +506,8 @@ public void processBids(List<BidderBid> bids) {
},
bidderErrorNotifier,
requestEnricher,
jacksonMapper);
jacksonMapper,
0.0);

final BidRequest bidRequest = bidRequestWithDeals("deal1", "deal2");
final BidderRequest bidderRequest = BidderRequest.builder()
Expand Down

0 comments on commit 0970699

Please sign in to comment.