okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
64a91dcdc
main
1"""Wide monitor pages preserve readable telemetry and redacted request data.""" 2 3import io 4import time 5import unittest 6 7try : 8from rich .console import Console 9from strata_cli .dashboard import MonitorHistory 10from strata_cli .detail_dashboard import render_detail_dashboard 11except ImportError : 12Console = None 13 14 15def snapshot (): 16now = time .time () 17slots = [{"slot" :i ,"group" :i // 2 ,"state" :"decoding" if i < 3 else "idle" , 18"request_id" :f"req- { i } " if i < 3 else None , 19"held_tokens" :1500 + 100 * i if i < 3 else 0 , 20"tok_s" :12.0 + i if i < 3 else None }for i in range (4 )] 21return { 22"sampled_at" :now ,"source" :"test" ,"instance" : {"id" :"test" ,"state" :"ready" }, 23"model" : {"id" :"test-model" ,"loaded" :True ,"context" :8192 }, 24"work" : {"active" :3 ,"occupied_slots" :3 ,"slots_effective" :4 , 25"slots_requested" :4 ,"groups" :2 ,"queued" :1 ,"waiting" :0 , 26"max_queue" :8 ,"admission_limit" :12 ,"admission_reserved" :4 , 27"batch_sample_age_s" :0.2 ,"effective_rows_window" :3.0 , 28"batch_active_rows_window" :3.0 ,"slots" :slots , 29"requests" : [{"id" :f"req- { i } " ,"state" :"decoding" ,"slot" :i , 30"group" :i // 2 ,"prompt_tokens" :400 , 31"generated" :60 + i ,"queued_at" :now - 2 , 32"admitted_at" :now - 1.5 , 33"first_engine_token_s" :0.8 , 34"prompt_body" :"SECRET_PROMPT" }for i in range (3 )]+ 35 [{"id" :"wait-0" ,"state" :"queued" ,"slot" :None , 36"prompt_tokens" :500 ,"queued_at" :now - 1 }]}, 37"rates" : {"aggregate_output_tok_s" :41.0 ,"answer_tok_s" :13.5 , 38"prefill_tok_s" :120.0 }, 39"topology" : {"mode" :"layer split" ,"resolved" :True , 40"selected_devices" : [0 ,1 ], 41"stages" : [{"stage" :i ,"device_index" :i , 42"layer_start" :10 * i ,"layer_end" :10 * i + 9 } 43for i in range (2 )]}, 44"devices" : [{"index" :i ,"name" :f"GPU- { i } " ,"util" :70 + i , 45"mem_used" : (10 + i )* 2 ** 30 ,"mem_total" :24 * 2 ** 30 , 46"temp" :60 + i ,"power" :180 + i }for i in range (2 )], 47"ram" : {"used" :20 * 2 ** 30 ,"total" :64 * 2 ** 30 }, 48"recent" : [{"id" :"done-0" ,"finish" :"stop" ,"prompt_tokens" :100 , 49"reused" :20 ,"output_tokens" :40 ,"duration_s" :3.2 , 50"first_engine_token_s" :0.7 }], 51"activity" : {"available" :True ,"last_seq" :2 , 52"events" : [{"seq" :1 ,"at" :now - 2 ,"request_id" :"req-0" , 53"event" :"queued" }, 54 {"seq" :2 ,"at" :now - 1 ,"request_id" :"req-0" , 55"event" :"admitted" }]}, 56 } 57 58 59@ unittest . skipIf ( Console is None , "optional Rich dependency absent" ) 60class VisualDetailTests (unittest .TestCase ): 61def render (self ,sample ,view ,width = 140 ,height = 44 ,** options ): 62output = io .StringIO () 63history = MonitorHistory () 64history .add (sample , ("id" ,"test" )) 65Console (file = output ,width = width - 2 ,color_system = None ).render_detail_dashboard (sample ,view ,width = width - 2 , 67height = height - 2 ,history = history , 68color = False ,** options )) 69return output .getvalue () 70 71def test_all_five_pages_fit_wide_terminals_and_keep_request_text_private (self ): 72sample = snapshot () 73for width ,height in ((140 ,44 ), (128 ,36 )): 74for view in ("serving" ,"requests" ,"engine" ,"hardware" ,"logs" ): 75with self .subTest (width = width ,view = view ): 76shown = self .render (sample ,view ,width ,height ) 77self .assertIn (f"STRATA / { view . upper () } " ,shown ) 78self .assertNotIn ("SECRET_PROMPT" ,shown ) 79self .assertLessEqual (len (shown .splitlines ()),height - 2 ) 80self .assertTrue (all (len (line )<= width - 2 for line in shown .splitlines ())) 81self .assertIn ("ROWS/WINDOW" ,self .render (sample ,"serving" )) 82self .assertIn ("GPU 0" ,self .render (sample ,"hardware" )) 83self .assertIn ("HOST SPAN" ,self .render (sample ,"engine" )) 84self .assertIn ("req-0" ,self .render (sample ,"logs" )) 85 86def test_selection_detail_and_stale_readings (self ): 87sample = snapshot () 88summary = self .render (sample ,"requests" ,selected = 0 ) 89expanded = self .render (sample ,"requests" ,selected = 0 ,detail = True ) 90self .assertIn ("Enter expands" ,summary ) 91self .assertIn ("First engine token" ,expanded ) 92self .assertNotIn ("First engine token" ,summary ) 93stale = self .render (sample ,"serving" ,connection_state = "stale" ) 94self .assertIn ("STALE" ,stale ) 95self .assertNotIn ("41.0 tok/s" ,stale ) 96stale_hardware = self .render (sample ,"hardware" ,connection_state = "stale" ) 97self .assertNotIn ("70%" ,stale_hardware ) 98self .assertIn ("--/--G" ,stale_hardware ) 99 100def test_replica_batch_windows_remain_separate (self ): 101sample = snapshot () 102sample ["topology" ]["mode" ]= "replicas (configured)" 103sample ["work" ]["effective_rows_window" ]= None 104sample ["work" ]["replica_batches" ]= [ 105 {"replica" :0 ,"effective_rows_window" :2.0 , 106"batch_active_rows_window" :1.5 ,"batch_sample_age_s" :0.2 }, 107 {"replica" :1 ,"effective_rows_window" :3.0 , 108"batch_active_rows_window" :2.0 ,"batch_sample_age_s" :0.3 }, 109 ] 110shown = self .render (sample ,"serving" ) 111self .assertIn ("R0 ROWS/WIN" ,shown ) 112self .assertIn ("R1 ROWS/WIN" ,shown ) 113self .assertIn ("Replica sample windows are independent" ,shown ) 114 115 116if __name__ == "__main__" : 117unittest .main ()