Skip to content

Commit

Permalink
Localize metrics in components/raftstore/src/store/metrics.rs (tikv#7287
Browse files Browse the repository at this point in the history
)

* localize some metric

Signed-off-by: Renkai <gaelookair@gmail.com>
  • Loading branch information
Renkai committed Apr 1, 2020
1 parent 496ca5a commit 59bb325
Show file tree
Hide file tree
Showing 12 changed files with 318 additions and 177 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Expand Up @@ -66,7 +66,6 @@ batch-system = { path = "components/batch-system", default-features = false }
bitflags = "1.0.1"
byteorder = "1.2"
chrono = "0.4"
coarsetime = "0.1"
codec = { path = "components/codec" }
configuration = { path = "components/configuration" }
crc32fast = "1.2"
Expand Down
4 changes: 4 additions & 0 deletions components/raftstore/Cargo.toml
Expand Up @@ -76,6 +76,10 @@ tokio-timer = "0.2"
txn_types = { path = "../txn_types"}
uuid = { version = "0.8.1", features = ["serde", "v4"] }

[dependencies.prometheus-static-metric]
git = "https://github.com/tikv/rust-prometheus.git"
rev = "a626d449eaebd5e8ce337f95c1d6dc9800f25df7"

[dependencies.yatp]
git = "https://github.com/tikv/yatp.git"

Expand Down
40 changes: 10 additions & 30 deletions components/raftstore/src/store/fsm/apply.rs
Expand Up @@ -1659,9 +1659,7 @@ impl ApplyDelegate {
|_| { unreachable!() }
);

PEER_ADMIN_CMD_COUNTER_VEC
.with_label_values(&["batch-split", "all"])
.inc();
PEER_ADMIN_CMD_COUNTER.batch_split.all.inc();

let split_reqs = req.get_splits();
let right_derive = split_reqs.get_right_derive();
Expand Down Expand Up @@ -1751,9 +1749,7 @@ impl ApplyDelegate {
});
let mut resp = AdminResponse::default();
resp.mut_splits().set_regions(regions.clone().into());
PEER_ADMIN_CMD_COUNTER_VEC
.with_label_values(&["batch-split", "success"])
.inc();
PEER_ADMIN_CMD_COUNTER.batch_split.success.inc();

