Skip to content

Commit

Permalink
Fixed reset impl for multi dim stats
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Alfonsi <[email protected]>
  • Loading branch information
Peter Alfonsi committed Mar 1, 2024
1 parent 2aeaa53 commit 60df761
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public void reset() {
response.memorySize.dec(response.getMemorySize());
response.entries.dec(response.getEntries());
}
totalStats.memorySize.dec(totalStats.getMemorySize());
totalStats.entries.dec(totalStats.getEntries());
}

private CacheStatsResponse internalGetStats(List<CacheStatsDimension> dimensions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.opensearch.common.Randomness;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.metrics.CounterMetric;
import org.opensearch.common.recycler.Recycler;
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.core.common.io.stream.BytesStreamInput;
import org.opensearch.test.OpenSearchTestCase;
Expand Down Expand Up @@ -189,6 +190,20 @@ public void testReset() throws Exception {
assertEquals(originalResponse.getMemorySize(), stats.getMemorySizeByDimensions(dims));
assertEquals(originalResponse.getEntries(), stats.getEntriesByDimensions(dims));
}

CacheStatsResponse expectedTotal = new CacheStatsResponse();
for (Set<CacheStatsDimension> dimSet : expected.keySet()) {
expectedTotal.add(expected.get(dimSet));
}
expectedTotal.memorySize = new CounterMetric();
expectedTotal.entries = new CounterMetric();
assertEquals(expectedTotal, stats.getTotalStats());

assertEquals(expectedTotal.getHits(), stats.getTotalHits());
assertEquals(expectedTotal.getMisses(), stats.getTotalMisses());
assertEquals(expectedTotal.getEvictions(), stats.getTotalEvictions());
assertEquals(expectedTotal.getMemorySize(), stats.getTotalMemorySize());
assertEquals(expectedTotal.getEntries(), stats.getTotalEntries());
}

private Map<String, List<String>> getUsedDimensionValues(MultiDimensionCacheStats stats, int numValuesPerDim) {
Expand Down

0 comments on commit 60df761

Please sign in to comment.