diff --git a/protocol/src/kv/mod.rs b/protocol/src/kv/mod.rs index d375b9f7..37f0486b 100644 --- a/protocol/src/kv/mod.rs +++ b/protocol/src/kv/mod.rs @@ -25,11 +25,11 @@ use super::Flag; use super::Protocol; use crate::kv::client::Client; use crate::kv::error::Error; -use crate::Command; use crate::HandShake; use crate::HashedCommand; use crate::RequestProcessor; use crate::Stream; +use crate::{Command, Operation}; use ds::RingSlice; use sharding::hash::Hash; @@ -251,10 +251,13 @@ impl Protocol for Kv { None } - // kv目前也不统计error,因为kv走mc binary协议,error基本都是get miss这种,不需要统计 + // kv走mc binary协议,get miss属于error不统计,只统计上行请求 #[inline] - fn metric_err(&self) -> bool { - false + fn metric_err(&self, req_op: Operation) -> bool { + match req_op { + Operation::Store => true, + _ => false, + } } } diff --git a/protocol/src/memcache/binary/mod.rs b/protocol/src/memcache/binary/mod.rs index d838db5e..8186f904 100644 --- a/protocol/src/memcache/binary/mod.rs +++ b/protocol/src/memcache/binary/mod.rs @@ -10,8 +10,8 @@ pub use packet::Binary; pub struct MemcacheBinary; use crate::{ - Command, Commander, Error, Flag, HashedCommand, Metric, MetricItem, Protocol, RequestProcessor, - Result, Stream, Writer, + Command, Commander, Error, Flag, HashedCommand, Metric, MetricItem, Operation, Protocol, + RequestProcessor, Result, Stream, Writer, }; use sharding::hash::Hash; @@ -193,7 +193,7 @@ impl Protocol for MemcacheBinary { // mc目前不需要统计error,因为mc的error基本都是get miss,del not-found这种,这种错误不需要统计 #[inline] - fn metric_err(&self) -> bool { + fn metric_err(&self, _req_op: Operation) -> bool { false } } diff --git a/protocol/src/parser.rs b/protocol/src/parser.rs index 681f60c1..14e92589 100644 --- a/protocol/src/parser.rs +++ b/protocol/src/parser.rs @@ -129,7 +129,7 @@ pub trait Proto: Unpin + Clone + Send + Sync + 'static { 1_u8 } - fn metric_err(&self) -> bool { + fn metric_err(&self, _req_op: Operation) -> bool { true } } diff --git a/stream/src/handler.rs b/stream/src/handler.rs index 270c2d1b..26c0808d 100644 --- a/stream/src/handler.rs +++ b/stream/src/handler.rs @@ -147,7 +147,7 @@ where self.num.rx(); // 统计请求耗时、异常响应 self.rtt += start.elapsed(); - if self.parser.metric_err() && !cmd.ok() { + if self.parser.metric_err(req.operation()) && !cmd.ok() { self.err += 1; } diff --git a/stream/src/pipeline.rs b/stream/src/pipeline.rs index ee56ae19..9598d1ae 100644 --- a/stream/src/pipeline.rs +++ b/stream/src/pipeline.rs @@ -179,7 +179,7 @@ where } // 不区分是否last,这样更精确的感知总的异常响应数量 - if self.parser.metric_err() && !rsp_ok { + if self.parser.metric_err(op) && !rsp_ok { *self.metrics.err() += 1; } }