Skip to content

Commit

Permalink
fixes after review (#6)
Browse files Browse the repository at this point in the history
* fixes after review

* fixes after review
  • Loading branch information
karle0wne authored Aug 22, 2023
1 parent 0a81b00 commit c705972
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 72 deletions.
10 changes: 0 additions & 10 deletions src/main/java/dev/vality/exporter/limits/config/CacheConfig.java

This file was deleted.

45 changes: 0 additions & 45 deletions src/main/java/dev/vality/exporter/limits/model/CustomTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@
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";
Expand All @@ -32,54 +23,18 @@ public static Tag providerId(String providerId) {
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);
}
Expand Down
31 changes: 14 additions & 17 deletions src/main/java/dev/vality/exporter/limits/service/LimitsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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;
Expand All @@ -19,6 +18,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
Expand Down Expand Up @@ -84,14 +84,14 @@ private void gauge(Map<String, Double> storage, Metric metric, String id, Tags t

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()));
}
Expand All @@ -108,16 +108,13 @@ private Tags getTags(LimitsData dto, LimitConfigEntity limitConfigEntity) {
}

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

0 comments on commit c705972

Please sign in to comment.