diff --git a/src/main/java/dev/vality/exporter/limits/config/CacheConfig.java b/src/main/java/dev/vality/exporter/limits/config/CacheConfig.java deleted file mode 100644 index b30537c..0000000 --- a/src/main/java/dev/vality/exporter/limits/config/CacheConfig.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.vality.exporter.limits.config; - -import org.springframework.cache.annotation.EnableCaching; -import org.springframework.context.annotation.Configuration; - -@Configuration -@EnableCaching -public class CacheConfig { - -} diff --git a/src/main/java/dev/vality/exporter/limits/model/CustomTag.java b/src/main/java/dev/vality/exporter/limits/model/CustomTag.java index 4ba5b4a..8cecc08 100644 --- a/src/main/java/dev/vality/exporter/limits/model/CustomTag.java +++ b/src/main/java/dev/vality/exporter/limits/model/CustomTag.java @@ -7,18 +7,9 @@ import lombok.experimental.UtilityClass; public class CustomTag { public static final String PROVIDER_ID_TAG = "provider_id"; - public static final String PROVIDER_NAME_TAG = "provider_name"; public static final String TERMINAL_ID_TAG = "terminal_id"; - public static final String TERMINAL_NAME_TAG = "terminal_name"; public static final String SHOP_ID_TAG = "shop_id"; - public static final String SHOP_NAME_TAG = "shop_name"; public static final String CURRENCY_TAG = "currency"; - public static final String COUNTRY_TAG = "issuer_country"; - public static final String BANK_TAG = "issuer_bank"; - public static final String BANK_CARD_PAYMENT_SYSTEM_TAG = "issuer_bank_card_payment_system"; - public static final String STATUS_TAG = "status"; - public static final String WALLET_ID_TAG = "wallet_id"; - public static final String WALLET_NAME_TAG = "wallet_name"; public static final String CONFIG_ID_TAG = "config_id"; public static final String TIME_RANGE_TYPE = "time_range_type"; public static final String TIME_RANGE_TYPE_CALENDAR = "time_range_type_calendar"; @@ -32,54 +23,18 @@ public class CustomTag { return Tag.of(PROVIDER_ID_TAG, providerId); } - public static Tag providerName(String providerName) { - return Tag.of(PROVIDER_NAME_TAG, providerName); - } - public static Tag terminalId(String terminalId) { return Tag.of(TERMINAL_ID_TAG, terminalId); } - public static Tag terminalName(String terminalName) { - return Tag.of(TERMINAL_NAME_TAG, terminalName); - } - public static Tag shopId(String shopId) { return Tag.of(SHOP_ID_TAG, shopId); } - public static Tag shopName(String shopName) { - return Tag.of(SHOP_NAME_TAG, shopName); - } - public static Tag currency(String currency) { return Tag.of(CURRENCY_TAG, currency); } - public static Tag issuerCountry(String country) { - return Tag.of(COUNTRY_TAG, country); - } - - public static Tag issuerBank(String bank) { - return Tag.of(BANK_TAG, bank); - } - - public static Tag issuerBankCardPaymentSystem(String issuerBankCardPaymentSystem) { - return Tag.of(BANK_CARD_PAYMENT_SYSTEM_TAG, issuerBankCardPaymentSystem); - } - - public static Tag status(String status) { - return Tag.of(STATUS_TAG, status); - } - - public static Tag walletId(String walletId) { - return Tag.of(WALLET_ID_TAG, walletId); - } - - public static Tag walletName(String walletName) { - return Tag.of(WALLET_NAME_TAG, walletName); - } - public static Tag configId(String configId) { return Tag.of(CONFIG_ID_TAG, configId); } diff --git a/src/main/java/dev/vality/exporter/limits/service/LimitsService.java b/src/main/java/dev/vality/exporter/limits/service/LimitsService.java index 66b611a..8a35284 100644 --- a/src/main/java/dev/vality/exporter/limits/service/LimitsService.java +++ b/src/main/java/dev/vality/exporter/limits/service/LimitsService.java @@ -9,7 +9,6 @@ import dev.vality.exporter.limits.model.LimitsData; import dev.vality.exporter.limits.model.Metric; import dev.vality.exporter.limits.repository.LimitConfigRepository; import io.micrometer.core.instrument.Gauge; -import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Tags; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; @@ -19,6 +18,7 @@ import org.springframework.stereotype.Service; import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; @Service @@ -84,14 +84,14 @@ public class LimitsService { private Tags getTags(LimitsData dto, LimitConfigEntity limitConfigEntity) { var tags = Tags.of( - CustomTag.terminalId(dto.getLimit().getRoute().getTerminalId()), - CustomTag.providerId(dto.getLimit().getRoute().getProviderId()), - CustomTag.currency(dto.getLimit().getChange().getCurrency()), - CustomTag.shopId(dto.getLimit().getShopId()), - CustomTag.configId(dto.getLimit().getConfigId()), - CustomTag.timeRangType(limitConfigEntity.getTimeRangType().name()), - CustomTag.limitContextType(limitConfigEntity.getLimitContextType())) - .and(getLimitScopeTypeTags(limitConfigEntity.getLimitScopeTypesJson())); + CustomTag.terminalId(dto.getLimit().getRoute().getTerminalId()), + CustomTag.providerId(dto.getLimit().getRoute().getProviderId()), + CustomTag.currency(dto.getLimit().getChange().getCurrency()), + CustomTag.shopId(dto.getLimit().getShopId()), + CustomTag.configId(dto.getLimit().getConfigId()), + CustomTag.timeRangType(limitConfigEntity.getTimeRangType().name()), + CustomTag.limitContextType(limitConfigEntity.getLimitContextType()), + CustomTag.limitScopeTypes(getLimitScopeTypes(limitConfigEntity.getLimitScopeTypesJson()))); if (limitConfigEntity.getTimeRangeTypeCalendar() != null) { tags = tags.and(CustomTag.timeRangeTypeCalendar(limitConfigEntity.getTimeRangeTypeCalendar())); } @@ -108,16 +108,13 @@ public class LimitsService { } @SneakyThrows - private List getLimitScopeTypeTags(String limitScopeTypesJson) { - var tags = objectMapper.readValue(limitScopeTypesJson, new TypeReference>>() { + private String getLimitScopeTypes(String limitScopeTypesJson) { + return objectMapper.readValue(limitScopeTypesJson, new TypeReference>>() { }) .stream() .flatMap(stringObjectMap -> stringObjectMap.keySet().stream()) - .map(s -> Tag.of(String.format("limit_scope_type_%s", s), "true")) - .collect(Collectors.toList()); - if (tags.isEmpty()) { - tags.add(Tag.of(String.format("limit_scope_type_%s", "all"), "true")); - } - return tags; + .collect(Collectors.collectingAndThen( + Collectors.joining(","), + s -> Objects.equals(s, "") ? "all" : s)); } }