refactor logs

This commit is contained in:
Anatoly Karlov 2023-08-17 18:15:23 +03:00
parent 9fbdca7469
commit 7f40ca1916
3 changed files with 18 additions and 13 deletions

View File

@ -0,0 +1,10 @@
package dev.vality.exporter.limits.config;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableCaching
public class CacheConfig {
}

View File

@ -6,12 +6,12 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public enum Metric {
LIMITS_BOUNDARY(
CALENDAR_LIMITS_BOUNDARY(
formatWithPrefix("limits_boundary_by_calendar"),
"Limits boundary since last scrape"),
LIMITS_AMOUNT(
"Calendar limits boundary since last scrape"),
CALENDAR_LIMITS_AMOUNT(
formatWithPrefix("limits_amount_by_calendar"),
"Limits amount since last scrape");
"Calendar limits amount since last scrape");
@Getter
private final String name;

View File

@ -36,14 +36,11 @@ public class LimitsService {
public void registerMetrics() {
var limitsDataByInterval = openSearchService.getLimitsDataByInterval();
log.info("limitsDataByInterval {}", limitsDataByInterval);
var limitConfigIds = limitsDataByInterval.stream()
.map(limitsData -> limitsData.getLimit().getConfigId())
.distinct()
.toList();
log.info("limitConfigIds {}", limitConfigIds);
var limitConfigEntities = limitConfigRepository.findAllUsingLimitConfigIdsAndTimeRangType(limitConfigIds, TimeRangeType.calendar);
log.info("limitConfigEntities {}", limitConfigEntities);
var limitConfigsById = limitConfigEntities.stream().collect(
Collectors.groupingBy(
o -> o.getPk().getLimitConfigId(),
@ -54,11 +51,10 @@ public class LimitsService {
values -> values.stream()
.max(Comparator.comparing(limitConfigEntity -> limitConfigEntity.getPk().getSequenceId()))
.orElse(null)))));
log.info("limitConfigsById {}", limitConfigsById);
for (var limitsData : limitsDataByInterval) {
var limitConfigEntity = limitConfigsById.get(limitsData.getLimit().getConfigId());
if (limitConfigEntity == null) {
log.info("limitConfigEntity null, limitsData {}", limitsData);
log.warn("limitConfigEntity null, no gauge limitsData {}", limitsData);
break;
}
var id = String.format(
@ -68,11 +64,10 @@ public class LimitsService {
limitsData.getLimit().getRoute().getTerminalId(),
limitsData.getLimit().getShopId(),
limitsData.getLimit().getChange().getCurrency());
log.info("id {}", id);
gauge(limitsBoundaryAggregatesMap, Metric.LIMITS_BOUNDARY, id, getTags(limitsData, limitConfigEntity), limitsData.getLimit().getBoundary());
gauge(limitsAmountAggregatesMap, Metric.LIMITS_AMOUNT, id, getTags(limitsData, limitConfigEntity), limitsData.getLimit().getAmount());
gauge(limitsBoundaryAggregatesMap, Metric.CALENDAR_LIMITS_BOUNDARY, id, getTags(limitsData, limitConfigEntity), limitsData.getLimit().getBoundary());
gauge(limitsAmountAggregatesMap, Metric.CALENDAR_LIMITS_AMOUNT, id, getTags(limitsData, limitConfigEntity), limitsData.getLimit().getAmount());
}
var registeredMetricsSize = meterRegistryService.getRegisteredMetricsSize(Metric.LIMITS_BOUNDARY.getName()) + meterRegistryService.getRegisteredMetricsSize(Metric.LIMITS_AMOUNT.getName());
var registeredMetricsSize = meterRegistryService.getRegisteredMetricsSize(Metric.CALENDAR_LIMITS_BOUNDARY.getName()) + meterRegistryService.getRegisteredMetricsSize(Metric.CALENDAR_LIMITS_AMOUNT.getName());
log.info("Limits metrics have been registered to 'prometheus', " +
"registeredMetricsSize = {}, clientSize = {}", registeredMetricsSize, limitsDataByInterval.size());
}