Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the bug in CacheConfigMetricsCollector #657

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide more insight as to why do we need to modify this?

Copy link
Contributor Author

@atharvasharma61 atharvasharma61 Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current logic returns a CacheMaxSizeStatus with null cacheMaxSize if exception is raised, while we require it to be non-null.

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
Loading