mirror of
https://github.com/valitydev/exporter-business-metrics.git
synced 2024-11-06 00:55:19 +00:00
Ft/currencies (#19)
* BUS-73: add currencies * BUS-73: add currencies * BUS-73: add currencies * BUS-73: add currencies * BUS-73: add currencies
This commit is contained in:
parent
4c84600152
commit
64404a3ca5
2
.github/settings.yml
vendored
2
.github/settings.yml
vendored
@ -1,2 +0,0 @@
|
||||
# These settings are synced to GitHub by https://probot.github.io/apps/settings/
|
||||
_extends: .github
|
10
.github/workflows/basic-linters.yml
vendored
10
.github/workflows/basic-linters.yml
vendored
@ -1,10 +0,0 @@
|
||||
name: Vality basic linters
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "*"
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
uses: valitydev/base-workflows/.github/workflows/basic-linters.yml@v1
|
2
.github/workflows/settings.yml
vendored
2
.github/workflows/settings.yml
vendored
@ -1,2 +0,0 @@
|
||||
# These settings are synced to GitHub by https://probot.github.io/apps/settings/
|
||||
_extends: .github
|
@ -43,4 +43,11 @@ public class GaugeConfig {
|
||||
.description(Metric.WITHDRAWALS_AMOUNT.getDescription())
|
||||
.register(meterRegistry);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MultiGauge multiGaugeCurrencyExponent(MeterRegistry meterRegistry) {
|
||||
return MultiGauge.builder(Metric.CURRENCY_EXPONENT.getName())
|
||||
.description(Metric.CURRENCY_EXPONENT.getDescription())
|
||||
.register(meterRegistry);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
package dev.vality.exporter.businessmetrics.entity.currency;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity
|
||||
@Builder
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Table(name = "currency")
|
||||
public class CurrencyEntity implements Serializable {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Column(name = "symbolic_code")
|
||||
private String symbolicCode;
|
||||
|
||||
@Column(name = "numeric_code")
|
||||
private String numericCode;
|
||||
|
||||
@Column(name = "exponent")
|
||||
private String exponent;
|
||||
|
||||
@Column(name = "current")
|
||||
private Boolean current;
|
||||
|
||||
}
|
@ -17,6 +17,8 @@ public class CustomTag {
|
||||
public static final String WALLET_ID_TAG = "wallet_id";
|
||||
public static final String WALLET_NAME_TAG = "wallet_name";
|
||||
public static final String DURATION_TAG = "duration";
|
||||
public static final String NUMERIC_CODE = "numeric_code";
|
||||
public static final String SYMBOLIC_CODE = "symbolic_code";
|
||||
|
||||
public static Tag providerId(String providerId) {
|
||||
return Tag.of(PROVIDER_ID_TAG, providerId);
|
||||
@ -61,4 +63,12 @@ public class CustomTag {
|
||||
public static Tag duration(String duration) {
|
||||
return Tag.of(DURATION_TAG, duration);
|
||||
}
|
||||
|
||||
public static Tag numericCode(String numericCode) {
|
||||
return Tag.of(NUMERIC_CODE, numericCode);
|
||||
}
|
||||
|
||||
public static Tag symbolicCode(String symbolicCode) {
|
||||
return Tag.of(SYMBOLIC_CODE, symbolicCode);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,11 @@ public enum Metric {
|
||||
|
||||
WITHDRAWALS_AMOUNT(
|
||||
formatWithPrefix("withdrawals_amount"),
|
||||
"Withdrawals amount since last scrape");
|
||||
"Withdrawals amount since last scrape"),
|
||||
|
||||
CURRENCY_EXPONENT(
|
||||
formatWithPrefix("currency_exponent"),
|
||||
"Currency exponent");
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
|
@ -0,0 +1,14 @@
|
||||
package dev.vality.exporter.businessmetrics.repository;
|
||||
|
||||
import dev.vality.exporter.businessmetrics.entity.currency.CurrencyEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface CurrencyRepository extends JpaRepository<CurrencyEntity, String> {
|
||||
|
||||
List<CurrencyEntity> findAllByCurrentIsTrue();
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package dev.vality.exporter.businessmetrics.service;
|
||||
|
||||
import dev.vality.exporter.businessmetrics.entity.currency.CurrencyEntity;
|
||||
import dev.vality.exporter.businessmetrics.model.CustomTag;
|
||||
import dev.vality.exporter.businessmetrics.model.Metric;
|
||||
import dev.vality.exporter.businessmetrics.repository.CurrencyRepository;
|
||||
import io.micrometer.core.instrument.MultiGauge;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@SuppressWarnings("LineLength")
|
||||
public class CurrencyService {
|
||||
|
||||
private static final String CURRENCY_EXPONENT = Metric.CURRENCY_EXPONENT.getName();
|
||||
|
||||
private final CurrencyRepository currencyRepository;
|
||||
private final MultiGauge multiGaugeCurrencyExponent;
|
||||
private final MeterRegistryService meterRegistryService;
|
||||
|
||||
public void registerMetrics() {
|
||||
processCurrencies();
|
||||
}
|
||||
|
||||
private void processCurrencies() {
|
||||
var currencyMetrics = currencyRepository.findAllByCurrentIsTrue();
|
||||
log.debug("Currencies metrics have been got from 'daway' db, count = {}",
|
||||
currencyMetrics.size());
|
||||
var rows = currencyMetrics.stream()
|
||||
.flatMap(dto -> {
|
||||
final var count = Double.parseDouble(dto.getExponent());
|
||||
return Map.of(
|
||||
CURRENCY_EXPONENT, MultiGauge.Row.of(getCurrencyTags(dto), this, o -> count)).entrySet().stream();
|
||||
})
|
||||
.collect(
|
||||
Collectors.groupingBy(
|
||||
Map.Entry::getKey,
|
||||
Collectors.mapping(
|
||||
Map.Entry::getValue,
|
||||
Collectors.<MultiGauge.Row<?>>toList())));
|
||||
multiGaugeCurrencyExponent.register(rows.getOrDefault(CURRENCY_EXPONENT, Collections.emptyList()), true);
|
||||
var registeredMetricsSize = meterRegistryService.getRegisteredMetricsSize(Metric.CURRENCY_EXPONENT.getName());
|
||||
log.info("Currencies metrics have been registered to 'prometheus', registeredMetricsSize = {}", registeredMetricsSize);
|
||||
|
||||
}
|
||||
|
||||
private Tags getCurrencyTags(CurrencyEntity dto) {
|
||||
return Tags.of(
|
||||
CustomTag.numericCode(dto.getNumericCode()),
|
||||
CustomTag.symbolicCode(dto.getSymbolicCode()));
|
||||
}
|
||||
}
|
@ -11,9 +11,11 @@ public class MetricsService {
|
||||
|
||||
private final PaymentService paymentService;
|
||||
private final WithdrawalService withdrawalService;
|
||||
private final CurrencyService currencyService;
|
||||
|
||||
public void registerMetrics() {
|
||||
paymentService.registerMetrics();
|
||||
withdrawalService.registerMetrics();
|
||||
currencyService.registerMetrics();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package dev.vality.exporter.businessmetrics;
|
||||
import dev.vality.exporter.businessmetrics.entity.payment.PaymentsAggregatedMetricDto;
|
||||
import dev.vality.exporter.businessmetrics.entity.payment.PaymentsTransactionCountMetricDto;
|
||||
import dev.vality.exporter.businessmetrics.entity.withdrawal.WithdrawalsAggregatedMetricDto;
|
||||
import dev.vality.exporter.businessmetrics.repository.CurrencyRepository;
|
||||
import dev.vality.exporter.businessmetrics.repository.PaymentRepository;
|
||||
import dev.vality.exporter.businessmetrics.repository.WithdrawalRepository;
|
||||
import dev.vality.exporter.businessmetrics.service.SchedulerRegisterMetricsService;
|
||||
@ -41,6 +42,9 @@ public class FlowTest {
|
||||
@MockBean
|
||||
private WithdrawalRepository withdrawalRepository;
|
||||
|
||||
@MockBean
|
||||
private CurrencyRepository currencyRepository;
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user