gavinchou commented on code in PR #59329:
URL: https://github.com/apache/doris/pull/59329#discussion_r2645388305
##########
cloud/src/common/metric.cpp:
##########
@@ -296,10 +234,117 @@ static void export_fdb_status_details(const std::string&
status_str) {
}
}
+ // Helper function for recursive name construction
+ // such as: {"disk": {"reads": {"counter": 123, "hz": 0}}}
+ // component is "disk", the names of these two values should be
"reads_counter" and "reads_hz"
+ auto recursive_name_helper = [](std::string& origin_name,
+ const char* next_level_name) ->
std::string {
+ return origin_name + '_' + next_level_name;
+ };
+
+ // Generic recursive function to traverse JSON node and set bvar values
+ // There are three cases here: int64, double, and object.
+ // If it is double or int64, put it directly into the bvar.
+ // If it is an object, recursively obtain the full name and corresponding
value.
+ auto recursive_traverse_and_set = [&recursive_name_helper](auto&&
set_value_callback,
+ auto&& self,
std::string name,
+ auto temp_node)
-> void {
+ // if the node is an object, then get Member(iter) and recursive with
iter as arg
+ if (temp_node->value.IsObject()) {
+ for (auto iter = temp_node->value.MemberBegin(); iter !=
temp_node->value.MemberEnd();
+ iter++) {
+ self(set_value_callback, self, recursive_name_helper(name,
iter->name.GetString()),
+ iter);
+ }
+ return;
+ }
+ // if not object, set bvar value
+ set_value_callback(name, temp_node);
+ };
+
+ auto get_process_metric = [&](std::string component) {
+ auto node = document.FindMember("cluster");
+ if (!node->value.HasMember("processes")) return;
+ node = node->value.FindMember("processes");
+ // process
+ for (auto process_node = node->value.MemberBegin(); process_node !=
node->value.MemberEnd();
+ process_node++) {
+ const char* process_id = process_node->name.GetString();
+ decltype(process_node) component_node;
+ // get component iter
+ if (!process_node->value.HasMember(component.data())) return;
Review Comment:
seems should be `continue` instead of `return` if there is no such a member
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]