Skip to content

Commit

Permalink
Rename and document Stats
Browse files Browse the repository at this point in the history
  • Loading branch information
pnwpedro committed Oct 29, 2024
1 parent e931c32 commit 9e8c0f9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.fauna.client;

public final class Stats {
/**
* A class for representing aggregate query stats. This should be used when collecting query stats
* across multiple requests.
* <p>
* For a single request, use @link com.fauna.response.QueryStats instead.
*/
public final class QueryStatsSummary {
private final long readOps;
private final long computeOps;
private final long writeOps;
Expand All @@ -15,7 +21,7 @@ public final class Stats {
private final int rateLimitedComputeQueryCount;
private final int rateLimitedWriteQueryCount;

public Stats(
public QueryStatsSummary(
long readOps,
long computeOps,
long writeOps,
Expand Down Expand Up @@ -43,17 +49,75 @@ public Stats(
this.rateLimitedWriteQueryCount = rateLimitedWriteQueryCount;
}

/**
* Gets the aggregate read ops.
* @return A long representing the aggregate read ops
*/
public long getReadOps() { return readOps; }

/**
* Gets the aggregate compute ops.
* @return A long representing the aggregate compute ops
*/
public long getComputeOps() { return computeOps; }

/**
* Gets the aggregate write ops.
* @return A long representing the aggregate write ops
*/
public long getWriteOps() { return writeOps; }

/**
* Gets the aggregate query time in milliseconds.
* @return A long representing the aggregate query time in milliseconds.
*/
public long getQueryTimeMs() { return queryTimeMs; }

/**
* Gets the count of retries due to contention.
* @return An int representing the count of retries due to contention.
*/
public int getContentionRetries() { return contentionRetries; }

/**
* Gets the aggregate storage bytes read.
* @return A long representing the aggregate number of storage bytes read.
*/
public long getStorageBytesRead() { return storageBytesRead; }

/**
* Gets the aggregate storage bytes written.
* @return A long representing the aggregate number of storage bytes written.
*/
public long getStorageBytesWrite() { return storageBytesWrite; }

/**
* Gets the aggregate processing time in milliseconds.
* @return A long representing the aggregate processing time in milliseconds.
*/
public long getProcessingTimeMs() { return processingTimeMs; }

/**
* Gets the count of queries summarized on this instance.
* @return An int representing the count of queries summarized.
*/
public int getQueryCount() { return queryCount; }

/**
* Gets the count of rate limited queries due to read limits.
* @return An int representing the count of rate limited queries.
*/
public int getRateLimitedReadQueryCount() { return rateLimitedReadQueryCount; }

/**
* Gets the count of rate limited queries due to compute limits.
* @return An int representing the count of rate limited queries.
*/
public int getRateLimitedComputeQueryCount() { return rateLimitedComputeQueryCount; }

/**
* Gets the count of rate limited queries due to write limits.
* @return An int representing the count of rate limited queries.
*/
public int getRateLimitedWriteQueryCount() { return rateLimitedWriteQueryCount; }
}
4 changes: 2 additions & 2 deletions src/main/java/com/fauna/client/StatsCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public interface StatsCollector {
* Return the collected Stats.
* @return Stats object
*/
Stats read();
QueryStatsSummary read();

/**
* Return the collected Stats and reset counts.
* @return Stats object
*/
Stats readAndReset();
QueryStatsSummary readAndReset();
}
8 changes: 4 additions & 4 deletions src/main/java/com/fauna/client/StatsCollectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public void add(QueryStats stats) {
}

@Override
public Stats read() {
return new Stats(
public QueryStatsSummary read() {
return new QueryStatsSummary(
readOps.get(),
computeOps.get(),
writeOps.get(),
Expand All @@ -73,8 +73,8 @@ public Stats read() {
}

@Override
public Stats readAndReset() {
return new Stats(
public QueryStatsSummary readAndReset() {
return new QueryStatsSummary(
readOps.getAndSet(0),
computeOps.getAndSet(0),
writeOps.getAndSet(0),
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/com/fauna/client/TestStatsCollectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void testAdd_singleQueryStats_updatesCorrectly() {
statsCollector.add(stats);

// Assert
Stats result = statsCollector.read();
QueryStatsSummary result = statsCollector.read();
assertEquals(10, result.getComputeOps());
assertEquals(20, result.getReadOps());
assertEquals(5, result.getWriteOps());
Expand All @@ -62,7 +62,7 @@ public void testAdd_multipleQueryStats_accumulatesValuesCorrectly() {
statsCollector.add(stats2);

// Assert
Stats result = statsCollector.read();
QueryStatsSummary result = statsCollector.read();
assertEquals(25, result.getComputeOps());
assertEquals(45, result.getReadOps());
assertEquals(15, result.getWriteOps());
Expand All @@ -80,7 +80,7 @@ public void testAdd_multipleQueryStats_accumulatesValuesCorrectly() {
@Test
public void testRead_initialStats_returnsZeroStats() {
// Act
Stats result = statsCollector.read();
QueryStatsSummary result = statsCollector.read();

// Assert
assertEquals(0, result.getComputeOps());
Expand All @@ -106,8 +106,8 @@ public void testReadAndReset_returnsAndResetsStats() {
statsCollector.add(stats);

// Act
Stats beforeReset = statsCollector.readAndReset();
Stats afterReset = statsCollector.read();
QueryStatsSummary beforeReset = statsCollector.readAndReset();
QueryStatsSummary afterReset = statsCollector.read();

// Assert the stats before reset
assertEquals(10, beforeReset.getComputeOps());
Expand Down

0 comments on commit 9e8c0f9

Please sign in to comment.