From 41317050c3611444142745b831f3d826aeb87f8a Mon Sep 17 00:00:00 2001 From: Jordan Hasgul Date: Thu, 8 Aug 2024 19:45:39 +0800 Subject: [PATCH] [APPENG-927] Yield MetricFilter's as Beans for Spring to apply to MeterRegistry via post processing (#46) * apply meter filters earlier Signed-off-by: Jordan Hasgul * just supply beans of meterfilter Signed-off-by: Jordan Hasgul * update changelog Signed-off-by: Jordan Hasgul * fix mysql not starting Signed-off-by: Jordan Hasgul * fix test names Signed-off-by: Jordan Hasgul * Provide TsMetricFilter not Tas Signed-off-by: Jordan Hasgul * add remaining filters as beans Signed-off-by: Jordan Hasgul * static for post processors Signed-off-by: Jordan Hasgul --------- Signed-off-by: Jordan Hasgul --- CHANGELOG.md | 6 ++++ gradle.properties | 2 +- .../EntryPointsAutoConfiguration.java | 32 +++++++++++++++++++ .../TransactionStatisticsIntTest.java | 4 +-- .../src/test/resources/application.yml | 10 +++--- ...AccessStatisticsEntryPointInterceptor.java | 1 - ...cutionStatisticsEntryPointInterceptor.java | 1 - .../TableAccessStatisticsSpyqlListener.java | 1 - .../TransactionsStatisticsSpyqlListener.java | 1 - 9 files changed, 47 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2198190..7edb2a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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). +## [2.16.3] - 2024-08-7 + +### Changed + +* MeterFilter's applied by the library are no longer explicitly applied and are instead + ## [2.16.2] - 2024-07-16 ### Added diff --git a/gradle.properties b/gradle.properties index 2cc408f..0e1ffcd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=2.16.2 +version=2.16.3 diff --git a/tw-entrypoints-starter/src/main/java/com/transferwise/common/entrypoints/EntryPointsAutoConfiguration.java b/tw-entrypoints-starter/src/main/java/com/transferwise/common/entrypoints/EntryPointsAutoConfiguration.java index 0bdac0e..184055a 100644 --- a/tw-entrypoints-starter/src/main/java/com/transferwise/common/entrypoints/EntryPointsAutoConfiguration.java +++ b/tw-entrypoints-starter/src/main/java/com/transferwise/common/entrypoints/EntryPointsAutoConfiguration.java @@ -5,20 +5,25 @@ import com.transferwise.common.baseutils.meters.cache.IMeterCache; import com.transferwise.common.baseutils.meters.cache.MeterCache; import com.transferwise.common.context.TwContext; +import com.transferwise.common.entrypoints.databaseaccessstatistics.DasMeterFilter; import com.transferwise.common.entrypoints.databaseaccessstatistics.DasUnknownCallsCollector; import com.transferwise.common.entrypoints.databaseaccessstatistics.DatabaseAccessStatisticsBeanPostProcessor; import com.transferwise.common.entrypoints.databaseaccessstatistics.DatabaseAccessStatisticsEntryPointInterceptor; +import com.transferwise.common.entrypoints.executionstatistics.EsMeterFilter; import com.transferwise.common.entrypoints.executionstatistics.ExecutionStatisticsEntryPointInterceptor; import com.transferwise.common.entrypoints.tableaccessstatistics.DefaultTasParsedQueryRegistry; import com.transferwise.common.entrypoints.tableaccessstatistics.DefaultTasQueryParsingInterceptor; import com.transferwise.common.entrypoints.tableaccessstatistics.DefaultTasQueryParsingListener; import com.transferwise.common.entrypoints.tableaccessstatistics.TableAccessStatisticsBeanPostProcessor; import com.transferwise.common.entrypoints.tableaccessstatistics.TasFlywayConfigurationCustomizer; +import com.transferwise.common.entrypoints.tableaccessstatistics.TasMeterFilter; import com.transferwise.common.entrypoints.tableaccessstatistics.TasParsedQueryRegistry; import com.transferwise.common.entrypoints.tableaccessstatistics.TasQueryParsingInterceptor; import com.transferwise.common.entrypoints.tableaccessstatistics.TasQueryParsingListener; import com.transferwise.common.entrypoints.transactionstatistics.TransactionStatisticsBeanPostProcessor; +import com.transferwise.common.entrypoints.transactionstatistics.TsMeterFilter; import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.config.MeterFilter; import org.springframework.beans.factory.BeanFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -60,6 +65,13 @@ public static DatabaseAccessStatisticsBeanPostProcessor twEntryPointsDatabaseAcc return new DatabaseAccessStatisticsBeanPostProcessor(); } + + @Bean + @ConditionalOnProperty(name = "tw-entrypoints.das.enabled", havingValue = "true", matchIfMissing = true) + public MeterFilter twEntryPointsDatabaseAccessStatisticsMeterFilter() { + return new DasMeterFilter(); + } + @Bean @ConditionalOnProperty(name = "tw-entrypoints.tas.enabled", havingValue = "true", matchIfMissing = true) @ConditionalOnMissingBean @@ -67,6 +79,12 @@ public static TableAccessStatisticsBeanPostProcessor twEntryPointsTableAccessSta return new TableAccessStatisticsBeanPostProcessor(beanFactory); } + @Bean + @ConditionalOnProperty(name = "tw-entrypoints.tas.enabled", havingValue = "true", matchIfMissing = true) + public MeterFilter twEntryPointsTableAccessStatisticsMeterFilter() { + return new TasMeterFilter(); + } + @Bean @ConditionalOnProperty(name = "tw-entrypoints.tas.enabled", havingValue = "true", matchIfMissing = true) @ConditionalOnMissingBean(TasParsedQueryRegistry.class) @@ -74,6 +92,7 @@ public DefaultTasParsedQueryRegistry twEntryPointsTableAccessStatisticsParsedQue return new DefaultTasParsedQueryRegistry(); } + @Bean @ConditionalOnProperty(name = "tw-entrypoints.tas.enabled", havingValue = "true", matchIfMissing = true) @ConditionalOnMissingBean(TasQueryParsingInterceptor.class) @@ -109,6 +128,12 @@ public static TransactionStatisticsBeanPostProcessor twEntryPointsTransactionSta return new TransactionStatisticsBeanPostProcessor(beanFactory); } + @Bean + @ConditionalOnProperty(name = "tw-entrypoints.ts.enabled", havingValue = "true", matchIfMissing = true) + public MeterFilter twEntryPointsTransactionStatisticsMetricsFilter() { + return new TsMeterFilter(); + } + @Bean @ConditionalOnProperty(name = "tw-entrypoints.es.enabled", havingValue = "true", matchIfMissing = true) @ConditionalOnMissingBean @@ -118,6 +143,13 @@ public ExecutionStatisticsEntryPointInterceptor twEntryPointsExecutionStatistics return interceptor; } + @Bean + @ConditionalOnProperty(name = "tw-entrypoints.es.enabled", havingValue = "true", matchIfMissing = true) + public MeterFilter twEntryPointsExecutionStatisticsMetricsFilter() { + return new EsMeterFilter(); + } + + @Bean @ConditionalOnMissingBean(IExecutorServicesProvider.class) public DefaultExecutorServicesProvider twDefaultExecutorServicesProvider() { diff --git a/tw-entrypoints-starter/src/test/java/com/transferwise/common/entrypoints/transactionstatistics/TransactionStatisticsIntTest.java b/tw-entrypoints-starter/src/test/java/com/transferwise/common/entrypoints/transactionstatistics/TransactionStatisticsIntTest.java index 49cbecf..f693b65 100644 --- a/tw-entrypoints-starter/src/test/java/com/transferwise/common/entrypoints/transactionstatistics/TransactionStatisticsIntTest.java +++ b/tw-entrypoints-starter/src/test/java/com/transferwise/common/entrypoints/transactionstatistics/TransactionStatisticsIntTest.java @@ -32,7 +32,7 @@ public void setup() { } @Test - public void successfullTransactionGetsRegisterd() { + public void successfulTransactionGetsRegistered() { transactionsHelper.withTransaction().call(() -> { jdbcTemplate.update("update table_a set version=2"); return null; @@ -73,7 +73,7 @@ public void successfullTransactionGetsRegisterd() { } @Test - public void rollbackGetsRegisterd() { + public void rollbackGetsRegistered() { try { transactionsHelper.withTransaction().call(() -> { jdbcTemplate.update("update table_a set version=2"); diff --git a/tw-entrypoints-starter/src/test/resources/application.yml b/tw-entrypoints-starter/src/test/resources/application.yml index 255723c..4fbc18c 100644 --- a/tw-entrypoints-starter/src/test/resources/application.yml +++ b/tw-entrypoints-starter/src/test/resources/application.yml @@ -13,9 +13,11 @@ tw-graceful-shutdown: --- spring: + datasource: + embedded: + mysql: + port: 3306 + enable: true config: activate: - on-profile: continuous-integration -embedded: - mysql: - port: 3306 + on-profile: continuous-integration \ No newline at end of file diff --git a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/databaseaccessstatistics/DatabaseAccessStatisticsEntryPointInterceptor.java b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/databaseaccessstatistics/DatabaseAccessStatisticsEntryPointInterceptor.java index 62d08a2..696dd60 100644 --- a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/databaseaccessstatistics/DatabaseAccessStatisticsEntryPointInterceptor.java +++ b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/databaseaccessstatistics/DatabaseAccessStatisticsEntryPointInterceptor.java @@ -35,7 +35,6 @@ public class DatabaseAccessStatisticsEntryPointInterceptor implements TwContextE public DatabaseAccessStatisticsEntryPointInterceptor(IMeterCache meterCache) { this.meterCache = meterCache; - meterCache.getMeterRegistry().config().meterFilter(new DasMeterFilter()); } @Override diff --git a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/executionstatistics/ExecutionStatisticsEntryPointInterceptor.java b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/executionstatistics/ExecutionStatisticsEntryPointInterceptor.java index d4c3341..30c1ce3 100644 --- a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/executionstatistics/ExecutionStatisticsEntryPointInterceptor.java +++ b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/executionstatistics/ExecutionStatisticsEntryPointInterceptor.java @@ -18,7 +18,6 @@ public class ExecutionStatisticsEntryPointInterceptor implements TwContextExecut public ExecutionStatisticsEntryPointInterceptor(IMeterCache meterCache) { this.meterCache = meterCache; - meterCache.getMeterRegistry().config().meterFilter(new EsMeterFilter()); } @Override diff --git a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/tableaccessstatistics/TableAccessStatisticsSpyqlListener.java b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/tableaccessstatistics/TableAccessStatisticsSpyqlListener.java index 42379d8..7df1e60 100644 --- a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/tableaccessstatistics/TableAccessStatisticsSpyqlListener.java +++ b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/tableaccessstatistics/TableAccessStatisticsSpyqlListener.java @@ -95,7 +95,6 @@ public TableAccessStatisticsSpyqlListener(IMeterCache meterCache, ExecutorServic this.tasQueryParsingListener = tasQueryParsingListener; final MeterRegistry meterRegistry = meterCache.getMeterRegistry(); - meterRegistry.config().meterFilter(new TasMeterFilter()); sqlParseResultsCache = Caffeine.newBuilder().maximumWeight(entryPointsProperties.getTas().getSqlParser().getCacheSizeMib() * MIB).recordStats() .executor(executorService) diff --git a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/transactionstatistics/TransactionsStatisticsSpyqlListener.java b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/transactionstatistics/TransactionsStatisticsSpyqlListener.java index 895e951..c963827 100644 --- a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/transactionstatistics/TransactionsStatisticsSpyqlListener.java +++ b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/transactionstatistics/TransactionsStatisticsSpyqlListener.java @@ -67,7 +67,6 @@ public class TransactionsStatisticsSpyqlListener implements SpyqlDataSourceListe public TransactionsStatisticsSpyqlListener(IMeterCache meterCache, String databaseName) { this.dbTag = Tag.of(EntryPointsMetrics.TAG_DATABASE, databaseName); this.meterCache = meterCache; - meterCache.getMeterRegistry().config().meterFilter(new TsMeterFilter()); } @Override