From 09f2f8b8c7c25fd974c7061d20a396f38ebb87ea Mon Sep 17 00:00:00 2001 From: Dan Wang Date: Fri, 2 Aug 2024 17:57:00 +0800 Subject: [PATCH] add comments --- src/shell/command_helper.h | 8 ++++++-- src/shell/commands/node_management.cpp | 11 +++++++++-- src/utils/metrics.h | 8 ++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/shell/command_helper.h b/src/shell/command_helper.h index 9cbc1272ab..00c84324ae 100644 --- a/src/shell/command_helper.h +++ b/src/shell/command_helper.h @@ -709,6 +709,8 @@ inline std::vector get_metrics(const std::vector &n return results; } +// Adapt the result returned by `get_metrics` into the structure that could be processed by +// `remote_command`. template inline std::pair process_get_metrics_result(const dsn::http_result &result, const node_desc &node, @@ -745,6 +747,8 @@ inline std::pair process_get_metrics_result(const dsn::http_r } \ } while (0) +// Adapt the result of some parsing operations on the metrics returned by `get_metrics` into the +// structure that could be processed by `remote_command`. template inline std::pair process_parse_metrics_result(const dsn::error_s &result, const node_desc &node, @@ -887,7 +891,7 @@ class aggregate_stats_calcs } \ } while (0) - // Perform the chosen accum aggregations on the fetched metrics. + // Perform the chosen aggregations (both assignment and accum) on the fetched metrics. dsn::error_s aggregate_metrics(const std::string &json_string) { DESERIALIZE_METRIC_QUERY_BRIEF_SNAPSHOT(value, json_string, query_snapshot); @@ -903,7 +907,7 @@ class aggregate_stats_calcs return dsn::error_s::ok(); } - // Perform all of the chosen aggregations (both accum and delta) on the fetched metrics. + // Perform the chosen aggregations (assignement, accum, delta and rate) on the fetched metrics. dsn::error_s aggregate_metrics(const std::string &json_string_start, const std::string &json_string_end) { diff --git a/src/shell/commands/node_management.cpp b/src/shell/commands/node_management.cpp index 280c646b1d..b8b98f2316 100644 --- a/src/shell/commands/node_management.cpp +++ b/src/shell/commands/node_management.cpp @@ -267,6 +267,7 @@ aggregate_meta_server_stats(const node_desc &node, auto command_result = process_parse_metrics_result( calcs.aggregate_metrics(query_snapshot), node, "aggregate meta server stats"); if (!command_result.first) { + // Metrics failed to be aggregated. return command_result; } @@ -276,8 +277,10 @@ aggregate_meta_server_stats(const node_desc &node, struct replica_server_stats { - double virt_mem_mb; - double res_mem_mb; + replica_server_stats() = default; + + double virt_mem_mb{0.0}; + double res_mem_mb{0.0}; DEFINE_JSON_SERIALIZATION(virt_mem_mb, res_mem_mb) }; @@ -299,6 +302,7 @@ aggregate_replica_server_stats(const node_desc &node, node, "aggregate replica server stats"); if (!command_result.first) { + // Metrics failed to be aggregated. return command_result; } @@ -309,6 +313,7 @@ aggregate_replica_server_stats(const node_desc &node, std::vector> get_server_stats(const std::vector &nodes, uint32_t sample_interval_ms) { + // Ask target node (meta or replica server) for the metrics of server stats. const auto &query_string = server_stat_filters().to_query_string(); const auto &results_start = get_metrics(nodes, query_string); std::this_thread::sleep_for(std::chrono::milliseconds(sample_interval_ms)); @@ -330,6 +335,7 @@ std::vector> get_server_stats(const std::vector> get_server_stats(const std::vector inline error_s deserialize_metric_snapshot(const std::string &json_string, TMetricSnapshot &snapshot) @@ -1721,10 +1722,13 @@ inline error_s deserialize_metric_snapshot(const std::string &json_string, } \ } while (0) +// Deserialize the json string into the snapshot specially for metric query which is declared +// internally. #define DESERIALIZE_METRIC_QUERY_BRIEF_SNAPSHOT(field, json_string, query_snapshot) \ dsn::metric_query_brief_##field##_snapshot query_snapshot; \ DESERIALIZE_METRIC_SNAPSHOT(json_string, query_snapshot) +// Deserialize both json string samples into respective snapshots. template inline error_s deserialize_metric_2_samples(const std::string &json_string_start, const std::string &json_string_end, @@ -1736,6 +1740,7 @@ inline error_s deserialize_metric_2_samples(const std::string &json_string_start return error_s::ok(); } +// Deserialize both json string samples into respective snapshots specially for metric queries. template inline error_s deserialize_metric_query_2_samples(const std::string &json_string_start, const std::string &json_string_end, @@ -1759,6 +1764,9 @@ inline error_s deserialize_metric_query_2_samples(const std::string &json_string return error_s::ok(); } +// Deserialize both json string samples into respective snapshots specially for metric queries +// which are declared internally. +// // Currently only Gauge and Counter are considered to have "increase" and "rate", which means // samples are needed. Thus brief `value` field is enough. #define DESERIALIZE_METRIC_QUERY_BRIEF_2_SAMPLES( \