mirror of https://github.com/tikv/client-rust.git
Move stats out of common crate
Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
parent
797257aff4
commit
20384872a8
|
@ -1888,7 +1888,6 @@ dependencies = [
|
|||
"kvproto",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"prometheus",
|
||||
"proptest",
|
||||
"proptest-derive",
|
||||
"regex",
|
||||
|
|
|
@ -82,6 +82,7 @@ mod config;
|
|||
mod pd;
|
||||
pub mod raw;
|
||||
mod request;
|
||||
mod stats;
|
||||
|
||||
#[cfg(test)]
|
||||
mod mock;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
//! A utility module for managing and retrying PD requests.
|
||||
|
||||
use crate::{Error, Region, RegionId, Result, SecurityManager, StoreId};
|
||||
use crate::{stats::pd_stats, Error, Region, RegionId, Result, SecurityManager, StoreId};
|
||||
use async_trait::async_trait;
|
||||
use futures_timer::Delay;
|
||||
use grpcio::Environment;
|
||||
|
@ -15,7 +15,6 @@ use std::{
|
|||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use tikv_client_common::stats::pd_stats;
|
||||
use tikv_client_pd::{Cluster, Connection};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use crate::{
|
||||
backoff::{Backoff, NoBackoff, NoJitterBackoff},
|
||||
pd::PdClient,
|
||||
stats::tikv_stats,
|
||||
transaction::{resolve_locks, HasLocks},
|
||||
BoundRange, Error, ErrorKind, Key, Result,
|
||||
};
|
||||
|
@ -62,7 +63,8 @@ pub trait KvRequest: Request + Clone + Sync + Send + 'static + Sized {
|
|||
let request = self.make_rpc_request(key_data, &store);
|
||||
async move {
|
||||
let request = request?;
|
||||
let response = store.dispatch::<_, Self::RpcResponse>(&request).await?;
|
||||
let response = store.dispatch::<_, Self::RpcResponse>(&request).await;
|
||||
let response = tikv_stats(request.label()).done(response)?;
|
||||
Ok((request, *response))
|
||||
}
|
||||
})
|
||||
|
@ -263,7 +265,6 @@ mod test {
|
|||
use grpcio::CallOption;
|
||||
use kvproto::{kvrpcpb, tikvpb::TikvClient};
|
||||
use std::{any::Any, sync::Mutex};
|
||||
use tikv_client_common::stats::{tikv_stats, RequestStats};
|
||||
|
||||
#[test]
|
||||
fn test_region_retry() {
|
||||
|
@ -295,8 +296,8 @@ mod test {
|
|||
Ok(Box::new(MockRpcResponse {}))
|
||||
}
|
||||
|
||||
fn stats(&self) -> RequestStats {
|
||||
tikv_stats("mock")
|
||||
fn label(&self) -> &'static str {
|
||||
"mock"
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
// Copyright 2018 TiKV Project Authors. Licensed under Apache-2.0.
|
||||
|
||||
use crate::Result;
|
||||
use prometheus::{Histogram, HistogramVec, IntCounterVec};
|
||||
use prometheus::{
|
||||
register_histogram, register_histogram_vec, register_int_counter_vec, Histogram, HistogramVec,
|
||||
IntCounterVec,
|
||||
};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
pub struct RequestStats {
|
||||
|
@ -70,7 +73,7 @@ pub fn observe_tso_batch(batch_size: usize) {
|
|||
PD_TSO_BATCH_SIZE_HISTOGRAM.observe(batch_size as f64);
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
lazy_static::lazy_static! {
|
||||
static ref TIKV_REQUEST_DURATION_HISTOGRAM_VEC: HistogramVec = register_histogram_vec!(
|
||||
"tikv_request_duration_seconds",
|
||||
"Bucketed histogram of TiKV requests duration",
|
|
@ -5,27 +5,21 @@ edition = "2018"
|
|||
|
||||
|
||||
[dependencies]
|
||||
derive-new = "0.5"
|
||||
failure = "0.1"
|
||||
grpcio = { version = "0.6", features = [ "secure", "prost-codec" ], default-features = false }
|
||||
futures = { version = "0.3.5", features = ["compat", "async-await", "thread-pool"] }
|
||||
grpcio = { version = "0.6", features = [ "secure", "prost-codec" ], default-features = false }
|
||||
kvproto = { git = "https://github.com/pingcap/kvproto.git", features = [ "prost-codec" ], default-features = false }
|
||||
lazy_static = "1"
|
||||
log = "0.4"
|
||||
regex = "1"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
log = "0.4"
|
||||
derive-new = "0.5"
|
||||
kvproto = { git = "https://github.com/pingcap/kvproto.git", features = [ "prost-codec" ], default-features = false }
|
||||
|
||||
[dependencies.prometheus]
|
||||
version = "0.8"
|
||||
default-features = false
|
||||
features = ["push", "process"]
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
clap = "2.32"
|
||||
tempdir = "0.3"
|
||||
tokio = { version = "0.2", features = ["rt-threaded", "macros"] }
|
||||
fail = { version = "0.3", features = [ "failpoints" ] }
|
||||
proptest = "0.9"
|
||||
proptest-derive = "0.1.0"
|
||||
fail = { version = "0.3", features = [ "failpoints" ] }
|
||||
tempdir = "0.3"
|
||||
tokio = { version = "0.2", features = ["rt-threaded", "macros"] }
|
||||
|
|
|
@ -2,15 +2,10 @@
|
|||
mod errors;
|
||||
mod kv;
|
||||
pub mod security;
|
||||
pub mod stats;
|
||||
mod timestamp;
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate prometheus;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use crate::errors::{Error, ErrorKind, Result};
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
lazy_static::lazy_static! {
|
||||
static ref SCHEME_REG: Regex = Regex::new(r"^\s*(https?://)").unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -70,9 +70,11 @@ pub struct Store {
|
|||
|
||||
impl Store {
|
||||
pub async fn dispatch<Req: Request, Resp: Any>(&self, request: &Req) -> Result<Box<Resp>> {
|
||||
let result = self.client.dispatch(request).await;
|
||||
let result = result.map(|r| r.downcast().expect("Downcast failed"));
|
||||
|
||||
request.stats().done(result)
|
||||
Ok(self
|
||||
.client
|
||||
.dispatch(request)
|
||||
.await?
|
||||
.downcast()
|
||||
.expect("Downcast failed"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,4 @@ pub use crate::{
|
|||
region::{Region, RegionId, RegionVerId, StoreId},
|
||||
request::Request,
|
||||
};
|
||||
pub use tikv_client_common::{
|
||||
security::SecurityManager, stats::RequestStats, Error, ErrorKind, Key, Result,
|
||||
};
|
||||
pub use tikv_client_common::{security::SecurityManager, Error, ErrorKind, Key, Result};
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.
|
||||
|
||||
use crate::{ErrorKind, RequestStats, Result};
|
||||
use crate::{ErrorKind, Result};
|
||||
use async_trait::async_trait;
|
||||
use grpcio::CallOption;
|
||||
use kvproto::{kvrpcpb, tikvpb::TikvClient};
|
||||
use std::any::Any;
|
||||
use tikv_client_common::stats::tikv_stats;
|
||||
|
||||
#[async_trait]
|
||||
pub trait Request: Any + Sync + Send + 'static {
|
||||
async fn dispatch(&self, client: &TikvClient, options: CallOption) -> Result<Box<dyn Any>>;
|
||||
fn stats(&self) -> RequestStats;
|
||||
fn label(&self) -> &'static str;
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
fn set_context(&mut self, context: kvrpcpb::Context);
|
||||
}
|
||||
|
@ -31,8 +30,8 @@ macro_rules! impl_request {
|
|||
.map_err(|e| ErrorKind::Grpc(e).into())
|
||||
}
|
||||
|
||||
fn stats(&self) -> RequestStats {
|
||||
tikv_stats($label)
|
||||
fn label(&self) -> &'static str {
|
||||
$label
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
|
|
Loading…
Reference in New Issue