Skip to content

Commit

Permalink
fix: prometheus feature flag fixup
Browse files Browse the repository at this point in the history
Signed-off-by: John Lewis <[email protected]>
  • Loading branch information
johnbchron committed Dec 1, 2024
1 parent 2d75f2d commit 13aafc6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ mod pd;
mod proto;
mod region;
mod region_cache;
#[cfg(feature = "prometheus")]
mod stats;
mod store;
mod timestamp;
Expand Down
8 changes: 8 additions & 0 deletions src/pd/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::proto::pdpb::{self};
use crate::region::RegionId;
use crate::region::RegionWithLeader;
use crate::region::StoreId;
#[cfg(feature = "prometheus")]
use crate::stats::pd_stats;
use crate::Error;
use crate::Result;
Expand Down Expand Up @@ -75,15 +76,22 @@ impl<Cl> RetryClient<Cl> {

macro_rules! retry_core {
($self: ident, $tag: literal, $call: expr) => {{
#[cfg(feature = "prometheus")]
let stats = pd_stats($tag);
let mut last_err = Ok(());
for _ in 0..LEADER_CHANGE_RETRY {
let res = $call;

#[cfg(feature = "prometheus")]
match stats.done(res) {
Ok(r) => return Ok(r),
Err(e) => last_err = Err(e),
}
#[cfg(not(feature = "prometheus"))]
match res {
Ok(r) => return Ok(r),
Err(e) => last_err = Err(e),
}

let mut reconnect_count = MAX_REQUEST_COUNT;
while let Err(e) = $self.reconnect(RECONNECT_INTERVAL_SEC).await {
Expand Down
3 changes: 3 additions & 0 deletions src/request/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::request::shard::HasNextBatch;
use crate::request::NextBatch;
use crate::request::Shardable;
use crate::request::{KvRequest, StoreRequest};
#[cfg(feature = "prometheus")]
use crate::stats::tikv_stats;
use crate::store::HasRegionError;
use crate::store::HasRegionErrors;
Expand Down Expand Up @@ -60,13 +61,15 @@ impl<Req: KvRequest> Plan for Dispatch<Req> {
type Result = Req::Response;

async fn execute(&self) -> Result<Self::Result> {
#[cfg(feature = "prometheus")]
let stats = tikv_stats(self.request.label());
let result = self
.kv_client
.as_ref()
.expect("Unreachable: kv_client has not been initialised in Dispatch")
.dispatch(&self.request)
.await;
#[cfg(feature = "prometheus")]
let result = stats.done(result);
result.map(|r| {
*r.downcast()
Expand Down

0 comments on commit 13aafc6

Please sign in to comment.