in src/main/java/org/opensearch/performanceanalyzer/collectors/CacheConfigMetricsCollector.java [72:141]
public void collectMetrics(long startTime) {
IndicesService indicesService = OpenSearchResources.INSTANCE.getIndicesService();
if (indicesService == null) {
return;
}
value.setLength(0);
value.append(PerformanceAnalyzerMetrics.getJsonCurrentMilliSeconds());
// This is for backward compatibility. Core OpenSearch may or may not emit maxWeight metric.
// (depending on whether the patch has been applied or not). Thus, we need to use
// reflection to check whether getMaxWeight() method exist in Cache.java
//
// Currently, we are collecting maxWeight metrics only for FieldData and Shard Request
// Cache.
CacheMaxSizeStatus fieldDataCacheMaxSizeStatus =
AccessController.doPrivileged(
(PrivilegedAction<CacheMaxSizeStatus>)
() -> {
try {
Cache fieldDataCache =
indicesService
.getIndicesFieldDataCache()
.getCache();
long fieldDataMaxSize =
(Long)
FieldUtils.readField(
fieldDataCache,
CACHE_MAX_WEIGHT,
true);
return new CacheMaxSizeStatus(
FIELD_DATA_CACHE.toString(), fieldDataMaxSize);
} catch (Exception e) {
return new CacheMaxSizeStatus(
FIELD_DATA_CACHE.toString(), null);
}
});
value.append(PerformanceAnalyzerMetrics.sMetricNewLineDelimitor)
.append(fieldDataCacheMaxSizeStatus.serialize());
CacheMaxSizeStatus shardRequestCacheMaxSizeStatus =
AccessController.doPrivileged(
(PrivilegedAction<CacheMaxSizeStatus>)
() -> {
try {
Object reqCache =
FieldUtils.readField(
indicesService,
"indicesRequestCache",
true);
Cache requestCache =
(Cache)
FieldUtils.readField(
reqCache, "cache", true);
Long requestCacheMaxSize =
(Long)
FieldUtils.readField(
requestCache,
CACHE_MAX_WEIGHT,
true);
return new CacheMaxSizeStatus(
SHARD_REQUEST_CACHE.toString(),
requestCacheMaxSize);
} catch (Exception e) {
return new CacheMaxSizeStatus(
SHARD_REQUEST_CACHE.toString(), null);
}
});
value.append(PerformanceAnalyzerMetrics.sMetricNewLineDelimitor)
.append(shardRequestCacheMaxSizeStatus.serialize());
saveMetricValues(value.toString(), startTime);
}