@cryptotaxi247 / netdata-1 / commits / b76a297de

Fix the context filtering on the data query endpoint (#10652)

Stelios Fragkakis committed Feb 17, 2021 at 21:13 UTC b76a297de1a89dfe9a72e68c7c2513bd350f5455
4 files changed +32 -3
web/api/formatters/rrd2json.c
+26 -1
@@ -32,6 +32,30 @@ void free_context_param_list(struct context_param **param_list)
32 *param_list = NULL;
33 }
34
35 +void rebuild_context_param_list(struct context_param *context_param_list, time_t after_requested)
36 +{
37 + RRDDIM *temp_rd = context_param_list->rd;
38 + RRDDIM *new_rd_list = NULL, *t;
39 + while (temp_rd) {
40 + t = temp_rd->next;
41 + if (rrdset_last_entry_t(temp_rd->rrdset) >= after_requested) {
42 + temp_rd->next = new_rd_list;
43 + new_rd_list = temp_rd;
44 + } else {
45 + freez((char *)temp_rd->id);
46 + freez((char *)temp_rd->name);
47 +#ifdef ENABLE_DBENGINE
48 + if (temp_rd->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE)
49 + freez(temp_rd->state->metric_uuid);
50 +#endif
51 + freez(temp_rd->state);
52 + freez(temp_rd);
53 + }
54 + temp_rd = t;
55 + }
56 + context_param_list->rd = new_rd_list;
57 +};
58 +
59 void build_context_param_list(struct context_param **param_list, RRDSET *st)
60 {
61 if (unlikely(!param_list || !st))
@@ -193,7 +217,6 @@ int rrdset2anything_api_v1(
217 time_t last_accessed_time = now_realtime_sec();
218 st->last_accessed_time = last_accessed_time;
219
196 - RRDDIM *temp_rd = context_param_list ? context_param_list->rd : NULL;
220
221 RRDR *r = rrd2rrdr(st, points, after, before, group_method, group_time, options, dimensions?buffer_tostring(dimensions):NULL, context_param_list);
222 if(!r) {
@@ -201,6 +224,8 @@ int rrdset2anything_api_v1(
224 return HTTP_RESP_INTERNAL_SERVER_ERROR;
225 }
226
227 + RRDDIM *temp_rd = context_param_list ? context_param_list->rd : NULL;
228 +
229 if(r->result_options & RRDR_RESULT_OPTION_RELATIVE)
230 buffer_no_cacheable(wb);
231 else if(r->result_options & RRDR_RESULT_OPTION_ABSOLUTE)
web/api/formatters/rrd2json.h
+1
@@ -86,6 +86,7 @@ extern int rrdset2value_api_v1(
86 );
87
88 extern void build_context_param_list(struct context_param **param_list, RRDSET *st);
89 +extern void rebuild_context_param_list(struct context_param *context_param_list, time_t after_requested);
90 extern void free_context_param_list(struct context_param **param_list);
91
92 #endif /* NETDATA_RRD2JSON_H */
web/api/queries/query.c
+3
@@ -1591,6 +1591,9 @@ RRDR *rrd2rrdr(
1591 if (first_entry_t > after_requested)
1592 first_entry_t = after_requested;
1593
1594 + if (context_param_list)
1595 + rebuild_context_param_list(context_param_list, after_requested);
1596 +
1597 #ifdef ENABLE_DBENGINE
1598 if (st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
1599 struct rrdeng_region_info *region_info_array;
web/api/queries/rrdr.c
+2 -2
@@ -130,8 +130,8 @@ RRDR *rrdr_create(struct rrdset *st, long n, struct context_param *context_param
130
131 // set the hidden flag on hidden dimensions
132 int c;
133 - for(c = 0, rd = temp_rd?temp_rd:st->dimensions ; rd ; c++, rd = rd->next) {
134 - if(unlikely(rrddim_flag_check(rd, RRDDIM_FLAG_HIDDEN)))
133 + for (c = 0, rd = temp_rd ? temp_rd : st->dimensions; rd; c++, rd = rd->next) {
134 + if (unlikely(rrddim_flag_check(rd, RRDDIM_FLAG_HIDDEN)))
135 r->od[c] = RRDR_DIMENSION_HIDDEN;
136 else
137 r->od[c] = RRDR_DIMENSION_DEFAULT;