Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
empiredan authored and wangdan committed Aug 19, 2024
1 parent 5fbacbd commit 09f2f8b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/shell/command_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ inline std::vector<dsn::http_result> get_metrics(const std::vector<node_desc> &n
return results;
}

// Adapt the result returned by `get_metrics` into the structure that could be processed by
// `remote_command`.
template <typename... Args>
inline std::pair<bool, std::string> process_get_metrics_result(const dsn::http_result &result,
const node_desc &node,
Expand Down Expand Up @@ -745,6 +747,8 @@ inline std::pair<bool, std::string> 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 <typename... Args>
inline std::pair<bool, std::string> process_parse_metrics_result(const dsn::error_s &result,
const node_desc &node,
Expand Down Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down
11 changes: 9 additions & 2 deletions src/shell/commands/node_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)
};
Expand All @@ -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;
}

Expand All @@ -309,6 +313,7 @@ aggregate_replica_server_stats(const node_desc &node,
std::vector<std::pair<bool, std::string>> get_server_stats(const std::vector<node_desc> &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));
Expand All @@ -330,6 +335,7 @@ std::vector<std::pair<bool, std::string>> get_server_stats(const std::vector<nod
SKIP_IF_PROCESS_RESULT_FALSE() \
}

// Skip the metrics that failed to be fetched.
PROCESS_GET_METRICS_RESULT(results_start[i], "starting server stats")
PROCESS_GET_METRICS_RESULT(results_end[i], "ending server stats")

Expand All @@ -338,6 +344,7 @@ std::vector<std::pair<bool, std::string>> get_server_stats(const std::vector<nod
dsn::metric_query_brief_value_snapshot query_snapshot_start;
dsn::metric_query_brief_value_snapshot query_snapshot_end;
{
// Skip the metrics that failed to be deserialized.
auto command_result = process_parse_metrics_result(
deserialize_metric_query_2_samples(results_start[i].body(),
results_end[i].body(),
Expand Down
8 changes: 8 additions & 0 deletions src/utils/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,7 @@ DEF_ALL_METRIC_BRIEF_SNAPSHOTS(value);

DEF_ALL_METRIC_BRIEF_SNAPSHOTS(p99);

// Deserialize the json string into the snapshot.
template <typename TMetricSnapshot>
inline error_s deserialize_metric_snapshot(const std::string &json_string,
TMetricSnapshot &snapshot)
Expand All @@ -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 <typename TMetricSnapshot>
inline error_s deserialize_metric_2_samples(const std::string &json_string_start,
const std::string &json_string_end,
Expand All @@ -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 <typename TMetricQuerySnapshot>
inline error_s deserialize_metric_query_2_samples(const std::string &json_string_start,
const std::string &json_string_end,
Expand All @@ -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( \
Expand Down

0 comments on commit 09f2f8b

Please sign in to comment.