SUPPORT-9182: small fix in logs

This commit is contained in:
gulnaz 2025-06-05 16:24:27 +03:00
parent c5ddacc405
commit e0b5d32cd0
2 changed files with 6 additions and 16 deletions

View file

@ -33,7 +33,7 @@ import ru.micord.ervu.util.NetworkUtils;
public class BaseAuditService implements AuditService { public class BaseAuditService implements AuditService {
private static final Logger LOGGER = LoggerFactory.getLogger(BaseAuditService.class); private static final Logger LOGGER = LoggerFactory.getLogger(BaseAuditService.class);
private static final List<String> IP_HEADERS = private static final List<String> IP_HEADERS =
Arrays.asList("X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR", "X-CLIENT-IP"); Arrays.asList("X-Forwarded-For", "WL-Proxy-Client-IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR");
private final AuditKafkaPublisher auditPublisher; private final AuditKafkaPublisher auditPublisher;
@ -114,7 +114,7 @@ public class BaseAuditService implements AuditService {
LOGGER.info("Thread {} - event published in {} ms", Thread.currentThread().getId(), LOGGER.info("Thread {} - event published in {} ms", Thread.currentThread().getId(),
System.currentTimeMillis() - startTime); System.currentTimeMillis() - startTime);
LOGGER.info("client ip from header: {}", getClientIp(request)); IP_HEADERS.forEach(header -> LOGGER.info("Data from header: {} - {}", header, request.getHeader(header)));
} }
@Override @Override
@ -144,14 +144,4 @@ public class BaseAuditService implements AuditService {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public String getClientIp(HttpServletRequest request) {
IP_HEADERS.forEach(header -> LOGGER.info("Data from header: {} - {}", header, request.getHeader(header)));
return IP_HEADERS.stream()
.map(request::getHeader)
.filter(Objects::nonNull)
.filter(ip -> !ip.isEmpty() && !ip.equalsIgnoreCase("unknown"))
.findFirst()
.orElseGet(request::getRemoteAddr);
}
} }

View file

@ -29,13 +29,13 @@ public abstract class BaseReplyingKafkaService<T, V> implements ReplyingKafkaSer
try { try {
ConsumerRecord<String, V> result = Optional.ofNullable(replyFuture.get()) ConsumerRecord<String, V> result = Optional.ofNullable(replyFuture.get())
.orElseThrow(() -> new KafkaMessageException("Kafka return result is null")); .orElseThrow(() -> new KafkaMessageException("Kafka return result is null"));
LOGGER.info("Thread {} - KafkaSendMessageAndGetReply: {} ms", LOGGER.info("Thread {} - KafkaSendMessageAndGetReply: {} ms, replyTopic: {}",
Thread.currentThread().getId(), System.currentTimeMillis() - startTime); Thread.currentThread().getId(), System.currentTimeMillis() - startTime, replyTopic);
return result; return result;
} }
catch (InterruptedException | ExecutionException e) { catch (InterruptedException | ExecutionException e) {
LOGGER.error("Thread {} - KafkaSendMessageAndGetReply: {} ms", LOGGER.error("Thread {} - KafkaSendMessageAndGetReply: {} ms, replyTopic: {}",
Thread.currentThread().getId(), System.currentTimeMillis() - startTime); Thread.currentThread().getId(), System.currentTimeMillis() - startTime, replyTopic);
throw new KafkaMessageReplyTimeoutException(e); throw new KafkaMessageReplyTimeoutException(e);
} }
} }