fixes after review (#6)

* fixes after review

* fixes after review
This commit is contained in:
Anatolii Karlov 2023-08-22 18:31:35 +03:00 committed by GitHub
parent 0a81b00342
commit c705972006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 72 deletions

View File

@ -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 {
}

View File

@ -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);
}

View File

@ -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<Tag> getLimitScopeTypeTags(String limitScopeTypesJson) {
var tags = objectMapper.readValue(limitScopeTypesJson, new TypeReference<List<Map<String, Object>>>() {
private String getLimitScopeTypes(String limitScopeTypesJson) {
return objectMapper.readValue(limitScopeTypesJson, new TypeReference<List<Map<String, Object>>>() {
})
.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));
}
}