Skip to content

Commit 4be1cfb

Browse files
committed
Support per shard redis proxy latency per command metrics
1 parent 73b6b34 commit 4be1cfb

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

source/extensions/filters/network/redis_proxy/conn_pool_impl.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,11 @@ InstanceImpl::PendingRequest::PendingRequest(InstanceImpl::ThreadLocalPool& pare
597597
if (shard_scope_ && parent_.config_->enableCommandStats()) {
598598
command_ = parent_.redis_command_stats_->getCommandFromRequest(getRequest(incoming_request_));
599599
parent_.redis_command_stats_->updateStatsTotal(*shard_scope_, command_);
600+
// Create per-shard per-command latency timer when both command stats and per-shard latency are enabled
601+
if (parent_.config_->enablePerShardLatencyStats()) {
602+
command_latency_timer_ = parent_.redis_command_stats_->createCommandTimer(
603+
*shard_scope_, command_, parent_.dispatcher_.timeSource());
604+
}
600605
}
601606
}
602607

@@ -639,6 +644,8 @@ void InstanceImpl::PendingRequest::onResponse(Common::Redis::RespValuePtr&& resp
639644
end_time - start_time_).count();
640645
latency_histogram_->recordValue(latency_us);
641646
}
647+
// Complete per-shard per-command latency timer (auto-records on destruction)
648+
command_latency_timer_.reset();
642649
pool_callbacks_.onResponse(std::move(response));
643650
parent_.onRequestCompleted();
644651
}
@@ -661,6 +668,8 @@ void InstanceImpl::PendingRequest::onFailure() {
661668
end_time - start_time_).count();
662669
latency_histogram_->recordValue(latency_us);
663670
}
671+
// Complete per-shard per-command latency timer (auto-records on destruction)
672+
command_latency_timer_.reset();
664673
pool_callbacks_.onFailure();
665674
parent_.refresh_manager_->onFailure(parent_.cluster_name_);
666675
parent_.onRequestCompleted();

source/extensions/filters/network/redis_proxy/conn_pool_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "envoy/common/time.h"
1111
#include "envoy/extensions/filters/network/redis_proxy/v3/redis_proxy.pb.h"
1212
#include "envoy/stats/stats_macros.h"
13+
#include "envoy/stats/timespan.h"
1314
#include "envoy/thread_local/thread_local.h"
1415
#include "envoy/upstream/cluster_manager.h"
1516

@@ -182,6 +183,7 @@ class InstanceImpl : public Instance, public std::enable_shared_from_this<Instan
182183
Stats::StatName command_; // Command name for per-shard command stats
183184
Stats::Histogram* latency_histogram_{nullptr}; // Per-shard latency histogram
184185
MonotonicTime start_time_; // Request start time for latency tracking
186+
Stats::TimespanPtr command_latency_timer_; // Per-shard per-command latency timer
185187
};
186188

187189
struct ThreadLocalPool : public ThreadLocal::ThreadLocalObject,

0 commit comments

Comments
 (0)