From 29e0b4e08ce3b16cb77cc8a9842b3aa601eb74ba Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Thu, 19 Feb 2026 20:58:39 +0200 Subject: [PATCH] alternator: track per-table latency for batch get/write operations Batch operations were updating only global latency histograms, which left table-level latency metrics incomplete. This change computes request duration once at the end of each operation and reuses it to update both global and per-table latency stats: Latencies are stored per table used, This aligns batch read/write metric behavior with other operations and improves per-table observability. Signed-off-by: Amnon Heiman --- alternator/executor.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/alternator/executor.cc b/alternator/executor.cc index 0a82db6784..8e7325ec98 100644 --- a/alternator/executor.cc +++ b/alternator/executor.cc @@ -3464,7 +3464,11 @@ future executor::batch_write_item(client_state& c if (should_add_wcu) { rjson::add(ret, "ConsumedCapacity", std::move(consumed_capacity)); } - _stats.api_operations.batch_write_item_latency.mark(std::chrono::steady_clock::now() - start_time); + auto duration = std::chrono::steady_clock::now() - start_time; + _stats.api_operations.batch_write_item_latency.mark(duration); + for (const auto& w : per_table_wcu) { + w.first->api_operations.batch_write_item_latency.mark(duration); + } co_return rjson::print(std::move(ret)); } @@ -4975,7 +4979,12 @@ future executor::batch_get_item(client_state& cli if (!some_succeeded && eptr) { co_await coroutine::return_exception_ptr(std::move(eptr)); } - _stats.api_operations.batch_get_item_latency.mark(std::chrono::steady_clock::now() - start_time); + auto duration = std::chrono::steady_clock::now() - start_time; + _stats.api_operations.batch_get_item_latency.mark(duration); + for (const table_requests& rs : requests) { + lw_shared_ptr per_table_stats = get_stats_from_schema(_proxy, *rs.schema); + per_table_stats->api_operations.batch_get_item_latency.mark(duration); + } if (is_big(response)) { co_return make_streamed(std::move(response)); } else {