@@ -325,6 +325,11 @@ class Module(MgrModule):
325325 type = 'str' ,
326326 default = '' ,
327327 desc = 'pools which the automatic balancing will be limited to' ,
328+ runtime = True ),
329+ Option (name = 'update_pg_upmap_activity' ,
330+ type = 'bool' ,
331+ default = False ,
332+ desc = 'Updates pg_upmap activity stats to be used in `balancer status detail`' ,
328333 runtime = True )
329334 ]
330335
@@ -339,12 +344,10 @@ class Module(MgrModule):
339344 no_optimization_needed = False
340345 success_string = 'Optimization plan created successfully'
341346 in_progress_string = 'in progress'
342- last_pg_upmap : List [Dict [str , Any ]] = []
343347 pg_upmap_items_added : List [Dict [str , Any ]] = []
344348 pg_upmap_items_removed : List [Dict [str , Any ]] = []
345- last_pg_upmap_primaries : List [Dict [str , Any ]] = []
346349 pg_upmap_primaries_added : List [Dict [str , Any ]] = []
347- pg_upmap_activity_initalized = False
350+ pg_upmap_primaries_removed : List [ Dict [ str , Any ]] = []
348351
349352 def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
350353 super (Module , self ).__init__ (* args , ** kwargs )
@@ -371,6 +374,11 @@ def show_status_detail(self) -> Tuple[int, str, str]:
371374 """
372375 Show balancer status (detailed)
373376 """
377+ pg_upmap_activity = cast (bool , self .get_module_option ('update_pg_upmap_activity' ))
378+ if not pg_upmap_activity :
379+ msg = 'This command is disabled.\n ' \
380+ 'To enable, run `ceph config set mgr mgr/balancer/update_pg_upmap_activity True`.\n '
381+ return 0 , msg , ''
374382 s = {
375383 'plans' : list (self .plans .keys ()),
376384 'active' : self .active ,
@@ -665,7 +673,9 @@ def plan_execute(self, plan: str) -> Tuple[int, str, str]:
665673 if not plan_ :
666674 return (- errno .ENOENT , '' , f'plan { plan } not found' )
667675 r , detail = self .execute (plan_ )
668- self .update_pg_upmap_activity () # update pg activity in `balancer status detail`
676+ pg_upmap_activity = cast (bool , self .get_module_option ('update_pg_upmap_activity' ))
677+ if pg_upmap_activity :
678+ self .update_pg_upmap_activity (plan_ ) # update pg activity in `balancer status detail`
669679 self .plan_rm (plan )
670680 return (r , '' , detail )
671681
@@ -757,7 +767,9 @@ def serve(self) -> None:
757767 self .execute (plan )
758768 else :
759769 self .optimize_result = detail
760- self .update_pg_upmap_activity () # update pg activity in `balancer status detail`
770+ pg_upmap_activity = cast (bool , self .get_module_option ('update_pg_upmap_activity' ))
771+ if pg_upmap_activity :
772+ self .update_pg_upmap_activity (plan ) # update pg activity in `balancer status detail`
761773 self .optimizing = False
762774 self .log .debug ('Sleeping for %d' , sleep_interval )
763775 self .event .wait (sleep_interval )
@@ -1582,22 +1594,16 @@ def gather_telemetry(self) -> Dict[str, Any]:
15821594 'mode' : self .mode ,
15831595 }
15841596
1585- def update_pg_upmap_activity (self ) -> None :
1586- osdmap = self .get_osdmap ()
1587- if not self .pg_upmap_activity_initalized :
1588- self .last_pg_upmap = osdmap .dump ().get ('pg_upmap_items' , '' )
1589- self .last_pg_upmap_primaries = osdmap .dump ().get ('pg_upmap_primaries' , '' )
1590- self .pg_upmap_activity_initalized = True
1597+ def update_pg_upmap_activity (self , plan : Plan ) -> None :
1598+ incdump = plan .inc .dump ()
15911599
15921600 # update pg_upmap_items
1593- self .pg_upmap_items_added = [pg for pg in osdmap .dump ().get ('pg_upmap_items' , '' ) if pg not in self .last_pg_upmap ]
1594- self .pg_upmap_items_removed = [pg for pg in self .last_pg_upmap if pg not in osdmap .dump ().get ('pg_upmap_items' , '' )]
1595- self .last_pg_upmap = osdmap .dump ().get ('pg_upmap_items' , '' )
1601+ self .pg_upmap_items_added = incdump .get ('new_pg_upmap_items' , [])
1602+ self .pg_upmap_items_removed = incdump .get ('old_pg_upmap_items' , [])
15961603
15971604 # update pg_upmap_primaries
1598- self .pg_upmap_primaries_added = [pg for pg in osdmap .dump ().get ('pg_upmap_primaries' , '' ) if pg not in self .last_pg_upmap_primaries ]
1599- self .pg_upmap_primaries_removed = [pg for pg in self .last_pg_upmap_primaries if pg not in osdmap .dump ().get ('pg_upmap_primaries' , '' )]
1600- self .last_pg_upmap_primaries = osdmap .dump ().get ('pg_upmap_primaries' , '' )
1605+ self .pg_upmap_primaries_added = incdump .get ('new_pg_upmap_primaries' , [])
1606+ self .pg_upmap_primaries_removed = incdump .get ('old_pg_upmap_primaries' , [])
16011607
16021608 def self_test (self ) -> None :
16031609 # turn balancer on
0 commit comments