Skip to content

Commit 9af8ba3

Browse files
authored
refactor: align metrics field names with current behavior (#16826)
- Rename `db_size` to `raft_log_size`, which is the size of on-disk data of raft-log. - Rename `key_num` to `snapshot_key_count`. This commit updates field names in - the the metrics API, - and the cluster status gRPC API.
1 parent 7abfa96 commit 9af8ba3

File tree

7 files changed

+37
-32
lines changed

7 files changed

+37
-32
lines changed

src/meta/binaries/metactl/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ impl App {
236236
let res = client.get_cluster_status().await?;
237237
println!("BinaryVersion: {}", res.binary_version);
238238
println!("DataVersion: {}", res.data_version);
239-
println!("DBSize: {}", res.db_size);
240-
println!("KeyNumber: {}", res.key_num);
239+
println!("RaftLogSize: {}", res.raft_log_size);
240+
println!("SnapshotKeyCount: {}", res.snapshot_key_count);
241241
println!("Node: id={} raft={}", res.id, res.endpoint);
242242
println!("State: {}", res.state);
243243
if let Some(leader) = res.leader {

src/meta/service/src/api/grpc/grpc_service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ impl MetaService for MetaServiceImpl {
462462
binary_version: status.binary_version,
463463
data_version: status.data_version.to_string(),
464464
endpoint: status.endpoint,
465-
db_size: status.db_size,
466-
key_num: status.key_num as u64,
465+
raft_log_size: status.raft_log_size,
466+
snapshot_key_count: status.snapshot_key_count as u64,
467467
state: status.state,
468468
is_leader: status.is_leader,
469469
current_term: status.current_term,

src/meta/service/src/meta_service/meta_node.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ impl MetaNode {
447447
server_metrics::set_last_seq(meta_node.get_last_seq().await);
448448

449449
// metrics about server storage
450-
server_metrics::set_db_size(meta_node.get_db_size().await);
451-
server_metrics::set_snapshot_key_num(meta_node.get_key_num().await);
450+
server_metrics::set_raft_log_size(meta_node.get_raft_log_size().await);
451+
server_metrics::set_snapshot_key_count(meta_node.get_snapshot_key_count().await);
452452

453453
last_leader = mm.current_leader;
454454
}
@@ -817,13 +817,14 @@ impl MetaNode {
817817
nodes
818818
}
819819

820-
async fn get_db_size(&self) -> u64 {
820+
/// Get the size in bytes of the on disk files of the raft log storage.
821+
async fn get_raft_log_size(&self) -> u64 {
821822
self.sto.log.read().await.on_disk_size()
822823
}
823824

824-
async fn get_key_num(&self) -> u64 {
825+
async fn get_snapshot_key_count(&self) -> u64 {
825826
self.sto
826-
.try_get_snapshot_key_num()
827+
.try_get_snapshot_key_count()
827828
.await
828829
.unwrap_or_default()
829830
}
@@ -841,8 +842,8 @@ impl MetaNode {
841842

842843
let endpoint = self.sto.get_node_raft_endpoint(&self.sto.id).await?;
843844

844-
let db_size = self.get_db_size().await;
845-
let key_num = self.get_key_num().await;
845+
let raft_log_size = self.get_raft_log_size().await;
846+
let key_count = self.get_snapshot_key_count().await;
846847

847848
let metrics = self.raft.metrics().borrow().clone();
848849

@@ -859,8 +860,8 @@ impl MetaNode {
859860
binary_version: METASRV_COMMIT_VERSION.as_str().to_string(),
860861
data_version: DATA_VERSION,
861862
endpoint: endpoint.to_string(),
862-
db_size,
863-
key_num,
863+
raft_log_size,
864+
snapshot_key_count: key_count,
864865
state: format!("{:?}", metrics.state),
865866
is_leader: metrics.state == openraft::ServerState::Leader,
866867
current_term: metrics.current_term,

src/meta/service/src/meta_service/meta_node_status.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ pub struct MetaNodeStatus {
3232
/// The raft service endpoint for internal communication
3333
pub endpoint: String,
3434

35-
/// The size in bytes of the on disk data.
36-
pub db_size: u64,
35+
/// The size in bytes of the raft-log on disk data.
36+
pub raft_log_size: u64,
3737

38-
/// key number of current snapshot
39-
pub key_num: u64,
38+
/// Total number of keys in current snapshot
39+
pub snapshot_key_count: u64,
4040

4141
/// Server state, one of "Follower", "Learner", "Candidate", "Leader".
4242
pub state: String,

src/meta/service/src/metrics/meta_metrics.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub mod server_metrics {
5252
node_is_health: Gauge,
5353
leader_changes: Counter,
5454
applying_snapshot: Gauge,
55-
snapshot_key_num: Gauge,
56-
db_size: Gauge,
55+
snapshot_key_count: Gauge,
56+
raft_log_size: Gauge,
5757
last_log_index: Gauge,
5858
last_seq: Gauge,
5959
current_term: Gauge,
@@ -73,8 +73,8 @@ pub mod server_metrics {
7373
node_is_health: Gauge::default(),
7474
leader_changes: Counter::default(),
7575
applying_snapshot: Gauge::default(),
76-
snapshot_key_num: Gauge::default(),
77-
db_size: Gauge::default(),
76+
snapshot_key_count: Gauge::default(),
77+
raft_log_size: Gauge::default(),
7878
last_log_index: Gauge::default(),
7979
last_seq: Gauge::default(),
8080
current_term: Gauge::default(),
@@ -109,11 +109,15 @@ pub mod server_metrics {
109109
metrics.applying_snapshot.clone(),
110110
);
111111
registry.register(
112-
key!("snapshot_key_num"),
113-
"snapshot key numbers",
114-
metrics.snapshot_key_num.clone(),
112+
key!("snapshot_key_count"),
113+
"number of keys in the last snapshot",
114+
metrics.snapshot_key_count.clone(),
115+
);
116+
registry.register(
117+
key!("raft_log_size"),
118+
"the size in bytes of the on disk data of raft log",
119+
metrics.raft_log_size.clone(),
115120
);
116-
registry.register(key!("db_size"), "db size", metrics.db_size.clone());
117121
registry.register(
118122
key!("proposals_applied"),
119123
"proposals applied",
@@ -174,12 +178,12 @@ pub mod server_metrics {
174178
SERVER_METRICS.applying_snapshot.inc_by(cnt);
175179
}
176180

177-
pub fn set_snapshot_key_num(snapshot_key_num: u64) {
178-
SERVER_METRICS.snapshot_key_num.set(snapshot_key_num as i64);
181+
pub fn set_snapshot_key_count(n: u64) {
182+
SERVER_METRICS.snapshot_key_count.set(n as i64);
179183
}
180184

181-
pub fn set_db_size(db_size: u64) {
182-
SERVER_METRICS.db_size.set(db_size as i64);
185+
pub fn set_raft_log_size(raft_log_size: u64) {
186+
SERVER_METRICS.raft_log_size.set(raft_log_size as i64);
183187
}
184188

185189
pub fn set_proposals_applied(proposals_applied: u64) {

src/meta/service/src/store/store_inner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl StoreInner {
292292
/// Return snapshot id and meta of the last snapshot.
293293
///
294294
/// It returns None if there is no snapshot or there is an error parsing snapshot meta or id.
295-
pub(crate) async fn try_get_snapshot_key_num(&self) -> Option<u64> {
295+
pub(crate) async fn try_get_snapshot_key_count(&self) -> Option<u64> {
296296
let sm = self.state_machine.read().await;
297297
let db = sm.levels().persisted()?;
298298
Some(db.stat().key_num)

src/meta/types/proto/meta.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ message ClusterStatus {
167167
string binary_version = 2;
168168
string data_version = 3;
169169
string endpoint = 4;
170-
uint64 db_size = 5;
170+
uint64 raft_log_size = 5;
171171
string state = 6;
172172
bool is_leader = 7;
173173
uint64 current_term = 8;
@@ -180,7 +180,7 @@ message ClusterStatus {
180180
repeated string voters = 15;
181181
repeated string non_voters = 16;
182182
uint64 last_seq = 17;
183-
uint64 key_num = 18;
183+
uint64 snapshot_key_count = 18;
184184
}
185185

186186
message ClientInfo {

0 commit comments

Comments
 (0)