From 7751e325900e8f58295c8935a62176e6907f1afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristo=20Kuusk=C3=BCll?= Date: Thu, 25 Jan 2024 11:37:21 +0200 Subject: [PATCH 1/5] Upgrading libraries, mainly the JSqlParser, to support more queries out of the box. --- CHANGELOG.md | 4 + build.common.gradle | 2 +- build.gradle | 15 +++- build.libraries.gradle | 17 +++-- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.jar | Bin 61608 -> 62076 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 7 +- .../TasFlywayConfigurationCustomizer.java | 2 +- .../common/entrypoints/test/BaseIntTest.java | 2 +- tw-entrypoints/build.gradle | 19 ++--- .../DasUnknownCallsCollector.java | 14 ++-- ...AccessStatisticsEntryPointInterceptor.java | 22 +++--- .../CustomTablesNamesFinder.java | 61 +++++---------- .../tableaccessstatistics/SqlParser.java | 40 ---------- .../TableAccessStatisticsSpyqlListener.java | 44 +++++++++-- .../TransactionsStatisticsSpyqlListener.java | 6 +- .../SqlParserUtilsTest.java | 70 ++++++++++++++---- 18 files changed, 169 insertions(+), 160 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adcabcb..ea85cec 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). +## [2.15.0] - 2024-01-25 + +* Upgrading libraries, mainly the JSqlParser, to support more queries out of the box. + ## [2.14.0] - 2023-09-26 ### Added diff --git a/build.common.gradle b/build.common.gradle index b83483e..1bc4189 100644 --- a/build.common.gradle +++ b/build.common.gradle @@ -126,8 +126,8 @@ test { } tasks.findAll { it.name.startsWith("spotbugs") }*.configure { - effort = "max" excludeFilter = file('../spotbugs-exclude.xml') + reports { xml.required = true html.required = true diff --git a/build.gradle b/build.gradle index 5078060..1a53b5e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,13 @@ +import com.github.spotbugs.snom.Confidence +import com.github.spotbugs.snom.Effort import org.eclipse.jgit.api.errors.RefAlreadyExistsException plugins { - id "com.github.spotbugs" version "5.0.13" apply false + id "com.github.spotbugs" version "6.0.7" id "idea" - id 'org.ajoberstar.grgit' version '5.0.0' - id 'io.github.gradle-nexus.publish-plugin' version "1.1.0" - id 'com.github.johnrengelman.shadow' version '7.0.0' apply false + id 'org.ajoberstar.grgit' version '5.2.1' + id 'io.github.gradle-nexus.publish-plugin' version "1.3.0" + id 'com.github.johnrengelman.shadow' version '8.1.1' apply false } idea.project { @@ -39,3 +41,8 @@ nexusPublishing { } } } + +spotbugs { + effort = Effort.valueOf('MAX') + reportLevel = Confidence.valueOf('DEFAULT') +} diff --git a/build.libraries.gradle b/build.libraries.gradle index 24ab9e4..45f38e8 100644 --- a/build.libraries.gradle +++ b/build.libraries.gradle @@ -3,18 +3,18 @@ ext { libraries = [ // explicit versions - guava : "com.google.guava:guava:31.1-jre", - jsqlParser : "com.github.jsqlparser:jsqlparser:4.6", + guava : "com.google.guava:guava:33.0.0-jre", + jsqlParser : "com.github.jsqlparser:jsqlparser:4.8", spotbugsAnnotations : "com.github.spotbugs:spotbugs-annotations:${spotbugs.toolVersion.get()}", springBootDependencies : "org.springframework.boot:spring-boot-dependencies:${springBootVersion}", - testContainersMariaDb : "org.testcontainers:mariadb:1.17.6", - twBaseUtils : "com.transferwise.common:tw-base-utils:1.10.1", + testContainersMariaDb : "org.testcontainers:mariadb:1.19.3", + twBaseUtils : "com.transferwise.common:tw-base-utils:1.12.3", twContext : "com.transferwise.common:tw-context:1.0.0", twContextStarter : "com.transferwise.common:tw-context-starter:1.0.0", - twGracefulShutdown : 'com.transferwise.common:tw-graceful-shutdown:2.11.0', - twGracefulShutdownInterfaces : 'com.transferwise.common:tw-graceful-shutdown-interfaces:2.11.0', - twSpyqlCore : "com.transferwise.common:tw-spyql-core:1.6.0", - twSpyqlStarter : "com.transferwise.common:tw-spyql-starter:1.6.0", + twGracefulShutdown : 'com.transferwise.common:tw-graceful-shutdown:2.14.2', + twGracefulShutdownInterfaces: 'com.transferwise.common:tw-graceful-shutdown-interfaces:2.14.2', + twSpyqlCore : "com.transferwise.common:tw-spyql-core:1.6.1", + twSpyqlStarter : "com.transferwise.common:tw-spyql-starter:1.6.1", // versions managed by spring-boot-dependencies platform caffeine : "com.github.ben-manes.caffeine:caffeine", @@ -24,6 +24,7 @@ ext { hikariCp : "com.zaxxer:HikariCP", junitJupiter : "org.junit.jupiter:junit-jupiter", + logbackClassic : "ch.qos.logback:logback-classic", lombok : "org.projectlombok:lombok", mariadbJavaClient : "org.mariadb.jdbc:mariadb-java-client", micrometerCore : "io.micrometer:micrometer-core", diff --git a/gradle.properties b/gradle.properties index 77685fc..6efb360 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=2.14.0 +version=2.15.0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ccebba7710deaf9f98673a68957ea02138b60d0a..c1962a79e29d3e0ab67b14947c167a862655af9b 100644 GIT binary patch delta 8979 zcmY*fV{{$d(moANW81db*tXT!Nn`UgX2ZtD$%&n`v2C-lt;YD?@2-14?EPcUv!0n* z`^Ws4HP4i8L%;4p*JkD-J9ja2aKi!sX@~#-MY5?EPBK~fXAl)Ti}^QGH@6h+V+|}F zv=1RqQxhWW9!hTvYE!)+*m%jEL^9caK;am9X8QP~a9X0N6(=WSX8KF#WpU-6TjyR3 zpKhscivP97d$DGc{KI(f#g07u{Jr0wn#+qNr}yW}2N3{Kx0lCq%p4LBKil*QDTEyR zg{{&=GAy_O0VJ(8ZbtS4tPeeeILKK(M?HtQY!6K^wt zxsPH>E%g%V@=!B;kWF54$xjC&4hO!ZEG0QFMHLqe!tgH;%vO62BQj||nokbX&2kxF zzg#N!2M|NxFL#YdwOL8}>iDLr%2=!LZvk_&`AMrm7Zm%#_{Ot_qw=HkdVg{f9hY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0m>**8D;+2ddTL>EcH_1YqCaTTu_#6Djm z*64!w#=Hz<>Fi1n+P}l#-)0e0P4o+D8^^Mk& zhHeJoh2paKlO+8r?$tx`qEcm|PSt6|1$1q?r@VvvMd1!*zAy3<`X9j?ZI|;jE-F(H zIn1+sm(zAnoJArtytHC|0&F0`i*dy-PiwbD-+j`ezvd4C`%F1y^7t}2aww}ZlPk)t z=Y`tm#jNM$d`pG%F42Xmg_pZnEnvC%avz=xNs!=6b%%JSuc(WObezkCeZ#C|3PpXj zkR8hDPyTIUv~?<%*)6=8`WfPPyB9goi+p$1N2N<%!tS2wopT2x`2IZi?|_P{GA|I5 z?7DP*?Gi#2SJZ!x#W9Npm)T;=;~Swyeb*!P{I^s@o5m_3GS2Lg?VUeBdOeae7&s5$ zSL_VuTJih_fq7g8O8b0g+GbmE+xG}^Wx`g~{mWTyr@=h zKlAymoHeZa`DgR?Pj8Yc+I|MrSB>X*ts#wNFOJxs!3aGE)xeTHlF`fC5^g(DTacl$ zx!ezQJdwIyc$8RyNS~Wh{0pp>8NcW)*J=7AQYdT?(QhJuq4u`QniZ!%6l{KWp-0Xp z4ZC6(E(_&c$$U_cmGFslsyX6(62~m*z8Yx2p+F5xmD%6A7eOnx`1lJA-Mrc#&xZWJ zzXV{{OIgzYaq|D4k^j%z|8JB8GnRu3hw#8Z@({sSmsF(x>!w0Meg5y(zg!Z0S^0k# z5x^g1@L;toCK$NB|Fn (m.getId().getName().startsWith("EntryPoints") || m.getId().getName().startsWith("database")) && !(m instanceof Gauge)) .forEach(m -> { - log.info("Removing metric: " + m.getId()); + log.debug("Removing metric: " + m.getId()); meterRegistry.remove(m); }); meterCache.clear(); diff --git a/tw-entrypoints/build.gradle b/tw-entrypoints/build.gradle index 5d09b08..7cecc42 100644 --- a/tw-entrypoints/build.gradle +++ b/tw-entrypoints/build.gradle @@ -22,17 +22,8 @@ dependencies { implementation libraries.twSpyqlCore implementation libraries.twGracefulShutdownInterfaces - shadow libraries.twContext - shadow libraries.commonsLang3 - shadow libraries.caffeine - shadow libraries.guava - shadow libraries.micrometerCore - shadow libraries.slf4jApi - shadow libraries.twBaseUtils - shadow libraries.twSpyqlCore - shadow libraries.twGracefulShutdownInterfaces - testImplementation libraries.junitJupiter + testRuntimeOnly libraries.logbackClassic } apply from: "build-idea-fix.gradle.kts" @@ -48,10 +39,10 @@ shadowJar { manifest { attributes 'Implementation-Version': "$project.version" } - relocate('net.sf.jsqlparser', 'com.transferwise.common.entrypoints.shadow') + relocate('net.sf.jsqlparser', 'com.transferwise.common.entrypoints.shadow.net.sf.jsqlparser') } -jar.enabled = true +jar.enabled = false jar.dependsOn shadowJar shadowJar { @@ -105,8 +96,8 @@ publishing { withXml { xml -> def dependenciesNode = xml.asNode().get('dependencies') ?: xml.asNode().appendNode('dependencies') - project.configurations.getByName("shadow").resolvedConfiguration.firstLevelModuleDependencies.forEach { - if (it.configuration != "platform-runtime") { + project.configurations.getByName("runtimeClasspath").resolvedConfiguration.firstLevelModuleDependencies.forEach { + if (it.configuration != "platform-runtime" && it.moduleName != 'jsqlparser') { def dependencyNode = dependenciesNode.appendNode('dependency') dependencyNode.appendNode('groupId', it.moduleGroup) dependencyNode.appendNode('artifactId', it.moduleName) diff --git a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/databaseaccessstatistics/DasUnknownCallsCollector.java b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/databaseaccessstatistics/DasUnknownCallsCollector.java index 76a074c..959d2ea 100644 --- a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/databaseaccessstatistics/DasUnknownCallsCollector.java +++ b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/databaseaccessstatistics/DasUnknownCallsCollector.java @@ -49,14 +49,14 @@ protected void registerUnknownCalls() { final long fetchedRows = das.getAndResetFetchedRowsCount(); TagsSet tagsSet = das.getTagsSet(); - UnknownCallMeters meters = meterCache.metersContainer(METRIC_PREFIX_DAS + "unknownCallMetrics", tagsSet, () -> { + UnknownCallMeters meters = meterCache.metersContainer(METRIC_PREFIX_DAS + "unknownCallMetrics", tagsSet, (name, tags) -> { UnknownCallMeters result = new UnknownCallMeters(); - result.commits = meterCache.counter(COUNTER_UNREGISTERED_COMMITS, tagsSet); - result.rollbacks = meterCache.counter(COUNTER_UNREGISTERED_ROLLBACKS, tagsSet); - result.nonTransactionalQueries = meterCache.counter(COUNTER_UNREGISTERED_NT_QUERIES, tagsSet); - result.transactionalQueries = meterCache.counter(COUNTER_UNREGISTERED_T_QUERIES, tagsSet); - result.timeTakenNs = meterCache.counter(COUNTER_UNREGISTERED_TIME_TAKEN_NS, tagsSet); - result.emptyTransactions = meterCache.counter(COUNTER_UNREGISTERED_EMPTY_TRANSACTIONS, tagsSet); + result.commits = meterCache.counter(COUNTER_UNREGISTERED_COMMITS, tags); + result.rollbacks = meterCache.counter(COUNTER_UNREGISTERED_ROLLBACKS, tags); + result.nonTransactionalQueries = meterCache.counter(COUNTER_UNREGISTERED_NT_QUERIES, tags); + result.transactionalQueries = meterCache.counter(COUNTER_UNREGISTERED_T_QUERIES, tags); + result.timeTakenNs = meterCache.counter(COUNTER_UNREGISTERED_TIME_TAKEN_NS, tags); + result.emptyTransactions = meterCache.counter(COUNTER_UNREGISTERED_EMPTY_TRANSACTIONS, tags); result.affectedRows = meterCache.counter(COUNTER_UNREGISTERED_AFFECTED_ROWS, tagsSet); result.fetchedRows = meterCache.counter(COUNTER_UNREGISTERED_FETCHED_ROWS, tagsSet); return result; 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 e5563c2..62d08a2 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 @@ -71,18 +71,18 @@ private void registerCall(TwContext context, Map { + CallMeters meters = meterCache.metersContainer(METRIC_PREFIX_DAS + "callMetrics", tagsSet, (name, tags) -> { CallMeters result = new CallMeters(); - result.commits = meterCache.summary(SUMMARY_REGISTERED_COMMITS, tagsSet); - result.rollbacks = meterCache.summary(SUMMARY_REGISTERED_ROLLBACKS, tagsSet); - result.nonTransactionalQueries = meterCache.summary(SUMMARY_REGISTERED_NT_QUERIES, tagsSet); - result.transactionalQueries = meterCache.summary(SUMMARY_REGISTERED_T_QUERIES, tagsSet); - result.maxConcurrentConnections = meterCache.summary(SUMMARY_REGISTERED_MAX_CONCURRENT_CONNECTIONS, tagsSet); - result.remainingOpenConnections = meterCache.summary(SUMMARY_REGISTERED_REMAINING_OPEN_CONNECTIONS, tagsSet); - result.emptyTransactions = meterCache.summary(SUMMARY_REGISTERED_EMPTY_TRANSACTIONS, tagsSet); - result.affectedRows = meterCache.summary(SUMMARY_REGISTERED_AFFECTED_ROWS, tagsSet); - result.fetchedRows = meterCache.summary(SUMMARY_REGISTERED_FETCHED_ROWS, tagsSet); - result.timeTakenNs = meterCache.timer(TIMER_REGISTERED_TIME_TAKEN, tagsSet); + result.commits = meterCache.summary(SUMMARY_REGISTERED_COMMITS, tags); + result.rollbacks = meterCache.summary(SUMMARY_REGISTERED_ROLLBACKS, tags); + result.nonTransactionalQueries = meterCache.summary(SUMMARY_REGISTERED_NT_QUERIES, tags); + result.transactionalQueries = meterCache.summary(SUMMARY_REGISTERED_T_QUERIES, tags); + result.maxConcurrentConnections = meterCache.summary(SUMMARY_REGISTERED_MAX_CONCURRENT_CONNECTIONS, tags); + result.remainingOpenConnections = meterCache.summary(SUMMARY_REGISTERED_REMAINING_OPEN_CONNECTIONS, tags); + result.emptyTransactions = meterCache.summary(SUMMARY_REGISTERED_EMPTY_TRANSACTIONS, tags); + result.affectedRows = meterCache.summary(SUMMARY_REGISTERED_AFFECTED_ROWS, tags); + result.fetchedRows = meterCache.summary(SUMMARY_REGISTERED_FETCHED_ROWS, tags); + result.timeTakenNs = meterCache.timer(TIMER_REGISTERED_TIME_TAKEN, tags); return result; }); diff --git a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/tableaccessstatistics/CustomTablesNamesFinder.java b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/tableaccessstatistics/CustomTablesNamesFinder.java index abe449d..0169e96 100644 --- a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/tableaccessstatistics/CustomTablesNamesFinder.java +++ b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/tableaccessstatistics/CustomTablesNamesFinder.java @@ -1,56 +1,33 @@ package com.transferwise.common.entrypoints.tableaccessstatistics; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import lombok.Getter; import net.sf.jsqlparser.schema.Table; -import net.sf.jsqlparser.statement.SetStatement; -import net.sf.jsqlparser.statement.ShowColumnsStatement; -import net.sf.jsqlparser.statement.Statements; -import net.sf.jsqlparser.statement.alter.Alter; -import net.sf.jsqlparser.statement.create.index.CreateIndex; -import net.sf.jsqlparser.statement.create.view.CreateView; -import net.sf.jsqlparser.statement.drop.Drop; -import net.sf.jsqlparser.statement.execute.Execute; import net.sf.jsqlparser.util.TablesNamesFinder; public class CustomTablesNamesFinder extends TablesNamesFinder { - @Override - protected String extractTableName(Table table) { - return table.getName(); - } - - @Override - public void visit(Drop drop) { - visit(drop.getName()); - } - - @Override - public void visit(CreateIndex createIndex) { - visit(createIndex.getTable()); - } - - @Override - public void visit(CreateView createView) { - visit(createView.getView()); - } + @Getter + private final List tables = new ArrayList<>(); + private final Set uniqueTables = new HashSet<>(); - @Override - public void visit(Alter alter) { - visit(alter.getTable()); - } - - @Override - public void visit(Statements stmts) { - } + /* + The super class loses the order of tables visited, as its tables list is based on Set. + We are providing here the option to get the ordered tables list. + */ @Override - public void visit(Execute execute) { - } + public void visit(Table tableName) { + String tableWholeName = extractTableName(tableName); - @Override - public void visit(SetStatement set) { - } + if (!uniqueTables.contains(tableWholeName)) { + uniqueTables.add(tableWholeName); + tables.add(tableWholeName); + } - @Override - public void visit(ShowColumnsStatement set) { + super.visit(tableName); } } diff --git a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/tableaccessstatistics/SqlParser.java b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/tableaccessstatistics/SqlParser.java index dbcb83c..8fcf66f 100644 --- a/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/tableaccessstatistics/SqlParser.java +++ b/tw-entrypoints/src/main/java/com/transferwise/common/entrypoints/tableaccessstatistics/SqlParser.java @@ -4,8 +4,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.parser.CCJSqlParser; import net.sf.jsqlparser.parser.StringProvider; @@ -13,15 +11,6 @@ public class SqlParser { - /* - DATABASE is reserved keyword in sql parser, so having DATABASE() in sql will just throw error. - DATABASE() is however used by some of our internal libraries for MariaDb. - */ - private static final Pattern FUNCTION_REPLACEMENT_PATTERN = Pattern.compile("DATABASE()", - Pattern.LITERAL | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); - - private static final Pattern ON_CONFLICT_REPLACEMENT_PATTERN = Pattern.compile("on\\s*conflict\\s*\\(.*?\\)", - Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL); private final ExecutorService executorService; public SqlParser(ExecutorService executorService) { @@ -29,39 +18,10 @@ public SqlParser(ExecutorService executorService) { } public Statements parse(String sql, Duration timeout) throws JSQLParserException { - sql = replaceFunctions(sql); - sql = replaceOnConflicts(sql); - CCJSqlParser parser = newParser(sql).withAllowComplexParsing(true); return parseStatementAsync(parser, timeout); } - // Sqlparser 4.6 does not support "on conflict" clause with multiple parameters. - // As a workaround, we change the query to a single parameter clause. - protected String replaceOnConflicts(String sql) { - var matcher = ON_CONFLICT_REPLACEMENT_PATTERN.matcher(sql); - - // 99.99% of sqls don't have it, so let's avoid new string creation for those. - if (matcher.find()) { - matcher.reset(); - return matcher.replaceAll(Matcher.quoteReplacement("on conflict (blah)")); - } - - return sql; - } - - protected String replaceFunctions(String sql) { - var matcher = FUNCTION_REPLACEMENT_PATTERN.matcher(sql); - - // 99.99% of sqls don't have it, so let's avoid new string creation for those. - if (matcher.find()) { - matcher.reset(); - return matcher.replaceAll(Matcher.quoteReplacement("UNSUPPORTED()")); - } - - return sql; - } - protected Statements parseStatementAsync(CCJSqlParser parser, Duration timeout) throws JSQLParserException { try { var future = executorService.submit(parser::Statements); 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 c7e872c..5883454 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 @@ -32,7 +32,14 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; +import net.sf.jsqlparser.statement.SetStatement; import net.sf.jsqlparser.statement.Statement; +import net.sf.jsqlparser.statement.UnsupportedStatement; +import net.sf.jsqlparser.statement.delete.Delete; +import net.sf.jsqlparser.statement.insert.Insert; +import net.sf.jsqlparser.statement.select.Select; +import net.sf.jsqlparser.statement.truncate.Truncate; +import net.sf.jsqlparser.statement.update.Update; import org.apache.commons.lang3.StringUtils; @Slf4j @@ -120,18 +127,26 @@ protected ParsedQuery parseSql(String sql, TwContext context) { return new ParsedQuery(); } - ParsedQuery result = new ParsedQuery(); - long startTimeMs = System.currentTimeMillis(); + var result = new ParsedQuery(); + var startTimeMs = System.currentTimeMillis(); try { var stmts = sqlParser.parse(sql, entryPointsProperties.getTas().getSqlParser().getTimeout()); - for (Statement stmt : stmts.getStatements()) { + for (var stmt : stmts) { + if (stmt instanceof UnsupportedStatement) { + throw new IllegalStateException("Unsupported statement."); + } + } + + for (Statement stmt : stmts) { + // Intern() makes later equal checks much faster. - String opName = getOperationName(stmt).intern(); - CustomTablesNamesFinder tablesNamesFinder = new CustomTablesNamesFinder(); + var opName = getOperationName(stmt).intern(); + var tablesNamesFinder = new CustomTablesNamesFinder(); List tableNames = null; try { - tableNames = tablesNamesFinder.getTableList(stmt); + tablesNamesFinder.getTables(stmt); + tableNames = tablesNamesFinder.getTables(); } catch (UnsupportedOperationException e) { // Some type of statements do not support finding table names. // For example a statement 'SHOW FULL TABLES IN ...'. @@ -199,8 +214,21 @@ protected String trimTableName(String tableName) { } protected String getOperationName(Statement stmt) { - // class.getSimpleName() is very slow on JDK 8 - return StringUtils.substringAfterLast(stmt.getClass().getName(), ".").toLowerCase(); + if (stmt instanceof Select) { + return "select"; + } else if (stmt instanceof Update) { + return "update"; + } else if (stmt instanceof Insert) { + return "insert"; + } else if (stmt instanceof Delete) { + return "delete"; + } else if (stmt instanceof Truncate) { + return "truncate"; + } else if (stmt instanceof SetStatement) { + return "set"; + } + + return stmt.getClass().getSimpleName().toLowerCase(); } class ConnectionListener implements SpyqlConnectionListener { 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 6a894c7..895e951 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 @@ -135,10 +135,10 @@ TAG_TRANSACTION_NAME, nullToUnknown(transactionDefinition.getName()), operationTag.getKey(), operationTag.getValue(), readOnlyTag.getKey(), readOnlyTag.getValue()); - TransactionMetrics metrics = meterCache.metersContainer(METRIC_COLLECTION_TRANSACTION_END, tagsSet, () -> { + TransactionMetrics metrics = meterCache.metersContainer(METRIC_COLLECTION_TRANSACTION_END, tagsSet, (name, tags) -> { TransactionMetrics result = new TransactionMetrics(); - result.completion = meterCache.timer(METRIC_TRANSACTION_COMPLETION, tagsSet); - result.finalization = meterCache.timer(METRIC_TRANSACTION_FINALIZATION, tagsSet); + result.completion = meterCache.timer(METRIC_TRANSACTION_COMPLETION, tags); + result.finalization = meterCache.timer(METRIC_TRANSACTION_FINALIZATION, tags); return result; }); diff --git a/tw-entrypoints/src/test/java/com/transferwise/common/entrypoints/tableaccessstatistics/SqlParserUtilsTest.java b/tw-entrypoints/src/test/java/com/transferwise/common/entrypoints/tableaccessstatistics/SqlParserUtilsTest.java index 638d16f..0e7de72 100644 --- a/tw-entrypoints/src/test/java/com/transferwise/common/entrypoints/tableaccessstatistics/SqlParserUtilsTest.java +++ b/tw-entrypoints/src/test/java/com/transferwise/common/entrypoints/tableaccessstatistics/SqlParserUtilsTest.java @@ -5,52 +5,92 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executors; +import lombok.Data; +import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.JSQLParserException; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +@Slf4j class SqlParserUtilsTest { @Test @SneakyThrows void testJSqlParser() { - List sqls = new ArrayList<>(); + final List testCases = new ArrayList<>(); - sqls.add("insert into fin_unique_tw_task_key(task_id,key_hash,key) values(?, ?, ?) on conflict (key_hash, key) do nothing"); + testCases.add(new TestCase("insert into fin_unique_tw_task_key(task_id,key_hash,key) values(?, ?, ?) on conflict (key_hash, key) do nothing", + List.of("fin_unique_tw_task_key"))); // DATABASE is a keyword for sql parser. - sqls.add("select DATABASE()"); + testCases.add(new TestCase("select DATABASE()", + List.of())); - sqls.add("delete tl from tag_links tl, tags t where t.name=? and tl.type=? and tl.tag_ref=? and tl.tag_id = t.id"); - sqls.add("select table_rows from information_schema.tables where table_schema=DATABASE() and table_name = 'tw_task'"); + testCases.add(new TestCase("delete tl from tag_links tl, tags t where t.name=? and tl.type=? and tl.tag_ref=? and tl.tag_id = t.id", + List.of("tag_links", "tags"))); + testCases.add(new TestCase("select table_rows from information_schema.tables where table_schema=DATABASE() and table_name = 'tw_task'", + List.of("information_schema.tables"))); - sqls.add("SHOW FULL TABLES IN fx WHERE TABLE_TYPE NOT LIKE 'VIEW'"); + testCases.add(new TestCase("SHOW FULL TABLES IN fx WHERE TABLE_TYPE NOT LIKE 'VIEW'", + List.of())); - sqls.add("SET statement_timeout TO '18000'"); - sqls.add("set idle_in_transaction_session_timeout to '600000'"); + testCases.add(new TestCase("SET statement_timeout TO '18000'", + List.of())); + testCases.add(new TestCase("set idle_in_transaction_session_timeout to '600000'", + List.of())); - sqls.add("insert into fin_unique_tw_task_key(task_id,key_hash,key) values(?, ?, ?) on conflict (key_hash, key) do nothing"); + testCases.add(new TestCase("insert into fin_unique_tw_task_key(task_id,key_hash,key) values(?, ?, ?) on conflict (key_hash, key) do nothing", + List.of("fin_unique_tw_task_key"))); + + testCases.add(new TestCase("UPDATE ninjas_wkp_partition_locks USE INDEX (uqidx1) set deadline=?", + List.of("ninjas_wkp_partition_locks"))); + + testCases.add(new TestCase("truncate table_a; truncate table_b", + List.of("table_a", "table_b"))); // Not supported by JSqlParser - // sqls.add("truncate table_a, table_b"); + // testCases.add(new TestCase("truncate table_a, table_b", + // List.of("table_a", "table_b"))); var sqlParser = new SqlParser(Executors.newCachedThreadPool()); var interceptor = new DefaultTasQueryParsingInterceptor(); - for (String sql : sqls) { + for (TestCase testCase : testCases) { try { - var interceptResult = interceptor.intercept(sql); + var interceptResult = interceptor.intercept(testCase.getSql()); if (interceptResult.getDecision() == Decision.SKIP) { continue; } - var statements = sqlParser.parse(sql, Duration.ofSeconds(5)); + var statements = sqlParser.parse(testCase.getSql(), Duration.ofSeconds(5)); + + List tables = new ArrayList<>(); + + for (var stmt : statements) { + var tablesNamesFinder = new CustomTablesNamesFinder(); + try { + tablesNamesFinder.getTables(stmt); + } catch (UnsupportedOperationException ignored) { + //ignored + } + tables.addAll(tablesNamesFinder.getTables()); + } + + Assertions.assertEquals(testCase.getExpectedTables(), tables); - statements.getStatements(); } catch (JSQLParserException e) { - throw new RuntimeException("Failed to parse sql '" + sql + "'.", e); + throw new RuntimeException("Failed to parse sql '" + testCase.getSql() + "'.", e); } } } + @RequiredArgsConstructor + @Data + private static class TestCase { + + private final String sql; + private final List expectedTables; + } } From 613ca640d5d2631fd7d1d95bc20247ddb6668018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristo=20Kuusk=C3=BCll?= Date: Thu, 25 Jan 2024 11:42:33 +0200 Subject: [PATCH 2/5] Fix. --- .github/workflows/build.yml | 8 ++++---- build.libraries.gradle | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9f9a53b..b7017ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,10 +18,10 @@ jobs: max-parallel: 100 matrix: spring_boot_version: - - 3.1.2 - - 3.0.7 - - 2.7.13 - - 2.6.15 + - 3.2.2 + - 3.1.6 + - 3.0.13 + - 2.7.18 env: SPRING_BOOT_VERSION: ${{ matrix.spring_boot_version }} services: diff --git a/build.libraries.gradle b/build.libraries.gradle index 45f38e8..452bc25 100644 --- a/build.libraries.gradle +++ b/build.libraries.gradle @@ -1,5 +1,5 @@ ext { - springBootVersion = System.getenv("SPRING_BOOT_VERSION") ?: "2.6.15" + springBootVersion = System.getenv("SPRING_BOOT_VERSION") ?: "2.7.18" libraries = [ // explicit versions From cdf868f6551f9379b11038a328dc48400f701351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristo=20Kuusk=C3=BCll?= Date: Fri, 26 Jan 2024 15:30:47 +0200 Subject: [PATCH 3/5] Fix. --- .../TableAccessStatisticsSpyqlListener.java | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) 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 5883454..fed72cc 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 @@ -13,7 +13,6 @@ import com.transferwise.common.context.TwContextMetricsTemplate; import com.transferwise.common.entrypoints.EntryPointsMetrics; import com.transferwise.common.entrypoints.EntryPointsProperties; -import com.transferwise.common.entrypoints.tableaccessstatistics.ParsedQuery.SqlOperation; import com.transferwise.common.entrypoints.tableaccessstatistics.TasQueryParsingInterceptor.InterceptResult.Decision; import com.transferwise.common.spyql.event.GetConnectionEvent; import com.transferwise.common.spyql.event.StatementExecuteEvent; @@ -21,14 +20,12 @@ import com.transferwise.common.spyql.listener.SpyqlConnectionListener; import com.transferwise.common.spyql.listener.SpyqlDataSourceListener; import io.micrometer.core.instrument.Gauge; -import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.binder.cache.CaffeineCacheMetrics; import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.List; -import java.util.Map.Entry; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; @@ -92,7 +89,7 @@ public TableAccessStatisticsSpyqlListener(IMeterCache meterCache, ExecutorServic this.tasQueryParsingInterceptor = tasQueryParsingInterceptor; this.tasQueryParsingListener = tasQueryParsingListener; - MeterRegistry meterRegistry = meterCache.getMeterRegistry(); + final var meterRegistry = meterCache.getMeterRegistry(); meterRegistry.config().meterFilter(new TasMeterFilter()); sqlParseResultsCache = Caffeine.newBuilder().maximumWeight(entryPointsProperties.getTas().getSqlParser().getCacheSizeMib() * MIB).recordStats() @@ -120,17 +117,17 @@ public SpyqlConnectionListener onGetConnection(GetConnectionEvent event) { } protected ParsedQuery parseSql(String sql, TwContext context) { - var interceptResult = tasQueryParsingInterceptor.intercept(sql); + final var interceptResult = tasQueryParsingInterceptor.intercept(sql); if (interceptResult.getDecision() == Decision.CUSTOM_PARSED_QUERY) { return interceptResult.getParsedQuery(); } else if (interceptResult.getDecision() == Decision.SKIP) { return new ParsedQuery(); } - var result = new ParsedQuery(); - var startTimeMs = System.currentTimeMillis(); + final var result = new ParsedQuery(); + final var startTimeMs = System.currentTimeMillis(); try { - var stmts = sqlParser.parse(sql, entryPointsProperties.getTas().getSqlParser().getTimeout()); + final var stmts = sqlParser.parse(sql, entryPointsProperties.getTas().getSqlParser().getTimeout()); for (var stmt : stmts) { if (stmt instanceof UnsupportedStatement) { @@ -138,7 +135,7 @@ protected ParsedQuery parseSql(String sql, TwContext context) { } } - for (Statement stmt : stmts) { + for (var stmt : stmts) { // Intern() makes later equal checks much faster. var opName = getOperationName(stmt).intern(); @@ -153,12 +150,12 @@ protected ParsedQuery parseSql(String sql, TwContext context) { log.debug("Unsupported query '{}'.", sql, e); } - ParsedQuery.SqlOperation sqlOp = result + final var sqlOp = result .getOperations() .computeIfAbsent(opName, k -> new ParsedQuery.SqlOperation()); if (tableNames != null) { - for (String tableName : tableNames) { + for (var tableName : tableNames) { tableName = trimTableName(tableName); // Intern() makes later equal checks much faster. tableName = tableName.intern(); @@ -184,7 +181,7 @@ protected ParsedQuery parseSql(String sql, TwContext context) { )).increment(); tasQueryParsingListener.parsingFailed(sql, Duration.of(System.currentTimeMillis() - startTimeMs, ChronoUnit.MILLIS), t); } finally { - long durationMs = System.currentTimeMillis() - startTimeMs; + var durationMs = System.currentTimeMillis() - startTimeMs; if (durationMs > entryPointsProperties.getTas().getSqlParser().getParseDurationWarnThreshold().toMillis()) { meterCache.counter(COUNTER_SLOW_PARSES, TagsSet.of( EntryPointsMetrics.TAG_DATABASE, databaseName, @@ -244,11 +241,11 @@ public void onStatementExecuteFailure(StatementExecuteFailureEvent event) { } protected void registerSql(String sql, boolean isInTransaction, boolean succeeded, long executionTimeNs) { - TwContext context = TwContext.current(); - final Tag inTransactionTag = isInTransaction ? TAG_IN_TRANSACTION_TRUE : TAG_IN_TRANSACTION_FALSE; - final Tag successTag = succeeded ? TAG_SUCCESS_TRUE : TAG_SUCCESS_FALSE; + final var context = TwContext.current(); + final var inTransactionTag = isInTransaction ? TAG_IN_TRANSACTION_TRUE : TAG_IN_TRANSACTION_FALSE; + final var successTag = succeeded ? TAG_SUCCESS_TRUE : TAG_SUCCESS_FALSE; - ParsedQuery parsedQuery = tasParsedQueryRegistry.get(sql); + var parsedQuery = tasParsedQueryRegistry.get(sql); if (parsedQuery == null) { if (TasUtils.isQueryParsingEnabled(TwContext.current())) { @@ -272,13 +269,13 @@ protected void registerSql(String sql, boolean isInTransaction, boolean succeede return; } - for (Entry entry : parsedQuery.getOperations().entrySet()) { - String opName = entry.getKey(); - SqlOperation op = entry.getValue(); + for (var entry : parsedQuery.getOperations().entrySet()) { + final var opName = entry.getKey(); + final var op = entry.getValue(); if (op.getTableNames() != null) { String firstTableName = null; - for (String tableName : op.getTableNames()) { - TagsSet tagsSet = TagsSet.of( + for (var tableName : op.getTableNames()) { + final var tagsSet = TagsSet.of( dbTag.getKey(), dbTag.getValue(), TwContextMetricsTemplate.TAG_EP_GROUP, context.getGroup(), TwContextMetricsTemplate.TAG_EP_NAME, context.getName(), From 46b108762f28de760352b3a75b3ebaf8562f00fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristo=20Kuusk=C3=BCll?= Date: Fri, 26 Jan 2024 15:46:05 +0200 Subject: [PATCH 4/5] Fix. --- .../TableAccessStatisticsSpyqlListener.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) 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 fed72cc..f535429 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 @@ -13,6 +13,8 @@ import com.transferwise.common.context.TwContextMetricsTemplate; import com.transferwise.common.entrypoints.EntryPointsMetrics; import com.transferwise.common.entrypoints.EntryPointsProperties; +import com.transferwise.common.entrypoints.tableaccessstatistics.ParsedQuery.SqlOperation; +import com.transferwise.common.entrypoints.tableaccessstatistics.TasQueryParsingInterceptor.InterceptResult; import com.transferwise.common.entrypoints.tableaccessstatistics.TasQueryParsingInterceptor.InterceptResult.Decision; import com.transferwise.common.spyql.event.GetConnectionEvent; import com.transferwise.common.spyql.event.StatementExecuteEvent; @@ -26,11 +28,13 @@ import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.List; +import java.util.Map.Entry; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.statement.SetStatement; import net.sf.jsqlparser.statement.Statement; +import net.sf.jsqlparser.statement.Statements; import net.sf.jsqlparser.statement.UnsupportedStatement; import net.sf.jsqlparser.statement.delete.Delete; import net.sf.jsqlparser.statement.insert.Insert; @@ -117,7 +121,7 @@ public SpyqlConnectionListener onGetConnection(GetConnectionEvent event) { } protected ParsedQuery parseSql(String sql, TwContext context) { - final var interceptResult = tasQueryParsingInterceptor.intercept(sql); + final InterceptResult interceptResult = tasQueryParsingInterceptor.intercept(sql); if (interceptResult.getDecision() == Decision.CUSTOM_PARSED_QUERY) { return interceptResult.getParsedQuery(); } else if (interceptResult.getDecision() == Decision.SKIP) { @@ -127,19 +131,19 @@ protected ParsedQuery parseSql(String sql, TwContext context) { final var result = new ParsedQuery(); final var startTimeMs = System.currentTimeMillis(); try { - final var stmts = sqlParser.parse(sql, entryPointsProperties.getTas().getSqlParser().getTimeout()); + final Statements stmts = sqlParser.parse(sql, entryPointsProperties.getTas().getSqlParser().getTimeout()); - for (var stmt : stmts) { + for (Statement stmt : stmts) { if (stmt instanceof UnsupportedStatement) { throw new IllegalStateException("Unsupported statement."); } } - for (var stmt : stmts) { + for (Statement stmt : stmts) { // Intern() makes later equal checks much faster. - var opName = getOperationName(stmt).intern(); - var tablesNamesFinder = new CustomTablesNamesFinder(); + final String opName = getOperationName(stmt).intern(); + final CustomTablesNamesFinder tablesNamesFinder = new CustomTablesNamesFinder(); List tableNames = null; try { tablesNamesFinder.getTables(stmt); @@ -150,12 +154,12 @@ protected ParsedQuery parseSql(String sql, TwContext context) { log.debug("Unsupported query '{}'.", sql, e); } - final var sqlOp = result + final SqlOperation sqlOp = result .getOperations() .computeIfAbsent(opName, k -> new ParsedQuery.SqlOperation()); if (tableNames != null) { - for (var tableName : tableNames) { + for (String tableName : tableNames) { tableName = trimTableName(tableName); // Intern() makes later equal checks much faster. tableName = tableName.intern(); @@ -242,16 +246,16 @@ public void onStatementExecuteFailure(StatementExecuteFailureEvent event) { protected void registerSql(String sql, boolean isInTransaction, boolean succeeded, long executionTimeNs) { final var context = TwContext.current(); - final var inTransactionTag = isInTransaction ? TAG_IN_TRANSACTION_TRUE : TAG_IN_TRANSACTION_FALSE; - final var successTag = succeeded ? TAG_SUCCESS_TRUE : TAG_SUCCESS_FALSE; + final Tag inTransactionTag = isInTransaction ? TAG_IN_TRANSACTION_TRUE : TAG_IN_TRANSACTION_FALSE; + final Tag successTag = succeeded ? TAG_SUCCESS_TRUE : TAG_SUCCESS_FALSE; - var parsedQuery = tasParsedQueryRegistry.get(sql); + ParsedQuery parsedQuery = tasParsedQueryRegistry.get(sql); if (parsedQuery == null) { if (TasUtils.isQueryParsingEnabled(TwContext.current())) { parsedQuery = sqlParseResultsCache.get(sql, sqlForCache -> parseSql(sqlForCache, context)); } else { - var interceptResult = tasQueryParsingInterceptor.intercept(sql); + InterceptResult interceptResult = tasQueryParsingInterceptor.intercept(sql); if (interceptResult.getDecision() == Decision.CUSTOM_PARSED_QUERY) { parsedQuery = interceptResult.getParsedQuery(); } @@ -269,13 +273,13 @@ protected void registerSql(String sql, boolean isInTransaction, boolean succeede return; } - for (var entry : parsedQuery.getOperations().entrySet()) { - final var opName = entry.getKey(); - final var op = entry.getValue(); + for (Entry entry : parsedQuery.getOperations().entrySet()) { + final String opName = entry.getKey(); + final SqlOperation op = entry.getValue(); if (op.getTableNames() != null) { String firstTableName = null; - for (var tableName : op.getTableNames()) { - final var tagsSet = TagsSet.of( + for (String tableName : op.getTableNames()) { + final TagsSet tagsSet = TagsSet.of( dbTag.getKey(), dbTag.getValue(), TwContextMetricsTemplate.TAG_EP_GROUP, context.getGroup(), TwContextMetricsTemplate.TAG_EP_NAME, context.getName(), From 7ffd464dea0f834e81f3196982b71c955196e459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristo=20Kuusk=C3=BCll?= Date: Fri, 26 Jan 2024 15:49:09 +0200 Subject: [PATCH 5/5] Fix. --- .../TableAccessStatisticsSpyqlListener.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 f535429..42379d8 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 @@ -22,6 +22,7 @@ import com.transferwise.common.spyql.listener.SpyqlConnectionListener; import com.transferwise.common.spyql.listener.SpyqlDataSourceListener; import io.micrometer.core.instrument.Gauge; +import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.binder.cache.CaffeineCacheMetrics; import java.time.Duration; @@ -93,7 +94,7 @@ public TableAccessStatisticsSpyqlListener(IMeterCache meterCache, ExecutorServic this.tasQueryParsingInterceptor = tasQueryParsingInterceptor; this.tasQueryParsingListener = tasQueryParsingListener; - final var meterRegistry = meterCache.getMeterRegistry(); + final MeterRegistry meterRegistry = meterCache.getMeterRegistry(); meterRegistry.config().meterFilter(new TasMeterFilter()); sqlParseResultsCache = Caffeine.newBuilder().maximumWeight(entryPointsProperties.getTas().getSqlParser().getCacheSizeMib() * MIB).recordStats() @@ -128,8 +129,8 @@ protected ParsedQuery parseSql(String sql, TwContext context) { return new ParsedQuery(); } - final var result = new ParsedQuery(); - final var startTimeMs = System.currentTimeMillis(); + final ParsedQuery result = new ParsedQuery(); + final long startTimeMs = System.currentTimeMillis(); try { final Statements stmts = sqlParser.parse(sql, entryPointsProperties.getTas().getSqlParser().getTimeout()); @@ -185,7 +186,7 @@ protected ParsedQuery parseSql(String sql, TwContext context) { )).increment(); tasQueryParsingListener.parsingFailed(sql, Duration.of(System.currentTimeMillis() - startTimeMs, ChronoUnit.MILLIS), t); } finally { - var durationMs = System.currentTimeMillis() - startTimeMs; + long durationMs = System.currentTimeMillis() - startTimeMs; if (durationMs > entryPointsProperties.getTas().getSqlParser().getParseDurationWarnThreshold().toMillis()) { meterCache.counter(COUNTER_SLOW_PARSES, TagsSet.of( EntryPointsMetrics.TAG_DATABASE, databaseName, @@ -245,7 +246,7 @@ public void onStatementExecuteFailure(StatementExecuteFailureEvent event) { } protected void registerSql(String sql, boolean isInTransaction, boolean succeeded, long executionTimeNs) { - final var context = TwContext.current(); + final TwContext context = TwContext.current(); final Tag inTransactionTag = isInTransaction ? TAG_IN_TRANSACTION_TRUE : TAG_IN_TRANSACTION_FALSE; final Tag successTag = succeeded ? TAG_SUCCESS_TRUE : TAG_SUCCESS_FALSE;