@@ -187,6 +187,16 @@ impl Metrics {
187187 . set ( 1 ) ;
188188 }
189189
190+ pub fn move_node_host_current ( & self , chain : & str , old_host : & str , new_host : & str ) {
191+ self . node_host_current
192+ . get_or_create ( & HostCurrentStateLabels {
193+ chain : chain. to_string ( ) ,
194+ host : old_host. to_string ( ) ,
195+ } )
196+ . set ( 0 ) ;
197+ self . set_node_host_current ( chain, new_host) ;
198+ }
199+
190200 pub fn add_cache_hit ( & self , chain : & str , path : & str ) {
191201 let path = self . truncate_path ( path) ;
192202 self . cache_hits . get_or_create ( & CacheLabels { chain : chain. to_string ( ) , path } ) . inc ( ) ;
@@ -301,4 +311,16 @@ mod tests {
301311 assert ! ( encoded. contains( "host=\" api.trongrid.io\" " ) ) ;
302312 assert ! ( encoded. contains( "reason=\" status=429\" " ) ) ;
303313 }
314+
315+ #[ test]
316+ fn moves_current_node_host ( ) {
317+ let metrics = create_test_metrics ( ) ;
318+
319+ metrics. set_node_host_current ( "thorchain" , "thornode.ninerealms.com" ) ;
320+ metrics. move_node_host_current ( "thorchain" , "thornode.ninerealms.com" , "gateway.liquify.com" ) ;
321+
322+ let encoded = metrics. get_metrics ( ) ;
323+ assert ! ( encoded. contains( "test_node_host_current{chain=\" thorchain\" ,host=\" thornode.ninerealms.com\" } 0" ) ) ;
324+ assert ! ( encoded. contains( "test_node_host_current{chain=\" thorchain\" ,host=\" gateway.liquify.com\" } 1" ) ) ;
325+ }
304326}
0 commit comments