-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Added changes to enable full file cache stats #17538
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,15 @@ | |
import java.io.IOException; | ||
|
||
/** | ||
* Statistics on file cache | ||
* Statistics for the file cache system that tracks memory usage and performance metrics. | ||
* {@link FileCache} internally uses a {@link org.opensearch.index.store.remote.utils.cache.SegmentedCache} | ||
* to manage cached file data in memory segments. | ||
* This class aggregates statistics across all cache segments including: | ||
* - Memory usage (total, active, used) | ||
* - Cache performance (hits, misses, evictions) | ||
* - Utilization percentages | ||
* The statistics are exposed via {@link org.opensearch.action.admin.cluster.node.stats.NodeStats} | ||
* to provide visibility into cache behavior and performance. | ||
* | ||
* @opensearch.api | ||
*/ | ||
|
@@ -33,6 +41,7 @@ | |
private final long evicted; | ||
private final long hits; | ||
private final long misses; | ||
private final FullFileCacheStats fullFileCacheStats; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This approach is not extensible, in case we need to add another BlockedFileCacheStats or PinnedFileCacheStats, we would have to create multiple duplicate classes with the same fields and functionality. Let's create a base class similar to below
Then we can create overallCacheStats, FullFileCacheStats, BlockedFileCacheStats, PinnedFileCacheStats and have our FileCacheStats as below
|
||
|
||
public FileCacheStats( | ||
final long timestamp, | ||
|
@@ -41,7 +50,8 @@ | |
final long used, | ||
final long evicted, | ||
final long hits, | ||
final long misses | ||
final long misses, | ||
final FullFileCacheStats fullFileCacheStats | ||
) { | ||
this.timestamp = timestamp; | ||
this.active = active; | ||
|
@@ -50,6 +60,7 @@ | |
this.evicted = evicted; | ||
this.hits = hits; | ||
this.misses = misses; | ||
this.fullFileCacheStats = fullFileCacheStats; | ||
} | ||
|
||
public FileCacheStats(final StreamInput in) throws IOException { | ||
|
@@ -60,6 +71,7 @@ | |
this.evicted = in.readLong(); | ||
this.hits = in.readLong(); | ||
this.misses = in.readLong(); | ||
this.fullFileCacheStats = new FullFileCacheStats(in); | ||
} | ||
|
||
public static short calculatePercentage(long used, long max) { | ||
|
@@ -75,6 +87,7 @@ | |
out.writeLong(evicted); | ||
out.writeLong(hits); | ||
out.writeLong(misses); | ||
if (fullFileCacheStats != null) fullFileCacheStats.writeTo(out); | ||
} | ||
|
||
public long getTimestamp() { | ||
|
@@ -113,6 +126,10 @@ | |
return misses; | ||
} | ||
|
||
public FullFileCacheStats fullFileCacheStats() { | ||
return fullFileCacheStats; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(Fields.FILE_CACHE); | ||
|
@@ -125,6 +142,9 @@ | |
builder.field(Fields.USED_PERCENT, getUsedPercent()); | ||
builder.field(Fields.HIT_COUNT, getCacheHits()); | ||
builder.field(Fields.MISS_COUNT, getCacheMisses()); | ||
if (fullFileCacheStats != null) { | ||
fullFileCacheStats.toXContent(builder, params); | ||
Check warning on line 146 in server/src/main/java/org/opensearch/index/store/remote/filecache/FileCacheStats.java
|
||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.index.store.remote.filecache; | ||
|
||
import org.opensearch.common.annotation.ExperimentalApi; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.core.xcontent.ToXContentFragment; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.opensearch.index.store.remote.filecache.FileCacheStats.calculatePercentage; | ||
|
||
/** | ||
* Statistics for the file cache system that tracks memory usage and performance metrics. | ||
* Aggregates statistics across all cache segments including: | ||
* - Memory usage: active and used bytes. | ||
* - Cache performance: hit counts and eviction counts. | ||
* - Utilization: active percentage of total used memory. | ||
* The statistics are exposed as part of {@link FileCacheStats} and via {@link org.opensearch.action.admin.cluster.node.stats.NodeStats} | ||
* to provide visibility into cache behavior and performance. | ||
* | ||
* @opensearch.api | ||
*/ | ||
@ExperimentalApi | ||
public class FullFileCacheStats implements Writeable, ToXContentFragment { | ||
|
||
private final long active; | ||
private final long used; | ||
private final long evicted; | ||
private final long hits; | ||
|
||
public FullFileCacheStats(final long active, final long used, final long evicted, final long hits) { | ||
this.active = active; | ||
this.used = used; | ||
this.evicted = evicted; | ||
this.hits = hits; | ||
} | ||
|
||
public FullFileCacheStats(final StreamInput in) throws IOException { | ||
this.active = in.readLong(); | ||
this.used = in.readLong(); | ||
this.evicted = in.readLong(); | ||
this.hits = in.readLong(); | ||
} | ||
|
||
@Override | ||
public void writeTo(final StreamOutput out) throws IOException { | ||
out.writeLong(active); | ||
out.writeLong(used); | ||
out.writeLong(evicted); | ||
out.writeLong(hits); | ||
} | ||
|
||
public long getActive() { | ||
return active; | ||
} | ||
|
||
public long getUsed() { | ||
return used; | ||
} | ||
|
||
public long getEvicted() { | ||
return evicted; | ||
} | ||
|
||
public long getHits() { | ||
return hits; | ||
} | ||
|
||
public short getActivePercent() { | ||
return calculatePercentage(active, used); | ||
} | ||
|
||
static final class Fields { | ||
Check warning on line 83 in server/src/main/java/org/opensearch/index/store/remote/filecache/FullFileCacheStats.java
|
||
static final String FULL_FILE_STATS = "full_file_stats"; | ||
static final String ACTIVE = "active"; | ||
static final String ACTIVE_IN_BYTES = "active_in_bytes"; | ||
static final String USED = "used"; | ||
static final String USED_IN_BYTES = "used_in_bytes"; | ||
static final String EVICTIONS = "evictions"; | ||
static final String EVICTIONS_IN_BYTES = "evictions_in_bytes"; | ||
static final String ACTIVE_PERCENT = "active_percent"; | ||
static final String HIT_COUNT = "hit_count"; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(Fields.FULL_FILE_STATS); | ||
builder.humanReadableField(FullFileCacheStats.Fields.ACTIVE_IN_BYTES, FullFileCacheStats.Fields.ACTIVE, getActive()); | ||
builder.humanReadableField(FullFileCacheStats.Fields.USED_IN_BYTES, FullFileCacheStats.Fields.USED, getUsed()); | ||
builder.humanReadableField(FullFileCacheStats.Fields.EVICTIONS_IN_BYTES, FullFileCacheStats.Fields.EVICTIONS, getEvicted()); | ||
builder.field(FullFileCacheStats.Fields.ACTIVE_PERCENT, getActivePercent()); | ||
builder.field(FullFileCacheStats.Fields.HIT_COUNT, getHits()); | ||
builder.endObject(); | ||
return builder; | ||
Check warning on line 104 in server/src/main/java/org/opensearch/index/store/remote/filecache/FullFileCacheStats.java
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we log the active usage here as well since it was logged previously as well.