From 414deafe2251bcde49903087038334b907abd172 Mon Sep 17 00:00:00 2001 From: Cuong Nguyen Date: Mon, 27 Nov 2023 19:19:12 -0500 Subject: [PATCH] Include status in txn duration measurement --- .../java/com/oltpbenchmark/PrometheusMetrics.java | 2 +- src/main/java/com/oltpbenchmark/api/Worker.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/oltpbenchmark/PrometheusMetrics.java b/src/main/java/com/oltpbenchmark/PrometheusMetrics.java index 6a7d5093a..cd97f0759 100644 --- a/src/main/java/com/oltpbenchmark/PrometheusMetrics.java +++ b/src/main/java/com/oltpbenchmark/PrometheusMetrics.java @@ -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 diff --git a/src/main/java/com/oltpbenchmark/api/Worker.java b/src/main/java/com/oltpbenchmark/api/Worker.java index 27bebf0cc..908414bbc 100644 --- a/src/main/java/com/oltpbenchmark/api/Worker.java +++ b/src/main/java/com/oltpbenchmark/api/Worker.java @@ -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(); @@ -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()) { @@ -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; @@ -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; } } @@ -503,7 +507,7 @@ protected final void doWork(DatabaseType databaseType, TransactionType transacti throw new RuntimeException(msg, ex); } - + return finalStatus; } private boolean isRetryable(SQLException ex) {