Skip to content

Commit

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

Signed-off-by: Atharva Sharma <atharvasharma61@gmail.com>

* Fixes error logging

Signed-off-by: Gagan Juneja <gjjuneja@amazon.com>

---------

Signed-off-by: Atharva Sharma <atharvasharma61@gmail.com>
Signed-off-by: Gagan Juneja <gjjuneja@amazon.com>
Co-authored-by: Gagan Juneja <gjjuneja@amazon.com>
(cherry picked from commit 489f318)

Co-authored-by: Atharva Sharma <60044988+atharvasharma61@users.noreply.github.com>
  • Loading branch information
1 parent 93014de commit df8947e
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 df8947e

Please sign in to comment.