Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2021"

[features]
default = ["prometheus"]
prometheus = ["prometheus/push", "prometheus/process"]
prometheus = ["dep:prometheus", "prometheus/push", "prometheus/process"]
# Enable integration tests with a running TiKV and PD instance.
# Use $PD_ADDRS, comma separated, to set the addresses the tests use.
integration-tests = []
Expand All @@ -34,7 +34,7 @@ futures = { version = "0.3" }
lazy_static = "1"
log = "0.4"
pin-project = "1"
prometheus = { version = "0.13", default-features = false }
prometheus = { version = "0.13", default-features = false, optional = true }
prost = "0.12"
rand = "0.8"
regex = "1"
Expand Down
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"))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks a little too invasive to me.

How about like this:

Define another DummyRequestStats with no member and empty methods. Then change pd_stats and tikv_stats to return coresponding object accroding to the feature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll get to it this evening.

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