meta_srv/handler/
extract_stat_handler.rs1use api::v1::meta::{HeartbeatRequest, Role};
16use common_meta::datanode::Stat;
17use common_telemetry::{info, warn};
18
19use crate::error::Result;
20use crate::handler::{HandleControl, HeartbeatAccumulator, HeartbeatHandler};
21use crate::metasrv::Context;
22use crate::metrics::{METRIC_META_HEARTBEAT_RATE, METRIC_META_HEARTBEAT_STAT_MEMORY_SIZE};
23
24pub struct ExtractStatHandler;
25
26#[async_trait::async_trait]
27impl HeartbeatHandler for ExtractStatHandler {
28 fn is_acceptable(&self, role: Role) -> bool {
29 role == Role::Datanode
30 }
31
32 async fn handle(
33 &self,
34 req: &HeartbeatRequest,
35 _ctx: &mut Context,
36 acc: &mut HeartbeatAccumulator,
37 ) -> Result<HandleControl> {
38 if req.mailbox_message.is_some() {
39 return Ok(HandleControl::Continue);
42 }
43
44 match Stat::try_from(req) {
45 Ok(stat) => {
46 METRIC_META_HEARTBEAT_RATE.inc();
47 METRIC_META_HEARTBEAT_STAT_MEMORY_SIZE.observe(stat.memory_size() as f64);
48 let _ = acc.stat.insert(stat);
49 }
50 Err(Some(header)) => {
51 info!("New handshake request: {:?}", header);
52 }
53 Err(_) => {
54 warn!("Incomplete heartbeat data: {:?}", req);
55 }
56 };
57
58 Ok(HandleControl::Continue)
59 }
60}