From 6a2065a52fb7fd968ac23294ada75f2e1742fa36 Mon Sep 17 00:00:00 2001 From: Anatoly Karlov Date: Thu, 25 May 2023 21:16:09 +0600 Subject: [PATCH] add logs, add exlude mocketbank --- .../entity/PaymentsMetricDto.java | 5 ++-- .../service/PaymentService.java | 26 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/dev/vality/exporter/businessmetrics/entity/PaymentsMetricDto.java b/src/main/java/dev/vality/exporter/businessmetrics/entity/PaymentsMetricDto.java index 588d42a..e238e24 100644 --- a/src/main/java/dev/vality/exporter/businessmetrics/entity/PaymentsMetricDto.java +++ b/src/main/java/dev/vality/exporter/businessmetrics/entity/PaymentsMetricDto.java @@ -37,6 +37,7 @@ import javax.persistence.*; inner join dw.payment_route as pr on p2.invoice_id = pr.invoice_id and p2.payment_id = pr.payment_id and + pr.route_provider_id not in (1) and pr.current) select p3.*, p.name as provider_name @@ -79,9 +80,9 @@ import javax.persistence.*; issuer_bank, status """, - resultSetMapping = "PaymentsMetricDto") + resultSetMapping = "PaymentsMetricDtoList") @SqlResultSetMapping( - name = "PaymentsMetricDto", + name = "PaymentsMetricDtoList", classes = @ConstructorResult( targetClass = PaymentsMetricDto.class, columns = { diff --git a/src/main/java/dev/vality/exporter/businessmetrics/service/PaymentService.java b/src/main/java/dev/vality/exporter/businessmetrics/service/PaymentService.java index 5b47edc..ecd7673 100644 --- a/src/main/java/dev/vality/exporter/businessmetrics/service/PaymentService.java +++ b/src/main/java/dev/vality/exporter/businessmetrics/service/PaymentService.java @@ -17,6 +17,7 @@ import java.util.function.ToDoubleFunction; @Service @RequiredArgsConstructor @Slf4j +@SuppressWarnings("LineLength") public class PaymentService { @Value("${interval.time}") @@ -26,12 +27,25 @@ public class PaymentService { public void registerMetrics(MeterRegistry meterRegistry) { var paymentsMetrics = paymentRepository.getPaymentsMetricsByInterval(intervalTime); - log.info("Actual payments metrics by {} seconds interval size = {}", intervalTime, paymentsMetrics.toString()); - paymentsMetrics.forEach(dto -> Gauge.builder(Metric.PAYMENTS_COUNT.getName(), dto, getValue()) - .description(Metric.PAYMENTS_COUNT.getDescription()) - .baseUnit(Metric.PAYMENTS_COUNT.getUnit()) - .tags(getTags(dto)) - .register(meterRegistry)); + log.info("Actual payments metrics have been got from 'daway' db, " + + "interval = {}, count = {}", intervalTime, paymentsMetrics.size()); + int pendingCount = 0; + int failedCount = 0; + int capturedCount = 0; + for (PaymentsMetricDto dto : paymentsMetrics) { + switch (dto.getStatus()) { + case "pending" -> pendingCount++; + case "captured" -> capturedCount++; + case "failed" -> failedCount++; + } + Gauge.builder(Metric.PAYMENTS_COUNT.getName(), dto, getValue()) + .description(Metric.PAYMENTS_COUNT.getDescription()) + .baseUnit(Metric.PAYMENTS_COUNT.getUnit()) + .tags(getTags(dto)) + .register(meterRegistry); + } + log.info("Actual payments metrics have been registered to 'prometheus', " + + "pendingCount = {}, failedCount = {}, capturedCount = {}", pendingCount, failedCount, capturedCount); } private ToDoubleFunction getValue() {