Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APPENG-927] Yield MetricFilter's as Beans for Spring to apply to MeterRegistry via post processing #88

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.30.0
version=0.30.1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public IMeterCache twDefaultMeterCache(MeterRegistry meterRegistry) {
return new MeterCache(meterRegistry);
}



@Bean
@ConditionalOnMissingBean(ITransactionsHelper.class)
public TransactionsHelper twTransactionsHelper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +66,46 @@ public TkmsMetricsTemplate tkmsMetricsTemplate(IMeterCache meterCache, TkmsPrope
return new TkmsMetricsTemplate(meterCache, tkmsProperties);
}

@Bean
@ConditionalOnBean(ITkmsMetricsTemplate.class)
public MeterFilter tkmsMeterFilter() {
Map<String, double[]> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,41 +81,7 @@ public class TkmsMetricsTemplate implements ITkmsMetricsTemplate, InitializingBe

@Override
public void afterPropertiesSet() {
Map<String, double[]> 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
Expand Down
Loading