Skip to content

Commit 4295a34

Browse files
committed
add comments
1 parent d2187d3 commit 4295a34

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/shell/commands/node_management.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ struct replica_server_stats
307307
{
308308
replica_server_stats() = default;
309309

310+
// `DEFINE_JSON_SERIALIZATION` is not used to encode the member variables of
311+
// `replica_server_stats` into JSON because the number of its member variables
312+
// is very large and far exceeds the parameter limit of this macro. Increasing
313+
// the macro's parameter limit would make the code overly verbose.
310314
std::string to_json_string() const
311315
{
312316
nlohmann::json rpc;

src/utils/metrics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ void metrics_http_service::get_metrics_handler(const http_request &req, http_res
390390
filters.with_metric_fields = kBriefMetricFields;
391391
}
392392

393+
// If the client specifies `as_value=true` in the HTTP request, it is necessary to
394+
// check whether metrics in `with_metric_fields` that contain multiple values (such
395+
// as percentiles) only need to return a single value to the client. If so, the
396+
// server-side `as_value` should be set to true, so that the returned field name
397+
// in the response is "value".
393398
if (as_value) {
394399
int kth_count{0};
395400
for (const auto &kth : kAllKthPercentiles) {

src/utils/metrics.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,17 @@ struct metric_filters
537537

538538
entity_metrics_type entity_metrics;
539539

540+
// When the `as_value` field is used to construct the query string in an HTTP request,
541+
// setting it to true means that for metrics with multiple values (such as percentiles),
542+
// if the server determines that only a single value will be returned to the client, it
543+
// should name that field "value" instead of something like "p99".
544+
//
545+
// When the `as_value` field is used on the HTTP server side to process a request, true
546+
// means that for multi-value metrics (such as percentiles), only one value will be
547+
// returned to the client, and this single returned field will be named "value".
548+
//
549+
// This parameter can greatly simplify the structured processing of JSON responses
550+
// returned by the server.
540551
bool as_value{false};
541552
};
542553

@@ -1401,6 +1412,10 @@ class percentile : public closeable_metric
14011412
continue;
14021413
}
14031414

1415+
// If `as_value` is true, then for metrics with multiple values (such as
1416+
// percentiles), only one value needs to be returned to the client. Therefore,
1417+
// its field name is set to "value" and the loop is exited (since only a single
1418+
// value is required to be returned).
14041419
if (filters.as_value) {
14051420
encode(writer, kMetricSingleValueField, value(i));
14061421
break;

0 commit comments

Comments
 (0)