@@ -41,10 +41,21 @@ async fn heartbeat(
4141 }
4242
4343 app_state. store_context . heartbeat_store . beat ( & heartbeat) ;
44- app_state
45- . store_context
46- . metrics_store
47- . store_metrics ( heartbeat. metrics . clone ( ) , node_address) ;
44+ if let Some ( metrics) = heartbeat. metrics . clone ( ) {
45+ app_state
46+ . store_context
47+ . metrics_store
48+ . store_metrics ( Some ( metrics. clone ( ) ) , node_address) ;
49+
50+ for metric in metrics {
51+ app_state. metrics . record_compute_task_gauge (
52+ & node_address. to_string ( ) ,
53+ & metric. key . task_id ,
54+ & metric. key . label ,
55+ metric. value ,
56+ ) ;
57+ }
58+ }
4859
4960 let current_task = app_state. scheduler . get_task_for_node ( node_address) ;
5061 match current_task {
@@ -73,10 +84,13 @@ pub fn heartbeat_routes() -> Scope {
7384mod tests {
7485 use super :: * ;
7586 use crate :: api:: tests:: helper:: create_test_app_state;
87+
7688 use actix_web:: http:: StatusCode ;
7789 use actix_web:: test;
7890 use actix_web:: App ;
7991 use serde_json:: json;
92+ use shared:: models:: metric:: MetricEntry ;
93+ use shared:: models:: metric:: MetricKey ;
8094 use shared:: models:: task:: TaskRequest ;
8195
8296 #[ actix_web:: test]
@@ -90,7 +104,10 @@ mod tests {
90104 . await ;
91105
92106 let address = "0x0000000000000000000000000000000000000000" . to_string ( ) ;
93- let req_payload = json ! ( { "address" : address} ) ;
107+ let req_payload = json ! ( { "address" : address, "metrics" : [
108+ { "key" : { "task_id" : "long-task-1234" , "label" : "performance/batch_avg_seq_length" } , "value" : 1.0 } ,
109+ { "key" : { "task_id" : "long-task-1234" , "label" : "performance/batch_min_seq_length" } , "value" : 5.0 }
110+ ] } ) ;
94111
95112 let req = test:: TestRequest :: post ( )
96113 . uri ( "/heartbeat" )
@@ -116,12 +133,31 @@ mod tests {
116133 address: "0x0000000000000000000000000000000000000000" . to_string( ) ,
117134 task_id: None ,
118135 task_state: None ,
119- metrics: None ,
136+ metrics: Some ( vec![
137+ MetricEntry {
138+ key: MetricKey {
139+ task_id: "long-task-1234" . to_string( ) ,
140+ label: "performance/batch_avg_seq_length" . to_string( ) ,
141+ } ,
142+ value: 1.0 ,
143+ } ,
144+ MetricEntry {
145+ key: MetricKey {
146+ task_id: "long-task-1234" . to_string( ) ,
147+ label: "performance/batch_min_seq_length" . to_string( ) ,
148+ } ,
149+ value: 5.0 ,
150+ }
151+ ] ) ,
120152 version: None ,
121153 timestamp: None ,
122154 p2p_id: None ,
123155 } )
124156 ) ;
157+
158+ let metrics = app_state. metrics . export_metrics ( ) . unwrap ( ) ;
159+ assert ! ( metrics. contains( "performance/batch_avg_seq_length" ) ) ;
160+ assert ! ( metrics. contains( "performance/batch_min_seq_length" ) ) ;
125161 }
126162
127163 #[ actix_web:: test]
0 commit comments