summaryrefslogtreecommitdiffstats
path: root/database/contexts
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-14 19:20:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-14 19:20:33 +0000
commit6cf8f2d5174a53f582e61d715edbb88d6e3367cc (patch)
tree78cec0fd8d09c4a6a052461d42f4b2be3af6d396 /database/contexts
parentAdding upstream version 1.39.1. (diff)
downloadnetdata-6cf8f2d5174a53f582e61d715edbb88d6e3367cc.tar.xz
netdata-6cf8f2d5174a53f582e61d715edbb88d6e3367cc.zip
Adding upstream version 1.40.0.upstream/1.40.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'database/contexts')
-rw-r--r--database/contexts/api_v2.c19
-rw-r--r--database/contexts/query_target.c2
-rw-r--r--database/contexts/rrdcontext.h39
3 files changed, 41 insertions, 19 deletions
diff --git a/database/contexts/api_v2.c b/database/contexts/api_v2.c
index a08d1509c..d83a9e9e3 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 69386a3f8..7759f85e8 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 5328483d6..0f0f90d32 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