Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: align metrics field names with current behavior #16826

Merged
merged 1 commit into from
Nov 13, 2024
Merged
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 src/meta/binaries/metactl/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ impl App {
let res = client.get_cluster_status().await?;
println!("BinaryVersion: {}", res.binary_version);
println!("DataVersion: {}", res.data_version);
println!("DBSize: {}", res.db_size);
println!("KeyNumber: {}", res.key_num);
println!("RaftLogSize: {}", res.raft_log_size);
println!("SnapshotKeyCount: {}", res.snapshot_key_count);
println!("Node: id={} raft={}", res.id, res.endpoint);
println!("State: {}", res.state);
if let Some(leader) = res.leader {
Expand Down
4 changes: 2 additions & 2 deletions src/meta/service/src/api/grpc/grpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ impl MetaService for MetaServiceImpl {
binary_version: status.binary_version,
data_version: status.data_version.to_string(),
endpoint: status.endpoint,
db_size: status.db_size,
key_num: status.key_num as u64,
raft_log_size: status.raft_log_size,
snapshot_key_count: status.snapshot_key_count as u64,
state: status.state,
is_leader: status.is_leader,
current_term: status.current_term,
Expand Down
19 changes: 10 additions & 9 deletions src/meta/service/src/meta_service/meta_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ impl MetaNode {
server_metrics::set_last_seq(meta_node.get_last_seq().await);

// metrics about server storage
server_metrics::set_db_size(meta_node.get_db_size().await);
server_metrics::set_snapshot_key_num(meta_node.get_key_num().await);
server_metrics::set_raft_log_size(meta_node.get_raft_log_size().await);
server_metrics::set_snapshot_key_count(meta_node.get_snapshot_key_count().await);

last_leader = mm.current_leader;
}
Expand Down Expand Up @@ -817,13 +817,14 @@ impl MetaNode {
nodes
}

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

async fn get_key_num(&self) -> u64 {
async fn get_snapshot_key_count(&self) -> u64 {
self.sto
.try_get_snapshot_key_num()
.try_get_snapshot_key_count()
.await
.unwrap_or_default()
}
Expand All @@ -841,8 +842,8 @@ impl MetaNode {

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

let db_size = self.get_db_size().await;
let key_num = self.get_key_num().await;
let raft_log_size = self.get_raft_log_size().await;
let key_count = self.get_snapshot_key_count().await;

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

Expand All @@ -859,8 +860,8 @@ impl MetaNode {
binary_version: METASRV_COMMIT_VERSION.as_str().to_string(),
data_version: DATA_VERSION,
endpoint: endpoint.to_string(),
db_size,
key_num,
raft_log_size,
snapshot_key_count: key_count,
state: format!("{:?}", metrics.state),
is_leader: metrics.state == openraft::ServerState::Leader,
current_term: metrics.current_term,
Expand Down
8 changes: 4 additions & 4 deletions src/meta/service/src/meta_service/meta_node_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ pub struct MetaNodeStatus {
/// The raft service endpoint for internal communication
pub endpoint: String,

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

/// key number of current snapshot
pub key_num: u64,
/// Total number of keys in current snapshot
pub snapshot_key_count: u64,

/// Server state, one of "Follower", "Learner", "Candidate", "Leader".
pub state: String,
Expand Down
28 changes: 16 additions & 12 deletions src/meta/service/src/metrics/meta_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub mod server_metrics {
node_is_health: Gauge,
leader_changes: Counter,
applying_snapshot: Gauge,
snapshot_key_num: Gauge,
db_size: Gauge,
snapshot_key_count: Gauge,
raft_log_size: Gauge,
last_log_index: Gauge,
last_seq: Gauge,
current_term: Gauge,
Expand All @@ -73,8 +73,8 @@ pub mod server_metrics {
node_is_health: Gauge::default(),
leader_changes: Counter::default(),
applying_snapshot: Gauge::default(),
snapshot_key_num: Gauge::default(),
db_size: Gauge::default(),
snapshot_key_count: Gauge::default(),
raft_log_size: Gauge::default(),
last_log_index: Gauge::default(),
last_seq: Gauge::default(),
current_term: Gauge::default(),
Expand Down Expand Up @@ -109,11 +109,15 @@ pub mod server_metrics {
metrics.applying_snapshot.clone(),
);
registry.register(
key!("snapshot_key_num"),
"snapshot key numbers",
metrics.snapshot_key_num.clone(),
key!("snapshot_key_count"),
"number of keys in the last snapshot",
metrics.snapshot_key_count.clone(),
);
registry.register(
key!("raft_log_size"),
"the size in bytes of the on disk data of raft log",
metrics.raft_log_size.clone(),
);
registry.register(key!("db_size"), "db size", metrics.db_size.clone());
registry.register(
key!("proposals_applied"),
"proposals applied",
Expand Down Expand Up @@ -174,12 +178,12 @@ pub mod server_metrics {
SERVER_METRICS.applying_snapshot.inc_by(cnt);
}

pub fn set_snapshot_key_num(snapshot_key_num: u64) {
SERVER_METRICS.snapshot_key_num.set(snapshot_key_num as i64);
pub fn set_snapshot_key_count(n: u64) {
SERVER_METRICS.snapshot_key_count.set(n as i64);
}

pub fn set_db_size(db_size: u64) {
SERVER_METRICS.db_size.set(db_size as i64);
pub fn set_raft_log_size(raft_log_size: u64) {
SERVER_METRICS.raft_log_size.set(raft_log_size as i64);
}

pub fn set_proposals_applied(proposals_applied: u64) {
Expand Down
2 changes: 1 addition & 1 deletion src/meta/service/src/store/store_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl StoreInner {
/// Return snapshot id and meta of the last snapshot.
///
/// It returns None if there is no snapshot or there is an error parsing snapshot meta or id.
pub(crate) async fn try_get_snapshot_key_num(&self) -> Option<u64> {
pub(crate) async fn try_get_snapshot_key_count(&self) -> Option<u64> {
let sm = self.state_machine.read().await;
let db = sm.levels().persisted()?;
Some(db.stat().key_num)
Expand Down
4 changes: 2 additions & 2 deletions src/meta/types/proto/meta.proto
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ message ClusterStatus {
string binary_version = 2;
string data_version = 3;
string endpoint = 4;
uint64 db_size = 5;
uint64 raft_log_size = 5;
string state = 6;
bool is_leader = 7;
uint64 current_term = 8;
Expand All @@ -180,7 +180,7 @@ message ClusterStatus {
repeated string voters = 15;
repeated string non_voters = 16;
uint64 last_seq = 17;
uint64 key_num = 18;
uint64 snapshot_key_count = 18;
}

message ClientInfo {
Expand Down
Loading