@@ -2230,17 +2230,8 @@ Metrics ServerFamily::GetMetrics(Namespace* ns) const {
2230
2230
return result;
2231
2231
}
2232
2232
2233
- void ServerFamily::Info (CmdArgList args, const CommandContext& cmd_cntx) {
2234
- if (args.size () > 1 ) {
2235
- return cmd_cntx.rb ->SendError (kSyntaxErr );
2236
- }
2237
-
2238
- string section;
2239
-
2240
- if (args.size () == 1 ) {
2241
- section = absl::AsciiStrToUpper (ArgS (args, 0 ));
2242
- }
2243
-
2233
+ string ServerFamily::FormatInfoMetrics (const Metrics& m, std::string_view section,
2234
+ bool priveleged) const {
2244
2235
string info;
2245
2236
2246
2237
auto should_enter = [&](string_view name, bool hidden = false ) {
@@ -2256,13 +2247,13 @@ void ServerFamily::Info(CmdArgList args, const CommandContext& cmd_cntx) {
2256
2247
absl::StrAppend (&info, a1, " :" , a2, " \r\n " );
2257
2248
};
2258
2249
2259
- ServerState* ss = ServerState::tlocal ();
2260
-
2261
- bool show_managed_info =
2262
- !absl::GetFlag (FLAGS_managed_service_info) || cmd_cntx.conn_cntx ->conn ()->IsPrivileged ();
2250
+ bool show_managed_info = priveleged || !absl::GetFlag (FLAGS_managed_service_info);
2263
2251
2264
2252
if (should_enter (" SERVER" )) {
2265
- auto kind = ProactorBase::me ()->GetKind ();
2253
+ ProactorBase* proactor = ProactorBase::me ();
2254
+
2255
+ // proactor might be null in tests.
2256
+ auto kind = proactor ? ProactorBase::me ()->GetKind () : ProactorBase::EPOLL;
2266
2257
const char * multiplex_api = (kind == ProactorBase::IOURING) ? " iouring" : " epoll" ;
2267
2258
2268
2259
append (" redis_version" , kRedisVersion );
@@ -2282,12 +2273,6 @@ void ServerFamily::Info(CmdArgList args, const CommandContext& cmd_cntx) {
2282
2273
append (" uptime_in_days" , uptime / (3600 * 24 ));
2283
2274
}
2284
2275
2285
- Metrics m;
2286
- // Save time by not calculating metrics if we don't need them.
2287
- if (!(section == " SERVER" || section == " REPLICATION" )) {
2288
- m = GetMetrics (cmd_cntx.conn_cntx ->ns );
2289
- }
2290
-
2291
2276
DbStats total;
2292
2277
for (const auto & db_stats : m.db_stats )
2293
2278
total += db_stats;
@@ -2486,7 +2471,10 @@ void ServerFamily::Info(CmdArgList args, const CommandContext& cmd_cntx) {
2486
2471
append (" last_saved_file" , save_info.file_name );
2487
2472
append (" last_success_save_duration_sec" , save_info.success_duration_sec );
2488
2473
2489
- unsigned is_loading = (ss->gstate () == GlobalState::LOADING);
2474
+ ServerState* ss = ServerState::tlocal ();
2475
+
2476
+ // ss can be null in tests.
2477
+ unsigned is_loading = ss && (ss->gstate () == GlobalState::LOADING);
2490
2478
append (" loading" , is_loading);
2491
2479
append (" saving" , is_saving);
2492
2480
append (" current_save_duration_sec" , curent_durration_sec);
@@ -2653,6 +2641,30 @@ void ServerFamily::Info(CmdArgList args, const CommandContext& cmd_cntx) {
2653
2641
append (" cluster_enabled" , IsClusterEnabledOrEmulated ());
2654
2642
append (" migration_errors_total" , service_.cluster_family ().MigrationsErrorsCount ());
2655
2643
}
2644
+
2645
+ return info;
2646
+ }
2647
+
2648
+ void ServerFamily::Info (CmdArgList args, const CommandContext& cmd_cntx) {
2649
+ if (args.size () > 1 ) {
2650
+ return cmd_cntx.rb ->SendError (kSyntaxErr );
2651
+ }
2652
+
2653
+ string section;
2654
+
2655
+ if (args.size () == 1 ) {
2656
+ section = absl::AsciiStrToUpper (ArgS (args, 0 ));
2657
+ }
2658
+
2659
+ Metrics metrics;
2660
+
2661
+ // Save time by not calculating metrics if we don't need them.
2662
+ if (!(section == " SERVER" || section == " REPLICATION" )) {
2663
+ metrics = GetMetrics (cmd_cntx.conn_cntx ->ns );
2664
+ }
2665
+
2666
+ string info = FormatInfoMetrics (metrics, section, cmd_cntx.conn_cntx ->conn ()->IsPrivileged ());
2667
+
2656
2668
auto * rb = static_cast <RedisReplyBuilder*>(cmd_cntx.rb );
2657
2669
rb->SendVerbatimString (info);
2658
2670
}
0 commit comments