Ok((
resp,
Expand All @@ -1768,9 +1764,7 @@ impl ApplyDelegate {
) -> Result<(AdminResponse, ApplyResult)> {
fail_point!("apply_before_prepare_merge");

PEER_ADMIN_CMD_COUNTER_VEC
.with_label_values(&["prepare_merge", "all"])
.inc();
PEER_ADMIN_CMD_COUNTER.prepare_merge.all.inc();

let prepare_merge = req.get_prepare_merge();
let index = prepare_merge.get_min_index();
Expand Down Expand Up @@ -1811,9 +1805,7 @@ impl ApplyDelegate {
)
});
fail_point!("apply_after_prepare_merge");
PEER_ADMIN_CMD_COUNTER_VEC
.with_label_values(&["prepare_merge", "success"])
.inc();
PEER_ADMIN_CMD_COUNTER.prepare_merge.success.inc();

Ok((
AdminResponse::default(),
Expand Down Expand Up @@ -1852,9 +1844,7 @@ impl ApplyDelegate {
apply_before_commit_merge();
}

PEER_ADMIN_CMD_COUNTER_VEC
.with_label_values(&["commit_merge", "all"])
.inc();
PEER_ADMIN_CMD_COUNTER.commit_merge.all.inc();

let merge = req.get_commit_merge();
let source_region = merge.get_source();
Expand Down Expand Up @@ -1959,9 +1949,7 @@ impl ApplyDelegate {
)
});

PEER_ADMIN_CMD_COUNTER_VEC
.with_label_values(&["commit_merge", "success"])
.inc();
PEER_ADMIN_CMD_COUNTER.commit_merge.success.inc();

let resp = AdminResponse::default();
Ok((
Expand All @@ -1978,9 +1966,7 @@ impl ApplyDelegate {
ctx: &mut ApplyContext<W>,
req: &AdminRequest,
) -> Result<(AdminResponse, ApplyResult)> {
PEER_ADMIN_CMD_COUNTER_VEC
.with_label_values(&["rollback_merge", "all"])
.inc();
PEER_ADMIN_CMD_COUNTER.rollback_merge.all.inc();
let region_state_key = keys::region_state_key(self.region_id());
let state: RegionLocalState = match ctx.engine.get_msg_cf(CF_RAFT, &region_state_key) {
Ok(Some(s)) => s,
Expand All @@ -2006,9 +1992,7 @@ impl ApplyDelegate {
)
});

PEER_ADMIN_CMD_COUNTER_VEC
.with_label_values(&["rollback_merge", "success"])
.inc();
PEER_ADMIN_CMD_COUNTER.rollback_merge.success.inc();
let resp = AdminResponse::default();
Ok((
resp,
Expand All @@ -2024,9 +2008,7 @@ impl ApplyDelegate {
ctx: &mut ApplyContext<W>,
req: &AdminRequest,
) -> Result<(AdminResponse, ApplyResult)> {
PEER_ADMIN_CMD_COUNTER_VEC
.with_label_values(&["compact", "all"])
.inc();
PEER_ADMIN_CMD_COUNTER.compact.all.inc();

let compact_index = req.get_compact_log().get_compact_index();
let resp = AdminResponse::default();
Expand Down Expand Up @@ -2070,9 +2052,7 @@ impl ApplyDelegate {
// compact failure is safe to be omitted, no need to assert.
compact_raft_log(&self.tag, apply_state, compact_index, compact_term)?;

PEER_ADMIN_CMD_COUNTER_VEC
.with_label_values(&["compact", "success"])
.inc();
PEER_ADMIN_CMD_COUNTER.compact.success.inc();

Ok((
resp,
Expand Down
12 changes: 3 additions & 9 deletions components/raftstore/src/store/fsm/peer.rs
Expand Up @@ -2903,9 +2903,7 @@ impl<'a, T: Transport, C: PdClient> PeerFsmDelegate<'a, T, C> {
/// Verify and store the hash to state. return true means the hash has been stored successfully.
fn verify_and_store_hash(&mut self, expected_index: u64, expected_hash: Vec<u8>) -> bool {
if expected_index < self.fsm.peer.consistency_state.index {
REGION_HASH_COUNTER_VEC
.with_label_values(&["verify", "miss"])
.inc();
REGION_HASH_COUNTER.verify.miss.inc();
warn!(
"has scheduled a new hash, skip.";
"region_id" => self.fsm.region_id(),
Expand Down Expand Up @@ -2939,9 +2937,7 @@ impl<'a, T: Transport, C: PdClient> PeerFsmDelegate<'a, T, C> {
"peer_id" => self.fsm.peer_id(),
"index" => self.fsm.peer.consistency_state.index
);
REGION_HASH_COUNTER_VEC
.with_label_values(&["verify", "matched"])
.inc();
REGION_HASH_COUNTER.verify.matched.inc();
self.fsm.peer.consistency_state.hash = vec![];
return false;
}
Expand All @@ -2950,9 +2946,7 @@ impl<'a, T: Transport, C: PdClient> PeerFsmDelegate<'a, T, C> {
{
// Maybe computing is too slow or computed result is dropped due to channel full.
// If computing is too slow, miss count will be increased twice.
REGION_HASH_COUNTER_VEC
.with_label_values(&["verify", "miss"])
.inc();
REGION_HASH_COUNTER.verify.miss.inc();
warn!(
"hash belongs to wrong index, skip.";
"region_id" => self.fsm.region_id(),
Expand Down
2 changes: 1 addition & 1 deletion components/raftstore/src/store/fsm/store.rs
Expand Up @@ -401,7 +401,7 @@ impl<'a, T: Transport, C: PdClient> StoreFsmDelegate<'a, T, C> {
}
let elapsed = t.elapsed();
RAFT_EVENT_DURATION
.with_label_values(&[tick.tag()])
.get(tick.tag())
.observe(duration_to_sec(elapsed) as f64);
slow_log!(
elapsed,
Expand Down

0 comments on commit 59bb325

Please sign in to comment.