Skip to content

Commit

Permalink
fix: refactoring on trace writing for log (and cost) tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-deri committed Sep 16, 2024
1 parent 57d25ef commit 232d230
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public enum AppErrorCodeMessageEnum {
PERSISTENCE_RPT_NOT_FOUND(2001, "RPT not found", "Error while retrieving RPT. RPT with sessionId [{0}] not found.", HttpStatus.NOT_FOUND, "An error occurred while trying to retrieve the RPT content saved in storage by WISP SOAP Converter. This can be related either with the use of a wrong sessionId or a missed persistence from WISP SOAP Converter, so it is better to analyze the entire flow using Technical Support's APIs. This block totally the conversion of the RPTs in GPD's payment positions, so the whole process is discarded."),
PERSISTENCE_RT_NOT_FOUND(2002, "RT not found", "Error while retrieving RT. RT with id [{0}] and partition key [{1}] not found.", HttpStatus.NOT_FOUND, "An error occurred while trying to retrieve the RT content saved in storage by WISP Converter. This can be related either with the use of a wrong identifier, a missed persistence or an expired object, so it is better to analyze the entire flow using Technical Support's APIs."),
PERSISTENCE_REQUESTID_CACHING_ERROR(2003, "RequestID caching error", "Error while reading cached RequestID. No valid value found for key [{0}].", HttpStatus.NOT_FOUND, "An error occurred while trying to retrieve data from internal cache. Specifically, the cached key, defined in format wisp_nav2iuv_<domainId>_<nav> needed for RT generation, was not found. This missing read invalidates the entire process of the RT generation."),
PERSISTENCE_SERVICE_BUS_CANCEL_ERROR(2004, "ServiceBus Error", "Error while communicating with Service Bus for cancel scheduled message related to payment token timeout. {0}", HttpStatus.INTERNAL_SERVER_ERROR, "An error occurred while communicating with Service Bus for cancel scheduled message related to payment token"),
PERSISTENCE_SERVICE_BUS_CANCEL_ERROR(2004, "ServiceBus Error", "Error while communicating with Service Bus for cancel scheduled message related to timer timeout. {0}", HttpStatus.INTERNAL_SERVER_ERROR, "An error occurred while communicating with Service Bus for cancel scheduled message related to timer timeout"),
PERSISTENCE_MAPPING_NAV_TO_IUV_ERROR(2005, "Mapping caching error", "Error while reading cached mapping from NAV to IUV. No valid value found for NAV-based key [{0}].", HttpStatus.NOT_FOUND, "An error occurred while trying to retrieve data from internal cache. Specifically, the cached key, defined in format wisp_nav2iuv_<domainId>_<nav> needed for RT generation is corrupted in some way, because it is not possible to extract 'domainId' or 'nav' correctly. This wrong read invalidates the entire process of the RT generation."),
CONFIGURATION_NOT_FOUND(2006, "Configuration not found", "The configuration for the selected item does not exist", HttpStatus.NOT_FOUND, "An error occured while retrieving the configuration. Check the input string and if the configuration is present or not"),
// --- Client errors ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public void sendMessage(ECommerceHangTimeoutMessage message) {
Long sequenceNumber = serviceBusSenderClient.scheduleMessage(serviceBusMessage, scheduledExpirationTime);

// log event
log.info("Sent scheduled message_base64 {} to the queue: {}", LogUtils.encodeToBase64(message.toString()), queueName);
generateRE(InternalStepStatus.ECOMMERCE_HANG_TIMER_CREATED, "Scheduled ECommerceHangTimerService: [" + message + "]");
log.debug("Sent scheduled message_base64 {} to the queue: {}", LogUtils.encodeToBase64(message.toString()), queueName);
generateRE(InternalStepStatus.ECOMMERCE_HANG_TIMER_CREATED, "Scheduled eCommerce hang release: [" + message + "]");

// insert in Redis cache sequenceNumber of the message
cacheRepository.insert(key, sequenceNumber.toString(), expirationTime, ChronoUnit.SECONDS);
Expand All @@ -108,7 +108,7 @@ public void sendMessage(ECommerceHangTimeoutMessage message) {
*/
public void cancelScheduledMessage(String noticeNumber, String fiscalCode) {

log.debug("Cancel scheduled message for ECommerceHangTimer {} {}", sanitizeInput(noticeNumber), sanitizeInput(fiscalCode));
log.debug("Cancel scheduled message for eCommerce hang release {} {}", sanitizeInput(noticeNumber), sanitizeInput(fiscalCode));
String key = String.format(ECOMMERCE_TIMER_MESSAGE_KEY_FORMAT, noticeNumber, fiscalCode);

// get the sequenceNumber from the Redis cache
Expand All @@ -118,7 +118,7 @@ public void cancelScheduledMessage(String noticeNumber, String fiscalCode) {

// cancel scheduled message in the service bus queue
callCancelScheduledMessage(sequenceNumber);
log.info("Canceled scheduled message for ecommerce_hang_timeout_base64 {} {}", LogUtils.encodeToBase64(sanitizeInput(noticeNumber)), LogUtils.encodeToBase64(sanitizeInput(fiscalCode)));
log.debug("Canceled scheduled message for ecommerce_hang_timeout_base64 {} {}", LogUtils.encodeToBase64(sanitizeInput(noticeNumber)), LogUtils.encodeToBase64(sanitizeInput(fiscalCode)));

// delete the sequenceNumber from the Redis cache
cacheRepository.delete(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void sendMessage(ReceiptTimerRequest message) {
// compute time and schedule message for consumer trigger
OffsetDateTime scheduledExpirationTime = OffsetDateTime.now().plus(message.getExpirationTime(), ChronoUnit.MILLIS);
Long sequenceNumber = serviceBusSenderClient.scheduleMessage(serviceBusMessage, scheduledExpirationTime);
log.info("Sent scheduled message_base64 {} to the queue: {}", LogUtils.encodeToBase64(message.toString()), queueName);
log.debug("Sent scheduled message_base64 {} to the queue: {}", LogUtils.encodeToBase64(message.toString()), queueName);

Check failure

Code scanning / CodeQL

Insertion of sensitive information into log files High

This
potentially sensitive information
is written to a log file.

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
generateRE(InternalStepStatus.RECEIPT_TIMER_GENERATION_CREATED_SCHEDULED_SEND, "Scheduled receipt: [" + message + "]");

// insert {wisp_timer_<paymentToken>, sequenceNumber} for Duplicate Prevention Logic and for call cancelScheduledMessage(sequenceNumber)
Expand Down Expand Up @@ -108,7 +108,7 @@ private void cancelScheduledMessage(String paymentToken) {
// cancel scheduled message
if (this.callCancelScheduledMessage(sequenceNumberString)) {

log.info("Canceled scheduled message for payment-token_base64 {}", LogUtils.encodeToBase64(paymentToken));
log.debug("Canceled scheduled message for payment-token_base64 {}", LogUtils.encodeToBase64(paymentToken));

Check failure

Code scanning / CodeQL

Insertion of sensitive information into log files High

This
potentially sensitive information
is written to a log file.

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
cacheRepository.delete(sequenceNumberKey);
log.debug("Deleted sequence number {} for payment-token: {} from cache", sequenceNumberString, sequenceNumberKey);
generateRE(InternalStepStatus.RECEIPT_TIMER_GENERATION_DELETED_SCHEDULED_SEND, "Deleted sequence number: [" + sequenceNumberString + "] for payment token: [" + sequenceNumberKey + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public RecoveryReceiptResponse recoverReceiptKOForCreditorInstitution(String cre

CompletableFuture<Boolean> executeRecovery = recoverReceiptKOAsync(dateFrom, dateTo, creditorInstitution, paymentsToReconcile);
executeRecovery
.thenAccept(value -> log.info("Reconciliation for creditor institution [{}] in date range [{}-{}] completed!", creditorInstitution, dateFrom, dateTo))
.thenAccept(value -> log.debug("Reconciliation for creditor institution [{}] in date range [{}-{}] completed!", creditorInstitution, dateFrom, dateTo))

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
.exceptionally(e -> {
log.error("Reconciliation for creditor institution [{}] in date range [{}-{}] ended unsuccessfully!", creditorInstitution, dateFrom, dateTo, e);
throw new AppException(e, AppErrorCodeMessageEnum.ERROR, e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void initializeClient() {
public void processMessage(ServiceBusReceivedMessageContext context) {
setSessionDataInfoInMDC("ecommerce-hang-timeout-trigger");
ServiceBusReceivedMessage message = context.getMessage();
log.info("Processing message. Session: {}, Sequence #: {}. Contents: {}", message.getMessageId(), message.getSequenceNumber(), message.getBody());
log.debug("Processing message. Session: {}, Sequence #: {}. Contents: {}", message.getMessageId(), message.getSequenceNumber(), message.getBody());
try {
// read the message
ECommerceHangTimeoutMessage timeoutMessage = mapper.readValue(message.getBody().toStream(), ECommerceHangTimeoutMessage.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void post() {
public void processMessage(ServiceBusReceivedMessageContext context) {
setSessionDataInfoInMDC("payment-token-timeout-trigger");
ServiceBusReceivedMessage message = context.getMessage();
log.info("Processing message. Session: {}, Sequence #: {}. Contents: {}", message.getMessageId(),
log.debug("Processing message. Session: {}, Sequence #: {}. Contents: {}", message.getMessageId(),
message.getSequenceNumber(), message.getBody());
try {
ReceiptDto receiptDto = mapper.readValue(message.getBody().toStream(), ReceiptDto.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void processMessage(ServiceBusReceivedMessageContext context) {
// retrieving content from context of arrived message
setSessionDataInfoInMDC("resend-rt");
ServiceBusReceivedMessage message = context.getMessage();
log.info("Processing " + message.getMessageId());
log.debug("Processing " + message.getMessageId());

// extracting the values needed for the search of the receipt persisted in storage
String compositedIdForReceipt = new String(message.getBody().toBytes());
Expand Down Expand Up @@ -144,7 +144,7 @@ private void resendRTToCreditorInstitution(String receiptId, RTRequestEntity rec

try {

log.info("Sending receipt [{}]", receiptId);
log.debug("Sending receipt [{}]", receiptId);

// unzip retrieved zipped payload from GZip format
byte[] unzippedPayload = ZipUtil.unzip(AppBase64Util.base64Decode(receipt.getPayload()));
Expand All @@ -158,7 +158,7 @@ private void resendRTToCreditorInstitution(String receiptId, RTRequestEntity rec
String rawPayload = new String(unzippedPayload);
paaInviaRTSenderService.sendToCreditorInstitution(receipt.getUrl(), extractHeaders(receipt.getHeaders()), rawPayload);
rtRetryComosService.deleteRTRequestEntity(receipt);
log.info("Sent receipt [{}]", receiptId);
log.debug("Sent receipt [{}]", receiptId);

// generate a new event in RE for store the successful re-sending of the receipt
generateREForSentRT();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/it/gov/pagopa/wispconverter/util/ReUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private static String formatClientHeaders(HttpHeaders headers) {
headers.add(s, StringUtils.join(h, ","));
});
} catch (UnsupportedOperationException e) {
log.trace("Impossible to add formatted header to existing Headers object:", e);
log.debug("Impossible to add formatted header to existing Headers object:", e);
}

return formatHeaders(headers);
Expand Down

0 comments on commit 232d230

Please sign in to comment.