Skip to content

Commit

Permalink
Include status in txn duration measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
ctring committed Nov 28, 2023
1 parent 9b9ae0b commit 414deaf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/oltpbenchmark/PrometheusMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PrometheusMetrics {
public static final Histogram TXN_DURATION = Histogram.build()
.name("benchbase_txn_duration_seconds")
.help("Transaction duration in seconds")
.labelNames("benchmark", "type")
.labelNames("benchmark", "type", "status")
.buckets(0.000_001, 0.000_010, 0.000_100, // 1 us, 10 us, 100 us
0.001_000, 0.010_000, 0.100_000, // 1 ms, 10 ms, 100 ms
1.0, 10.0, 100.0) // 1 s, 10 s, 100 s
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/oltpbenchmark/api/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public final void run() {

long start = System.nanoTime();

doWork(configuration.getDatabaseType(), transactionType);
TransactionStatus status = doWork(configuration.getDatabaseType(), transactionType);

long end = System.nanoTime();

Expand Down Expand Up @@ -315,7 +315,8 @@ public final void run() {
intervalRequests.incrementAndGet();

PrometheusMetrics.TXN_DURATION.labels(this.benchmark.getBenchmarkName(),
transactionType.getName())
transactionType.getName(),
status.name())
.observe((end - start) / 1_000_000_000.0);
}
if (prePhase.isLatencyRun()) {
Expand Down Expand Up @@ -395,7 +396,8 @@ private TransactionType getTransactionType(SubmittedProcedure pieceOfWork, Phase
* @param databaseType TODO
* @param transactionType TODO
*/
protected final void doWork(DatabaseType databaseType, TransactionType transactionType) {
protected final TransactionStatus doWork(DatabaseType databaseType, TransactionType transactionType) {
TransactionStatus finalStatus = TransactionStatus.UNKNOWN;

try {
int retryCount = 0;
Expand Down Expand Up @@ -494,6 +496,8 @@ protected final void doWork(DatabaseType databaseType, TransactionType transacti

PrometheusMetrics.TXNS.labels(this.benchmark.getBenchmarkName(), transactionType.getName(),
status.name()).inc();

finalStatus = status;
}

}
Expand All @@ -503,7 +507,7 @@ protected final void doWork(DatabaseType databaseType, TransactionType transacti

throw new RuntimeException(msg, ex);
}

return finalStatus;
}

private boolean isRetryable(SQLException ex) {
Expand Down

0 comments on commit 414deaf

Please sign in to comment.