From d29ac819d9f6b5aef34fe3f6e2df863d3a47b4c1 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 09:55:48 -0700 Subject: [PATCH] Update Jooq version and address bind variable failure in AdmissionControl Emitter (#493) (#494) Signed-off-by: Khushboo Rajput (cherry picked from commit 30ca0b302c3be7b36703b326772ea31cf065fded) Co-authored-by: Khushboo Rajput <59671881+khushbr@users.noreply.github.com> --- build.gradle | 10 ++++++++-- .../rca/persistence/SQLitePersistor.java | 6 ++---- .../performanceanalyzer/reader/MetricsEmitter.java | 1 - .../reader/MetricsEmitterTests.java | 7 +++++++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index a73b20156..6b1cd79ad 100644 --- a/build.gradle +++ b/build.gradle @@ -338,10 +338,16 @@ dependencies { def guavaVersion = "${versions.guava}" def jakartaVersion = "${versions.jakarta_annotation}" - implementation 'org.jooq:jooq:3.10.8' + // Sqlite and JOOQ version are coupled, see https://www.jooq.org/download/support-matrix + // In case they fall out of compatibility, JOOQ will throw error message: + // 'No bind variables have been provided with a single statement batch execution. This may be due to accidental API misuse> + def jooqVersion = "3.16.20" + def sqliteVersion = "3.41.2.2" + + implementation "org.jooq:jooq:${jooqVersion}" implementation 'org.bouncycastle:bcprov-jdk15to18:1.74' implementation 'org.bouncycastle:bcpkix-jdk15to18:1.74' - implementation 'org.xerial:sqlite-jdbc:3.41.2.2' + implementation "org.xerial:sqlite-jdbc:${sqliteVersion}" implementation "com.google.guava:guava:${guavaVersion}" implementation 'com.google.code.gson:gson:2.9.0' implementation 'org.checkerframework:checker-qual:3.29.0' diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/persistence/SQLitePersistor.java b/src/main/java/org/opensearch/performanceanalyzer/rca/persistence/SQLitePersistor.java index f3bcdd845..88990de89 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/persistence/SQLitePersistor.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/persistence/SQLitePersistor.java @@ -126,9 +126,7 @@ private static class ColumnValuePair { // It is needed during SQLite file rotation @Override synchronized void createNewDSLContext() { - if (create != null) { - create.close(); - } + // No need to close DSL Context in Jooq 3.16+, see https://github.com/jOOQ/jOOQ/issues/10512 create = DSL.using(super.conn, SQLDialect.SQLITE); jooqTableColumns = new HashMap<>(); tableNameToJavaClassMap = new HashMap<>(); @@ -413,7 +411,7 @@ List readAllForMaxField(Class clz, String fieldName, Class fieldClz) // This gives the type of the setter parameter. Class setterType = setter.getParameterTypes()[0]; - int nestedRowId = jooqField.cast(Integer.class).getValue(record); + int nestedRowId = record.getValue(jooqField, Integer.class); // Now that we have the Type of the parameter and the rowID specifying the data // the object diff --git a/src/main/java/org/opensearch/performanceanalyzer/reader/MetricsEmitter.java b/src/main/java/org/opensearch/performanceanalyzer/reader/MetricsEmitter.java index d209bf7f1..5a225a0ba 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/reader/MetricsEmitter.java +++ b/src/main/java/org/opensearch/performanceanalyzer/reader/MetricsEmitter.java @@ -784,7 +784,6 @@ public static void emitAdmissionControlMetrics( if (controllerObj.isPresent() && rejectionCountObj.isPresent()) { handle.bind( controllerObj.orElseGet(Object::new).toString(), - rejectionCountObj.map(o -> Long.parseLong(o.toString())).orElse(0L), // the rest are agg fields: sum, avg, min, max rejectionCountObj.map(o -> Long.parseLong(o.toString())).orElse(0L), rejectionCountObj.map(o -> Long.parseLong(o.toString())).orElse(0L), diff --git a/src/test/java/org/opensearch/performanceanalyzer/reader/MetricsEmitterTests.java b/src/test/java/org/opensearch/performanceanalyzer/reader/MetricsEmitterTests.java index 6b657a549..f66feea35 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/reader/MetricsEmitterTests.java +++ b/src/test/java/org/opensearch/performanceanalyzer/reader/MetricsEmitterTests.java @@ -25,7 +25,9 @@ import org.jooq.SQLDialect; import org.jooq.impl.DSL; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import org.opensearch.performanceanalyzer.PerformanceAnalyzerApp; import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics; import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics; import org.opensearch.performanceanalyzer.config.TroubleshootingConfig; @@ -44,6 +46,11 @@ public MetricsEmitterTests() throws SQLException, ClassNotFoundException { private static final String DB_URL = "jdbc:sqlite:"; + @Before + public void setup() { + PerformanceAnalyzerApp.initAggregators(); + } + @Test public void testMetricsEmitter() throws Exception { //