Skip to content

Commit

Permalink
[APPENG-927] Yield MetricFilter's as Beans for Spring to apply to Met…
Browse files Browse the repository at this point in the history
…erRegistry via post processing (#46)

* apply meter filters earlier

Signed-off-by: Jordan Hasgul <jordan.hasgul@transferwise.com>

* just supply beans of meterfilter

Signed-off-by: Jordan Hasgul <jordan.hasgul@transferwise.com>

* update changelog

Signed-off-by: Jordan Hasgul <jordan.hasgul@transferwise.com>

* fix mysql not starting

Signed-off-by: Jordan Hasgul <jordan.hasgul@transferwise.com>

* fix test names

Signed-off-by: Jordan Hasgul <jordan.hasgul@transferwise.com>

* Provide TsMetricFilter not Tas

Signed-off-by: Jordan Hasgul <jordan.hasgul@transferwise.com>

* add remaining filters as beans

Signed-off-by: Jordan Hasgul <jordan.hasgul@transferwise.com>

* static for post processors

Signed-off-by: Jordan Hasgul <jordan.hasgul@transferwise.com>

---------

Signed-off-by: Jordan Hasgul <jordan.hasgul@transferwise.com>
  • Loading branch information
jordanhasgul authored Aug 8, 2024
1 parent f249f76 commit 4131705
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.16.2
version=2.16.3
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,20 +65,34 @@ 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
public static TableAccessStatisticsBeanPostProcessor twEntryPointsTableAccessStatisticsBeanPostProcessor(BeanFactory beanFactory) {
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)
public DefaultTasParsedQueryRegistry twEntryPointsTableAccessStatisticsParsedQueryRegistry() {
return new DefaultTasParsedQueryRegistry();
}


@Bean
@ConditionalOnProperty(name = "tw-entrypoints.tas.enabled", havingValue = "true", matchIfMissing = true)
@ConditionalOnMissingBean(TasQueryParsingInterceptor.class)
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
10 changes: 6 additions & 4 deletions tw-entrypoints-starter/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class DatabaseAccessStatisticsEntryPointInterceptor implements TwContextE

public DatabaseAccessStatisticsEntryPointInterceptor(IMeterCache meterCache) {
this.meterCache = meterCache;
meterCache.getMeterRegistry().config().meterFilter(new DasMeterFilter());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class ExecutionStatisticsEntryPointInterceptor implements TwContextExecut

public ExecutionStatisticsEntryPointInterceptor(IMeterCache meterCache) {
this.meterCache = meterCache;
meterCache.getMeterRegistry().config().meterFilter(new EsMeterFilter());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4131705

Please sign in to comment.