Skip to content

Commit

Permalink
Fixed the bug in CacheConfigMetricsCollector (#657)
Browse files Browse the repository at this point in the history
* Fixed the bug in CacheConfigMetricsCollector

Signed-off-by: Atharva Sharma <[email protected]>

* Fixes error logging

Signed-off-by: Gagan Juneja <[email protected]>

---------

Signed-off-by: Atharva Sharma <[email protected]>
Signed-off-by: Gagan Juneja <[email protected]>
Co-authored-by: Gagan Juneja <[email protected]>
  • Loading branch information
atharvasharma61 and Gagan Juneja authored Jun 11, 2024
1 parent 71f8ee9 commit 489f318
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -104,10 +107,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(
Expand All @@ -118,10 +125,15 @@ public void collectMetrics(long startTime) {
SHARD_REQUEST_CACHE.toString(),
requestCacheMaxSize);
} catch (Exception e) {
return new CacheMaxSizeStatus(
SHARD_REQUEST_CACHE.toString(), null);
LOG.error("Error while evaluating requestCacheMaxSize", e);
return null;
}
});

if (shardRequestCacheMaxSizeStatus == null) {
return;
}

value.append(PerformanceAnalyzerMetrics.sMetricNewLineDelimitor)
.append(shardRequestCacheMaxSizeStatus.serialize());
saveMetricValues(value.toString(), startTime);
Expand Down

0 comments on commit 489f318

Please sign in to comment.