diff options
Diffstat (limited to 'database/contexts')
-rw-r--r-- | database/contexts/api_v2.c | 19 | ||||
-rw-r--r-- | database/contexts/query_target.c | 2 | ||||
-rw-r--r-- | database/contexts/rrdcontext.h | 39 |
3 files changed, 41 insertions, 19 deletions
diff --git a/database/contexts/api_v2.c b/database/contexts/api_v2.c index a08d1509..d83a9e9e 100644 --- a/database/contexts/api_v2.c +++ b/database/contexts/api_v2.c @@ -352,21 +352,12 @@ static ssize_t rrdcontext_to_json_v2_add_host(void *data, RRDHOST *host, bool qu buffer_json_member_add_string_or_empty(wb, "osVersion", host->system_info->host_os_version); } + time_t now = now_realtime_sec(); buffer_json_member_add_object(wb, "status"); - - size_t receiver_hops = host->system_info ? host->system_info->hops : (host == localhost) ? 0 : 1; - buffer_json_member_add_object(wb, "collection"); - buffer_json_member_add_uint64(wb, "hops", receiver_hops); - buffer_json_member_add_boolean(wb, "online", host == localhost || !rrdhost_flag_check(host, RRDHOST_FLAG_ORPHAN | RRDHOST_FLAG_RRDPUSH_RECEIVER_DISCONNECTED)); - buffer_json_member_add_boolean(wb, "replicating", rrdhost_receiver_replicating_charts(host)); - buffer_json_object_close(wb); // collection - - buffer_json_member_add_object(wb, "streaming"); - buffer_json_member_add_uint64(wb, "hops", host->sender ? host->sender->hops : receiver_hops + 1); - buffer_json_member_add_boolean(wb, "online", rrdhost_flag_check(host, RRDHOST_FLAG_RRDPUSH_SENDER_CONNECTED)); - buffer_json_member_add_boolean(wb, "replicating", rrdhost_sender_replicating_charts(host)); - buffer_json_object_close(wb); // streaming - + { + rrdhost_receiver_to_json(wb, host, "collection", now); + rrdhost_sender_to_json(wb, host, "streaming", now); + } buffer_json_object_close(wb); // status } diff --git a/database/contexts/query_target.c b/database/contexts/query_target.c index 69386a3f..7759f85e 100644 --- a/database/contexts/query_target.c +++ b/database/contexts/query_target.c @@ -1049,7 +1049,7 @@ QUERY_TARGET *query_target_create(QUERY_TARGET_REQUEST *qtr) { qt->window.before = qt->request.before; qt->window.options = qt->request.options; - if(query_target_has_percentage_of_instance(qt)) + if(query_target_has_percentage_of_group(qt)) qt->window.options &= ~RRDR_OPTION_PERCENTAGE; rrdr_relative_window_to_absolute(&qt->window.after, &qt->window.before, &qt->window.now); diff --git a/database/contexts/rrdcontext.h b/database/contexts/rrdcontext.h index 5328483d..0f0f90d3 100644 --- a/database/contexts/rrdcontext.h +++ b/database/contexts/rrdcontext.h @@ -524,10 +524,41 @@ bool rrdcontext_retention_match(RRDCONTEXT_ACQUIRED *rca, time_t after, time_t b #define query_target_aggregatable(qt) ((qt)->window.options & RRDR_OPTION_RETURN_RAW) -static inline bool query_target_has_percentage_of_instance(QUERY_TARGET *qt) { - for(size_t g = 0; g < MAX_QUERY_GROUP_BY_PASSES ;g++) +static inline bool query_has_group_by_aggregation_percentage(QUERY_TARGET *qt) { + + // backwards compatibility + // If the request was made with group_by = "percentage-of-instance" + // we need to send back "raw" output with "count" + // otherwise, we need to send back "raw" output with "hidden" + + bool last_is_percentage = false; + + for(int g = 0; g < MAX_QUERY_GROUP_BY_PASSES ;g++) { + if(qt->request.group_by[g].group_by == RRDR_GROUP_BY_NONE) + break; + if(qt->request.group_by[g].group_by & RRDR_GROUP_BY_PERCENTAGE_OF_INSTANCE) + // backwards compatibility + return false; + + if(qt->request.group_by[g].aggregation == RRDR_GROUP_BY_FUNCTION_PERCENTAGE) + last_is_percentage = true; + + else + last_is_percentage = false; + } + + return last_is_percentage; +} + +static inline bool query_target_has_percentage_of_group(QUERY_TARGET *qt) { + for(size_t g = 0; g < MAX_QUERY_GROUP_BY_PASSES ;g++) { + if (qt->request.group_by[g].group_by & RRDR_GROUP_BY_PERCENTAGE_OF_INSTANCE) + return true; + + if (qt->request.group_by[g].aggregation == RRDR_GROUP_BY_FUNCTION_PERCENTAGE) return true; + } return false; } @@ -536,7 +567,7 @@ static inline bool query_target_needs_all_dimensions(QUERY_TARGET *qt) { if(qt->request.options & RRDR_OPTION_PERCENTAGE) return true; - return query_target_has_percentage_of_instance(qt); + return query_target_has_percentage_of_group(qt); } static inline bool query_target_has_percentage_units(QUERY_TARGET *qt) { @@ -546,7 +577,7 @@ static inline bool query_target_has_percentage_units(QUERY_TARGET *qt) { if((qt->request.options & RRDR_OPTION_PERCENTAGE) && !(qt->window.options & RRDR_OPTION_RETURN_RAW)) return true; - return query_target_has_percentage_of_instance(qt); + return query_target_has_percentage_of_group(qt); } #endif // NETDATA_RRDCONTEXT_H |