From 5860387aca1cdf913d9fd505d4d1372a98666a2f Mon Sep 17 00:00:00 2001 From: Atharva Sharma Date: Fri, 31 May 2024 13:30:24 +0530 Subject: [PATCH 1/2] Fixed the bug in CacheConfigMetricsCollector Signed-off-by: Atharva Sharma --- .../collectors/CacheConfigMetricsCollector.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/CacheConfigMetricsCollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/CacheConfigMetricsCollector.java index e2828483..dc14e128 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/CacheConfigMetricsCollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/CacheConfigMetricsCollector.java @@ -104,10 +104,14 @@ public void collectMetrics(long startTime) { indicesService, "indicesRequestCache", true); + Object openSearchOnHeapCache = + FieldUtils.readField(reqCache, "cache", true); Cache requestCache = (Cache) FieldUtils.readField( - reqCache, "cache", true); + openSearchOnHeapCache, + "cache", + true); Long requestCacheMaxSize = (Long) FieldUtils.readField( @@ -118,10 +122,15 @@ public void collectMetrics(long startTime) { SHARD_REQUEST_CACHE.toString(), requestCacheMaxSize); } catch (Exception e) { - return new CacheMaxSizeStatus( - SHARD_REQUEST_CACHE.toString(), null); + e.printStackTrace(); + return null; } }); + + if (shardRequestCacheMaxSizeStatus == null) { + return; + } + value.append(PerformanceAnalyzerMetrics.sMetricNewLineDelimitor) .append(shardRequestCacheMaxSizeStatus.serialize()); saveMetricValues(value.toString(), startTime); From 85e49d7786d905e2dacf90244df92d74832cb953 Mon Sep 17 00:00:00 2001 From: Gagan Juneja Date: Mon, 10 Jun 2024 22:29:22 +0530 Subject: [PATCH 2/2] Fixes error logging Signed-off-by: Gagan Juneja --- .../collectors/CacheConfigMetricsCollector.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/CacheConfigMetricsCollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/CacheConfigMetricsCollector.java index dc14e128..419a251e 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/CacheConfigMetricsCollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/CacheConfigMetricsCollector.java @@ -17,6 +17,8 @@ import java.security.AccessController; import java.security.PrivilegedAction; import org.apache.commons.lang3.reflect.FieldUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.opensearch.common.cache.Cache; import org.opensearch.indices.IndicesService; import org.opensearch.performanceanalyzer.OpenSearchResources; @@ -43,6 +45,7 @@ public class CacheConfigMetricsCollector extends PerformanceAnalyzerMetricsColle implements MetricsProcessor { public static final int SAMPLING_TIME_INTERVAL = MetricsConfiguration.CONFIG_MAP.get(CacheConfigMetricsCollector.class).samplingInterval; + private static final Logger LOG = LogManager.getLogger(CacheConfigMetricsCollector.class); private static final int KEYS_PATH_LENGTH = 0; private StringBuilder value; @@ -122,7 +125,7 @@ public void collectMetrics(long startTime) { SHARD_REQUEST_CACHE.toString(), requestCacheMaxSize); } catch (Exception e) { - e.printStackTrace(); + LOG.error("Error while evaluating requestCacheMaxSize", e); return null; } });