Skip to content

Commit

Permalink
Make file cache stats consistent with other APIs (#7169)
Browse files Browse the repository at this point in the history
Some cosmetic changes here to make the stat names consistent with
[RequestCacheStats][1] and [QueryCacheStats][2] that already exist in
the API.

I've also removed the 'replaced' and 'removed' stats. These are internal
cache details that I don't think will be useful to a user. We can always
add them back later if needed.

Note this is backward incompatible, but this is okay as this will get in
ahead of the next release which removes the feature flag from searchable
snapshots.

[1]: https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/index/cache/request/RequestCacheStats.java
[2]: https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/index/cache/query/QueryCacheStats.java

Signed-off-by: Andrew Ross <andrross@amazon.com>
(cherry picked from commit 621b27f)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Apr 16, 2023
1 parent 596c376 commit 125c475
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ public FileCacheStats fileCacheStats() {
capacity(),
usage.usage(),
stats.evictionWeight(),
stats.removeWeight(),
stats.replaceCount(),
stats.hitCount(),
stats.missCount()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,25 @@ public class FileCacheStats implements Writeable, ToXContentFragment {
private final long total;
private final long used;
private final long evicted;
private final long removed;
private final long replaced;
private final long hits;
private final long miss;
private final long misses;

public FileCacheStats(
final long timestamp,
final long active,
final long total,
final long used,
final long evicted,
final long removed,
final long replaced,
final long hits,
final long miss
final long misses
) {
this.timestamp = timestamp;
this.active = active;
this.total = total;
this.used = used;
this.evicted = evicted;
this.removed = removed;
this.replaced = replaced;
this.hits = hits;
this.miss = miss;
this.misses = misses;
}

public FileCacheStats(final StreamInput in) throws IOException {
Expand All @@ -62,10 +56,8 @@ public FileCacheStats(final StreamInput in) throws IOException {
this.total = in.readLong();
this.used = in.readLong();
this.evicted = in.readLong();
this.removed = in.readLong();
this.replaced = in.readLong();
this.hits = in.readLong();
this.miss = in.readLong();
this.misses = in.readLong();
}

public static short calculatePercentage(long used, long max) {
Expand All @@ -79,10 +71,8 @@ public void writeTo(final StreamOutput out) throws IOException {
out.writeLong(total);
out.writeLong(used);
out.writeLong(evicted);
out.writeLong(removed);
out.writeLong(replaced);
out.writeLong(hits);
out.writeLong(miss);
out.writeLong(misses);
}

public long getTimestamp() {
Expand Down Expand Up @@ -113,20 +103,12 @@ public ByteSizeValue getEvicted() {
return new ByteSizeValue(evicted);
}

public ByteSizeValue getRemoved() {
return new ByteSizeValue(removed);
}

public long getReplacedCount() {
return replaced;
}

public long getCacheHits() {
return hits;
}

public long getCacheMiss() {
return miss;
public long getCacheMisses() {
return misses;
}

@Override
Expand All @@ -136,13 +118,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.humanReadableField(Fields.ACTIVE_IN_BYTES, Fields.ACTIVE, getActive());
builder.humanReadableField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, getTotal());
builder.humanReadableField(Fields.USED_IN_BYTES, Fields.USED, getUsed());
builder.humanReadableField(Fields.EVICTED_IN_BYTES, Fields.EVICTED, getEvicted());
builder.humanReadableField(Fields.REMOVED_IN_BYTES, Fields.REMOVED, getRemoved());
builder.field(Fields.REPLACED_COUNT, getReplacedCount());
builder.humanReadableField(Fields.EVICTIONS_IN_BYTES, Fields.EVICTIONS, getEvicted());
builder.field(Fields.ACTIVE_PERCENT, getActivePercent());
builder.field(Fields.USED_PERCENT, getUsedPercent());
builder.field(Fields.CACHE_HITS, getCacheHits());
builder.field(Fields.CACHE_MISS, getCacheMiss());
builder.field(Fields.HIT_COUNT, getCacheHits());
builder.field(Fields.MISS_COUNT, getCacheMisses());
builder.endObject();
return builder;
}
Expand All @@ -154,18 +134,15 @@ static final class Fields {
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 EVICTED = "evicted";
static final String EVICTED_IN_BYTES = "evicted_in_bytes";
static final String REMOVED = "removed";
static final String REMOVED_IN_BYTES = "removed_in_bytes";
static final String REPLACED_COUNT = "replaced_count";
static final String EVICTIONS = "evictions";
static final String EVICTIONS_IN_BYTES = "evictions_in_bytes";
static final String TOTAL = "total";
static final String TOTAL_IN_BYTES = "total_in_bytes";

static final String ACTIVE_PERCENT = "active_percent";
static final String USED_PERCENT = "used_percent";

static final String CACHE_HITS = "cache_hits";
static final String CACHE_MISS = "cache_miss";
static final String HIT_COUNT = "hit_count";
static final String MISS_COUNT = "miss_count";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public static FileCacheStats getFileCacheStats(final long fileCacheCapacity, fin
fileCacheCapacity,
usage.usage(),
stats.evictionWeight(),
stats.removeWeight(),
stats.replaceCount(),
stats.hitCount(),
stats.missCount()
);
Expand All @@ -64,10 +62,8 @@ public static void validateFileCacheStats(FileCacheStats original, FileCacheStat
assertEquals(original.getActive(), deserialized.getActive());
assertEquals(original.getActivePercent(), deserialized.getActivePercent());
assertEquals(original.getEvicted(), deserialized.getEvicted());
assertEquals(original.getRemoved(), deserialized.getRemoved());
assertEquals(original.getReplacedCount(), deserialized.getReplacedCount());
assertEquals(original.getCacheHits(), deserialized.getCacheHits());
assertEquals(original.getCacheMiss(), deserialized.getCacheMiss());
assertEquals(original.getCacheMisses(), deserialized.getCacheMisses());
}

public void testFileCacheStatsSerialization() throws IOException {
Expand Down

0 comments on commit 125c475

Please sign in to comment.