@cryptotaxi247 / netdata-1 / commits / f3d00f79a

Added new data query option "allow_past" (#10112)

Stelios Fragkakis committed Oct 22, 2020 at 21:43 UTC f3d00f79abfa6a2f61b80d2ebff22cfba7b4aa6b
5 files changed +52 -25
web/api/netdata-swagger.json
+22 -10
@@ -130,8 +130,8 @@
130 {
131 "name": "chart",
132 "in": "query",
133 - "description": "The id of the chart as returned by the /charts call.",
134 - "required": true,
133 + "description": "The id of the chart as returned by the /charts call. Note chart or context must be specified",
134 + "required": false,
135 "allowEmptyValue": false,
136 "schema": {
137 "type": "string",
@@ -139,6 +139,17 @@
139 "default": "system.cpu"
140 }
141 },
142 + {
143 + "name": "context",
144 + "in": "query",
145 + "description": "The context of the chart as returned by the /charts call. Note chart or context must be specified",
146 + "required": false,
147 + "allowEmptyValue": false,
148 + "schema": {
149 + "type": "string",
150 + "format": "as returned by /charts"
151 + }
152 + },
153 {
154 "name": "dimension",
155 "in": "query",
@@ -156,7 +167,7 @@
167 {
168 "name": "after",
169 "in": "query",
159 - "description": "This parameter can either be an absolute timestamp specifying the starting point of the data to be returned, or a relative number of seconds (negative, relative to parameter: before). Netdata will assume it is a relative number if it is less that 3 years (in seconds). Netdata will adapt this parameter to the boundaries of the round robin database. The default is the beginning of the round robin database (i.e. by default netdata will attempt to return data for the entire database).",
170 + "description": "This parameter can either be an absolute timestamp specifying the starting point of the data to be returned, or a relative number of seconds (negative, relative to parameter: before). Netdata will assume it is a relative number if it is less that 3 years (in seconds). If not specified the default is -600 seconds. Netdata will adapt this parameter to the boundaries of the round robin database unless the allow_past option is specified.",
171 "required": true,
172 "allowEmptyValue": false,
173 "schema": {
@@ -273,7 +284,8 @@
284 "unaligned",
285 "match-ids",
286 "match-names",
276 - "showcustomvars"
287 + "showcustomvars",
288 + "allow_past"
289 ]
290 },
291 "default": [
@@ -328,7 +340,7 @@
340 "description": "Bad request - the body will include a message stating what is wrong."
341 },
342 "404": {
331 - "description": "No chart with the given id is found."
343 + "description": "Chart or context is not found. The supplied chart or context will be reported."
344 },
345 "500": {
346 "description": "Internal server error. This usually means the server is out of memory."
@@ -478,7 +490,7 @@
490 "oneOf": [
491 {
492 "type": "string",
481 - "enum" : [
493 + "enum": [
494 "green",
495 "brightgreen",
496 "yellow",
@@ -520,7 +532,7 @@
532 "oneOf": [
533 {
534 "type": "string",
523 - "enum" : [
535 + "enum": [
536 "green",
537 "brightgreen",
538 "yellow",
@@ -551,7 +563,7 @@
563 "oneOf": [
564 {
565 "type": "string",
554 - "enum" : [
566 + "enum": [
567 "green",
568 "brightgreen",
569 "yellow",
@@ -812,7 +824,7 @@
824 "/alarms": {
825 "get": {
826 "summary": "Get a list of active or raised alarms on the server",
815 - "description": "The alarms endpoint returns the list of all raised or enabled alarms on the Netdata agent. Called without any parameters, the raised alarms in state WARNING or CRITICAL are returned, the same response is delivered when \"?active\" is passed in the URL. By passing \"?all\", all the enabled alarms are returned.",
827 + "description": "The alarms endpoint returns the list of all raised or enabled alarms on the netdata server. Called without any parameters, the raised alarms in state WARNING or CRITICAL are returned. By passing \"?all\", all the enabled alarms are returned.",
828 "parameters": [
829 {
830 "name": "all",
@@ -852,7 +864,7 @@
864 "/alarms_values": {
865 "get": {
866 "summary": "Get a list of active or raised alarms on the server",
855 - "description": "The alarms endpoint returns the list of all raised or enabled alarms on the Netdata agent. Called without any parameters, the raised alarms in state WARNING or CRITICAL are returned, the same response is delivered when \"?active\" is passed in the URL. By passing \"?all\", all the enabled alarms are returned.",
867 + "description": "The alarms_values endpoint returns the list of all raised or enabled alarms on the netdata server. Called without any parameters, the raised alarms in state WARNING or CRITICAL are returned. By passing \"?all\", all the enabled alarms are returned. This option output differs from `/alarms` in the number of variables delivered. This endpoint gives to user `id`, `value` and alarm `status`.",
868 "parameters": [
869 {
870 "name": "all",
web/api/netdata-swagger.yaml
+16 -8
@@ -101,13 +101,21 @@ paths:
101 parameters:
102 - name: chart
103 in: query
104 - description: The id of the chart as returned by the /charts call.
105 - required: true
104 + description: The id of the chart as returned by the /charts call. Note chart or context must be specified
105 + required: false
106 allowEmptyValue: false
107 schema:
108 type: string
109 format: as returned by /charts
110 default: system.cpu
111 + - name: context
112 + in: query
113 + description: The context of the chart as returned by the /charts call. Note chart or context must be specified
114 + required: false
115 + allowEmptyValue: false
116 + schema:
117 + type: string
118 + format: as returned by /charts
119 - name: dimension
120 in: query
121 description: Zero, one or more dimension ids or names, as returned by the /chart
@@ -125,11 +133,10 @@ paths:
133 description: "This parameter can either be an absolute timestamp specifying the
134 starting point of the data to be returned, or a relative number of
135 seconds (negative, relative to parameter: before). Netdata will
128 - assume it is a relative number if it is less that 3 years (in
129 - seconds). Netdata will adapt this parameter to the boundaries of the
130 - round robin database. The default is the beginning of the round
131 - robin database (i.e. by default netdata will attempt to return data
132 - for the entire database)."
136 + assume it is a relative number if it is less that 3 years (in seconds).
137 + If not specified the default is -600 seconds. Netdata will adapt this
138 + parameter to the boundaries of the round robin database unless the allow_past
139 + option is specified."
140 required: true
141 allowEmptyValue: false
142 schema:
@@ -243,6 +250,7 @@ paths:
250 - match-ids
251 - match-names
252 - showcustomvars
253 + - allow_past
254 default:
255 - seconds
256 - jsonwrap
@@ -285,7 +293,7 @@ paths:
293 "400":
294 description: Bad request - the body will include a message stating what is wrong.
295 "404":
288 - description: No chart with the given id is found.
296 + description: Chart or context is not found. The supplied chart or context will be reported.
297 "500":
298 description: Internal server error. This usually means the server is out of
299 memory.
web/api/queries/query.c
+12 -7
@@ -740,6 +740,7 @@ static int rrdr_convert_before_after_to_absolute(
740 , int update_every
741 , time_t first_entry_t
742 , time_t last_entry_t
743 + , RRDR_OPTIONS options
744 ) {
745 int absolute_period_requested = -1;
746 long long after_requested, before_requested;
@@ -785,10 +786,12 @@ static int rrdr_convert_before_after_to_absolute(
786
787 // make sure they are within our timeframe
788 if(before_requested > last_entry_t) before_requested = last_entry_t;
788 - if(before_requested < first_entry_t) before_requested = first_entry_t;
789 + if(before_requested < first_entry_t && !(options & RRDR_OPTION_ALLOW_PAST))
790 + before_requested = first_entry_t;
791
792 if(after_requested > last_entry_t) after_requested = last_entry_t;
791 - if(after_requested < first_entry_t) after_requested = first_entry_t;
793 + if(after_requested < first_entry_t && !(options & RRDR_OPTION_ALLOW_PAST))
794 + after_requested = first_entry_t;
795
796 // check if they are reversed
797 if(after_requested > before_requested) {
@@ -1566,8 +1569,6 @@ RRDR *rrd2rrdr(
1569 int rrd_update_every;
1570 int absolute_period_requested;
1571
1569 -// RRDDIM *temp_rd = context_param_list ? context_param_list->rd : NULL;
1570 -
1572 time_t first_entry_t;
1573 time_t last_entry_t;
1574 if (context_param_list) {
@@ -1581,7 +1582,11 @@ RRDR *rrd2rrdr(
1582 rrd_update_every = st->update_every;
1583 absolute_period_requested = rrdr_convert_before_after_to_absolute(&after_requested, &before_requested,
1584 rrd_update_every, first_entry_t,
1584 - last_entry_t);
1585 + last_entry_t, options);
1586 + if (options & RRDR_OPTION_ALLOW_PAST)
1587 + if (first_entry_t > after_requested)
1588 + first_entry_t = after_requested;
1589 +
1590 #ifdef ENABLE_DBENGINE
1591 if (st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
1592 struct rrdeng_region_info *region_info_array;
@@ -1597,7 +1602,7 @@ RRDR *rrd2rrdr(
1602 /* recalculate query alignment */
1603 absolute_period_requested =
1604 rrdr_convert_before_after_to_absolute(&after_requested, &before_requested, rrd_update_every,
1600 - first_entry_t, last_entry_t);
1605 + first_entry_t, last_entry_t, options);
1606 }
1607 freez(region_info_array);
1608 }
@@ -1610,7 +1615,7 @@ RRDR *rrd2rrdr(
1615 /* recalculate query alignment */
1616 absolute_period_requested = rrdr_convert_before_after_to_absolute(&after_requested, &before_requested,
1617 rrd_update_every, first_entry_t,
1613 - last_entry_t);
1618 + last_entry_t, options);
1619 }
1620 return rrd2rrdr_variablestep(st, points_requested, after_requested, before_requested, group_method,
1621 resampling_time_requested, options, dimensions, rrd_update_every,
web/api/queries/rrdr.h
+1
@@ -23,6 +23,7 @@ typedef enum rrdr_options {
23 RRDR_OPTION_MATCH_IDS = 0x00004000, // when filtering dimensions, match only IDs
24 RRDR_OPTION_MATCH_NAMES = 0x00008000, // when filtering dimensions, match only names
25 RRDR_OPTION_CUSTOM_VARS = 0x00010000, // when wraping response in a JSON, return custom variables in response
26 + RRDR_OPTION_ALLOW_PAST = 0x00020000, // The after parameter can extend in the past before the first entry
27 } RRDR_OPTIONS;
28
29 typedef enum rrdr_value_flag {
web/api/web_api_v1.c
+1
@@ -35,6 +35,7 @@ static struct {
35 , {"match_names" , 0 , RRDR_OPTION_MATCH_NAMES}
36 , {"match-names" , 0 , RRDR_OPTION_MATCH_NAMES}
37 , {"showcustomvars" , 0 , RRDR_OPTION_CUSTOM_VARS}
38 + , {"allow_past" , 0 , RRDR_OPTION_ALLOW_PAST}
39 , { NULL, 0, 0}
40 };
41