From 6578073b269cf96b294cee174535e9f5432d64cf Mon Sep 17 00:00:00 2001 From: CoderJeffrey Date: Thu, 29 Jun 2023 17:36:21 -0700 Subject: [PATCH] Add comments and adjust UTs (Signed-off-by: Jeffrey Liu ujeffliu@amazon.com) Signed-off-by: CoderJeffrey --- .../rca/store/OpenSearchAnalysisGraph.java | 3 +- .../reader/MetricsEmitter.java | 8 ++--- .../SearchBackPressureMetricsProcessor.java | 4 +-- .../SearchBackPressureMetricsSnapShot.java | 35 +++++++++++-------- ...earchBackPressureMetricsProcessorTest.java | 6 ++-- ...SearchBackPressureMetricsSnapShotTest.java | 4 +-- 6 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/opensearch/performanceanalyzer/rca/store/OpenSearchAnalysisGraph.java b/src/main/java/org/opensearch/performanceanalyzer/rca/store/OpenSearchAnalysisGraph.java index e144f2ee1..80763befb 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/rca/store/OpenSearchAnalysisGraph.java +++ b/src/main/java/org/opensearch/performanceanalyzer/rca/store/OpenSearchAnalysisGraph.java @@ -183,7 +183,8 @@ public void construct() { // Use EVALUATION_INTERVAL_SECONDS instead of RCA_PERIOD which resolved to 12 seconds. // This is resulting in this RCA not getting executed in every 5 seconds. Rca> threadMetricsRca = - new ThreadMetricsRca(threadBlockedTime, threadWaitedTime, EVALUATION_INTERVAL_SECONDS); + new ThreadMetricsRca( + threadBlockedTime, threadWaitedTime, EVALUATION_INTERVAL_SECONDS); threadMetricsRca.addTag( RcaConsts.RcaTagConstants.TAG_LOCUS, RcaConsts.RcaTagConstants.LOCUS_DATA_CLUSTER_MANAGER_NODE); diff --git a/src/main/java/org/opensearch/performanceanalyzer/reader/MetricsEmitter.java b/src/main/java/org/opensearch/performanceanalyzer/reader/MetricsEmitter.java index 28d7b6dbe..30d07ce8b 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/reader/MetricsEmitter.java +++ b/src/main/java/org/opensearch/performanceanalyzer/reader/MetricsEmitter.java @@ -756,8 +756,10 @@ public static void emitSearchBackPressureMetrics( Result searchbp_records = searchBackPressureMetricsSnapShot.fetchAll(); // String SEARCHBP_MODE_DIM = "searchbp_mode"; - String SEARCHBP_TYPE_DIM = AllMetrics.SearchBackPressureStatsValue.SEARCHBP_TYPE_DIM.toString(); - String SEARCHBP_TABLE_NAME = AllMetrics.SearchBackPressureStatsValue.SEARCHBP_TABLE_NAME.toString(); + String SEARCHBP_TYPE_DIM = + AllMetrics.SearchBackPressureStatsValue.SEARCHBP_TYPE_DIM.toString(); + String SEARCHBP_TABLE_NAME = + AllMetrics.SearchBackPressureStatsValue.SEARCHBP_TABLE_NAME.toString(); List dims = new ArrayList() { @@ -838,8 +840,6 @@ public static void emitSearchBackPressureMetrics( for (Record record : searchbp_records) { for (String stats_type : stats_types) { Optional tmpStatsObj = Optional.ofNullable(record.get(stats_type)); - // LOG.info(stats_type + " is: " + tmpStatsObj.map(o -> - // Long.parseLong(o.toString())).toString()); handle.bind( stats_type, diff --git a/src/main/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsProcessor.java b/src/main/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsProcessor.java index e3ab8a90a..766ed8bbe 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsProcessor.java +++ b/src/main/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsProcessor.java @@ -56,7 +56,7 @@ static SearchBackPressureMetricsProcessor buildSearchBackPressureMetricsProcesso currentWindowStartTime, searchBackPressureMetricsSnapShot); return new SearchBackPressureMetricsProcessor(searchBackPressureMetricsSnapShot); } - + return new SearchBackPressureMetricsProcessor( searchBackPressureSnapshotNavigableMap.get(currentWindowStartTime)); } @@ -105,7 +105,7 @@ private void parseJsonLine(final String jsonString) { if (map.isEmpty()) { throw new RuntimeException("Missing SearchBackPressure Metrics payload."); } - + // A list of dims to be collected ArrayList required_searchbp_dims = new ArrayList() { diff --git a/src/main/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsSnapShot.java b/src/main/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsSnapShot.java index 0f4246cd9..907ab5540 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsSnapShot.java +++ b/src/main/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsSnapShot.java @@ -28,7 +28,14 @@ public class SearchBackPressureMetricsSnapShot implements Removable { // entry point to interact with SQLite db private final DSLContext create; + /* + * This is a tmp table created to populate searchbp stats + * table name is the search_back_pressure_ + windowStartTime + */ private final String tableName; + + /* columns are the key metrics to be collected (e.g. shar-level search back pressure cancellation count) + */ private List> columns; // Create a table with specifed fields (columns) @@ -47,14 +54,14 @@ public SearchBackPressureMetricsSnapShot(Connection conn, Long windowStartTime) AllMetrics.SearchBackPressureStatsValue .SEARCHBP_SHARD_STATS_CANCELLATIONCOUNT .toString()), - Long.class)); + Integer.class)); this.add( DSL.field( DSL.name( AllMetrics.SearchBackPressureStatsValue .SEARCHBP_TASK_STATS_CANCELLATIONCOUNT .toString()), - Long.class)); + Integer.class)); // Shard Stats Resource Heap / CPU Usage this.add( @@ -63,28 +70,28 @@ public SearchBackPressureMetricsSnapShot(Connection conn, Long windowStartTime) AllMetrics.SearchBackPressureStatsValue .SEARCHBP_SHARD_STATS_RESOURCE_HEAP_USAGE_CANCELLATIONCOUNT .toString()), - Long.class)); + Integer.class)); this.add( DSL.field( DSL.name( AllMetrics.SearchBackPressureStatsValue .SEARCHBP_SHARD_STATS_RESOURCE_HEAP_USAGE_CURRENTMAX .toString()), - Long.class)); + Integer.class)); this.add( DSL.field( DSL.name( AllMetrics.SearchBackPressureStatsValue .SEARCHBP_SHARD_STATS_RESOURCE_HEAP_USAGE_ROLLINGAVG .toString()), - Long.class)); + Integer.class)); this.add( DSL.field( DSL.name( AllMetrics.SearchBackPressureStatsValue .SEARCHBP_SHARD_STATS_RESOURCE_CPU_USAGE_CANCELLATIONCOUNT .toString()), - Long.class)); + Integer.class)); this.add( DSL.field( @@ -92,14 +99,14 @@ public SearchBackPressureMetricsSnapShot(Connection conn, Long windowStartTime) AllMetrics.SearchBackPressureStatsValue .SEARCHBP_SHARD_STATS_RESOURCE_CPU_USAGE_CURRENTMAX .toString()), - Long.class)); + Integer.class)); this.add( DSL.field( DSL.name( AllMetrics.SearchBackPressureStatsValue .SEARCHBP_SHARD_STATS_RESOURCE_CPU_USAGE_CURRENTAVG .toString()), - Long.class)); + Integer.class)); // Task Stats Resource Heap / CPU Usage this.add( @@ -108,28 +115,28 @@ public SearchBackPressureMetricsSnapShot(Connection conn, Long windowStartTime) AllMetrics.SearchBackPressureStatsValue .SEARCHBP_TASK_STATS_RESOURCE_HEAP_USAGE_CANCELLATIONCOUNT .toString()), - Long.class)); + Integer.class)); this.add( DSL.field( DSL.name( AllMetrics.SearchBackPressureStatsValue .SEARCHBP_TASK_STATS_RESOURCE_HEAP_USAGE_CURRENTMAX .toString()), - Long.class)); + Integer.class)); this.add( DSL.field( DSL.name( AllMetrics.SearchBackPressureStatsValue .SEARCHBP_TASK_STATS_RESOURCE_HEAP_USAGE_ROLLINGAVG .toString()), - Long.class)); + Integer.class)); this.add( DSL.field( DSL.name( AllMetrics.SearchBackPressureStatsValue .SEARCHBP_TASK_STATS_RESOURCE_CPU_USAGE_CANCELLATIONCOUNT .toString()), - Long.class)); + Integer.class)); this.add( DSL.field( @@ -137,14 +144,14 @@ public SearchBackPressureMetricsSnapShot(Connection conn, Long windowStartTime) AllMetrics.SearchBackPressureStatsValue .SEARCHBP_TASK_STATS_RESOURCE_CPU_USAGE_CURRENTMAX .toString()), - Long.class)); + Integer.class)); this.add( DSL.field( DSL.name( AllMetrics.SearchBackPressureStatsValue .SEARCHBP_TASK_STATS_RESOURCE_CPU_USAGE_CURRENTAVG .toString()), - Long.class)); + Integer.class)); } }; diff --git a/src/test/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsProcessorTest.java b/src/test/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsProcessorTest.java index 6abbf4a90..2f5fc10ed 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsProcessorTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsProcessorTest.java @@ -93,7 +93,7 @@ public void testSearchBackPressureProcessEvent() throws Exception { // SEARCHBP_SHARD_STATS_RESOURCE_HEAP_USAGE_ROLLINGAVG value is 3L according to the // SERIALIZED_EVENT, should EQUAL Assert.assertEquals( - 3L, + 3, result.get(0) .get( AllMetrics.SearchBackPressureStatsValue @@ -102,7 +102,7 @@ public void testSearchBackPressureProcessEvent() throws Exception { // SEARCHBP_TASK_STATS_RESOURCE_CPU_USAGE_CANCELLATIONCOUNT value is 0L according to the // SERIALIZED_EVENT, should EQUAL Assert.assertEquals( - 0L, + 0, result.get(0) .get( AllMetrics.SearchBackPressureStatsValue @@ -112,7 +112,7 @@ public void testSearchBackPressureProcessEvent() throws Exception { // SEARCHBP_TASK_STATS_RESOURCE_CPU_USAGE_CANCELLATIONCOUNT value is 0L according to the // SERIALIZED_EVENT, should NOT EQUAL Assert.assertNotEquals( - 2L, + 2, result.get(0) .get( AllMetrics.SearchBackPressureStatsValue diff --git a/src/test/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsSnapShotTest.java b/src/test/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsSnapShotTest.java index eeaa1a30f..b2c3626d5 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsSnapShotTest.java +++ b/src/test/java/org/opensearch/performanceanalyzer/reader/SearchBackPressureMetricsSnapShotTest.java @@ -109,7 +109,7 @@ public void testReadSearchBackPressureMetricsSnapshot() throws Exception { assertEquals(1, result.size()); // for 14 (length of required_searchbp_dims) fields, each assign a value from 0 to 13 // test each field and verify the result - for (long i = 0; i < required_searchbp_dims.size(); i++) { + for (int i = 0; i < required_searchbp_dims.size(); i++) { Assert.assertEquals( AllMetrics.SearchBackPressureStatsValue.SEARCHBP_SHARD_STATS_CANCELLATIONCOUNT .toString() @@ -128,7 +128,7 @@ public void tearDown() throws Exception { private void insertIntoTable(BatchBindStep handle) { Object[] bindVals = new Object[required_searchbp_dims.size()]; for (int i = 0; i < required_searchbp_dims.size(); i++) { - bindVals[i] = Long.valueOf(i); + bindVals[i] = Integer.valueOf(i); } handle.bind(bindVals).execute();