@@ -52,9 +52,44 @@ static ostream& _prefix(std::ostream *_dout, Monitor &mon) {
5252MgrStatMonitor::MgrStatMonitor (Monitor &mn, Paxos &p, const string& service_name)
5353 : PaxosService(mn, p, service_name)
5454{
55+ g_conf ().add_observer (this );
5556}
5657
57- MgrStatMonitor::~MgrStatMonitor () = default ;
58+ MgrStatMonitor::~MgrStatMonitor ()
59+ {
60+ g_conf ().remove_observer (this );
61+ }
62+
63+ std::vector<std::string> MgrStatMonitor::get_tracked_keys () const noexcept
64+ {
65+ return {
66+ " enable_availability_tracking" ,
67+ };
68+ }
69+
70+ void MgrStatMonitor::handle_conf_change (
71+ const ConfigProxy& conf,
72+ const std::set<std::string>& changed)
73+ {
74+ if (changed.count (" enable_availability_tracking" )) {
75+ std::scoped_lock l (lock);
76+ bool oldval = enable_availability_tracking;
77+ bool newval = g_conf ().get_val <bool >(" enable_availability_tracking" );
78+ dout (10 ) << __func__ << " enable_availability_tracking config option is changed from "
79+ << oldval << " to " << newval
80+ << dendl;
81+
82+ // if fetaure is toggled from off to on,
83+ // store the new value of last_uptime and last_downtime
84+ // (to be updated in calc_pool_availability)
85+ if (newval > oldval) {
86+ reset_availability_last_uptime_downtime_val = ceph_clock_now ();
87+ dout (10 ) << __func__ << " reset_availability_last_uptime_downtime_val "
88+ << reset_availability_last_uptime_downtime_val << dendl;
89+ }
90+ enable_availability_tracking = newval;
91+ }
92+ }
5893
5994void MgrStatMonitor::create_initial ()
6095{
@@ -69,6 +104,29 @@ void MgrStatMonitor::create_initial()
69104void MgrStatMonitor::calc_pool_availability ()
70105{
71106 dout (20 ) << __func__ << dendl;
107+ std::scoped_lock l (lock);
108+
109+ // if feature is disabled by user, do not update the uptime
110+ // and downtime, exit early
111+ if (!enable_availability_tracking) {
112+ dout (20 ) << __func__ << " tracking availability score is disabled" << dendl;
113+ return ;
114+ }
115+
116+ // if reset_availability_last_uptime_downtime_val is not utime_t(1, 2),
117+ // update last_uptime and last_downtime for all pools to the
118+ // recorded values
119+ if (reset_availability_last_uptime_downtime_val.has_value ()) {
120+ for (const auto & i : pool_availability) {
121+ const auto & poolid = i.first ;
122+ pool_availability[poolid].last_downtime = reset_availability_last_uptime_downtime_val.value ();
123+ pool_availability[poolid].last_uptime = reset_availability_last_uptime_downtime_val.value ();
124+ }
125+ dout (20 ) << __func__ << " reset last_uptime and last_downtime to "
126+ << reset_availability_last_uptime_downtime_val << dendl;
127+ reset_availability_last_uptime_downtime_val.reset ();
128+ }
129+
72130 auto pool_avail_end = pool_availability.end ();
73131 for (const auto & i : digest.pool_pg_unavailable_map ) {
74132 const auto & poolid = i.first ;
0 commit comments