From 40c03cfdce904974e257f31c0645068c30b1b0c1 Mon Sep 17 00:00:00 2001 From: Jordan Hasgul Date: Thu, 8 Aug 2024 22:23:17 +0800 Subject: [PATCH 1/2] provide meter filter as bean Signed-off-by: Jordan Hasgul --- .../tkms/config/TkmsAutoConfiguration.java | 2 + .../kafka/tkms/config/TkmsConfiguration.java | 47 +++++++++++++++++++ .../tkms/metrics/TkmsMetricsTemplate.java | 36 +------------- 3 files changed, 50 insertions(+), 35 deletions(-) diff --git a/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/config/TkmsAutoConfiguration.java b/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/config/TkmsAutoConfiguration.java index 987a80c..b9f8b61 100644 --- a/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/config/TkmsAutoConfiguration.java +++ b/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/config/TkmsAutoConfiguration.java @@ -37,6 +37,8 @@ public IMeterCache twDefaultMeterCache(MeterRegistry meterRegistry) { return new MeterCache(meterRegistry); } + + @Bean @ConditionalOnMissingBean(ITransactionsHelper.class) public TransactionsHelper twTransactionsHelper() { diff --git a/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/config/TkmsConfiguration.java b/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/config/TkmsConfiguration.java index dfa87d2..1a650c1 100644 --- a/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/config/TkmsConfiguration.java +++ b/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/config/TkmsConfiguration.java @@ -28,6 +28,13 @@ import com.transferwise.kafka.tkms.metrics.ITkmsMetricsTemplate; import com.transferwise.kafka.tkms.metrics.TkmsClusterWideStateMonitor; import com.transferwise.kafka.tkms.metrics.TkmsMetricsTemplate; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.Meter.Type; +import io.micrometer.core.instrument.config.MeterFilter; +import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import javax.sql.DataSource; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -59,6 +66,46 @@ public TkmsMetricsTemplate tkmsMetricsTemplate(IMeterCache meterCache, TkmsPrope return new TkmsMetricsTemplate(meterCache, tkmsProperties); } + @Bean + @ConditionalOnBean(ITkmsMetricsTemplate.class) + public MeterFilter tkmsMeterFilter() { + Map slos = new HashMap<>(); + double[] defaultSlos = new double[]{1, 5, 25, 125, 625, 3125, 15625}; + slos.put(TkmsMetricsTemplate.TIMER_PROXY_POLL, defaultSlos); + slos.put(TkmsMetricsTemplate.TIMER_PROXY_CYCLE, defaultSlos); + slos.put(TkmsMetricsTemplate.TIMER_PROXY_CYCLE_PAUSE, defaultSlos); + slos.put(TkmsMetricsTemplate.TIMER_DAO_POLL_FIRST_RESULT, defaultSlos); + slos.put(TkmsMetricsTemplate.TIMRE_DAO_POLL_ALL_RESULTS, defaultSlos); + slos.put(TkmsMetricsTemplate.TIMER_DAO_POLL_GET_CONNECTION, defaultSlos); + slos.put(TkmsMetricsTemplate.TIMER_PROXY_KAFKA_MESSAGES_SEND, defaultSlos); + slos.put(TkmsMetricsTemplate.TIMER_PROXY_MESSAGES_DELETION, defaultSlos); + slos.put(TkmsMetricsTemplate.SUMMARY_DAO_POLL_ALL_RESULTS_COUNT, defaultSlos); + slos.put(TkmsMetricsTemplate.TIMER_MESSAGE_INSERT_TO_ACK, new double[]{1, 5, 25, 125, 625, 3125, 15625}); + slos.put(TkmsMetricsTemplate.SUMMARY_DAO_COMPRESSION_RATIO_ACHIEVED, new double[]{0.05, 0.1, 0.25, 0.5, 0.75, 1, 1.25, 2, 4}); + slos.put(TkmsMetricsTemplate.SUMMARY_MESSAGES_IN_TRANSACTION, new double[]{1, 5, 25, 125, 625, 3125, 15625, 5 * 15625}); + + return new MeterFilter() { + @Override + public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) { + double[] sloConfigValues = slos.get(id.getName()); + if (sloConfigValues != null) { + double[] sloValues = Arrays.copyOf(sloConfigValues, sloConfigValues.length); + if (id.getType() == Type.TIMER) { + for (int i = 0; i < sloValues.length; i++) { + sloValues[i] = sloValues[i] * 1_000_000L; + } + } + return DistributionStatisticConfig.builder() + .percentilesHistogram(false) + .serviceLevelObjectives(sloValues) + .build() + .merge(config); + } + return config; + } + }; + } + @Bean @ConditionalOnMissingBean(ITransactionalKafkaMessageSender.class) public TransactionalKafkaMessageSender tkmsTransactionalKafkaMessageSender() { diff --git a/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/metrics/TkmsMetricsTemplate.java b/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/metrics/TkmsMetricsTemplate.java index 11c1687..9963190 100644 --- a/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/metrics/TkmsMetricsTemplate.java +++ b/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/metrics/TkmsMetricsTemplate.java @@ -81,41 +81,7 @@ public class TkmsMetricsTemplate implements ITkmsMetricsTemplate, InitializingBe @Override public void afterPropertiesSet() { - Map slos = new HashMap<>(); - double[] defaultSlos = new double[]{1, 5, 25, 125, 625, 3125, 15625}; - slos.put(TIMER_PROXY_POLL, defaultSlos); - slos.put(TIMER_PROXY_CYCLE, defaultSlos); - slos.put(TIMER_PROXY_CYCLE_PAUSE, defaultSlos); - slos.put(TIMER_DAO_POLL_FIRST_RESULT, defaultSlos); - slos.put(TIMRE_DAO_POLL_ALL_RESULTS, defaultSlos); - slos.put(TIMER_DAO_POLL_GET_CONNECTION, defaultSlos); - slos.put(TIMER_PROXY_KAFKA_MESSAGES_SEND, defaultSlos); - slos.put(TIMER_PROXY_MESSAGES_DELETION, defaultSlos); - slos.put(SUMMARY_DAO_POLL_ALL_RESULTS_COUNT, defaultSlos); - slos.put(TIMER_MESSAGE_INSERT_TO_ACK, new double[]{1, 5, 25, 125, 625, 3125, 15625}); - slos.put(SUMMARY_DAO_COMPRESSION_RATIO_ACHIEVED, new double[]{0.05, 0.1, 0.25, 0.5, 0.75, 1, 1.25, 2, 4}); - slos.put(SUMMARY_MESSAGES_IN_TRANSACTION, new double[]{1, 5, 25, 125, 625, 3125, 15625, 5 * 15625}); - - meterCache.getMeterRegistry().config().meterFilter(new MeterFilter() { - @Override - public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) { - double[] sloConfigValues = slos.get(id.getName()); - if (sloConfigValues != null) { - double[] sloValues = Arrays.copyOf(sloConfigValues, sloConfigValues.length); - if (id.getType() == Type.TIMER) { - for (int i = 0; i < sloValues.length; i++) { - sloValues[i] = sloValues[i] * 1_000_000L; - } - } - return DistributionStatisticConfig.builder() - .percentilesHistogram(false) - .serviceLevelObjectives(sloValues) - .build() - .merge(config); - } - return config; - } - }); + } @Override From 49d640d8d4d4c85b4cc43fb5bacb156dee93326a Mon Sep 17 00:00:00 2001 From: Jordan Hasgul Date: Thu, 8 Aug 2024 22:23:26 +0800 Subject: [PATCH 2/2] update changelog and bump version Signed-off-by: Jordan Hasgul --- CHANGELOG.md | 4 ++++ gradle.properties | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25d59b4..43f1af6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.30.1] - 2024-08-08 +### Changed +- MeterFilter's applied by the library are no longer explicitly applied and are instead + ## [0.30.0] 2024-08-06 ### Added - Added `ITkmsMessageDecorator` that kicks in before message is registered and adds custom headers diff --git a/gradle.properties b/gradle.properties index 902c55f..fe6a7f0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=0.30.0 +version=0.30.1