From f3d00f79abfa6a2f61b80d2ebff22cfba7b4aa6b Mon Sep 17 00:00:00 2001 From: Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> Date: Thu, 22 Oct 2020 21:43:20 +0300 Subject: Added new data query option "allow_past" (#10112) --- web/api/netdata-swagger.json | 32 ++++++++++++++++++++++---------- web/api/netdata-swagger.yaml | 24 ++++++++++++++++-------- web/api/queries/query.c | 19 ++++++++++++------- web/api/queries/rrdr.h | 1 + web/api/web_api_v1.c | 1 + 5 files changed, 52 insertions(+), 25 deletions(-) (limited to 'web') diff --git a/web/api/netdata-swagger.json b/web/api/netdata-swagger.json index c6a24e1af7..47f5fe379d 100644 --- a/web/api/netdata-swagger.json +++ b/web/api/netdata-swagger.json @@ -130,8 +130,8 @@ { "name": "chart", "in": "query", - "description": "The id of the chart as returned by the /charts call.", - "required": true, + "description": "The id of the chart as returned by the /charts call. Note chart or context must be specified", + "required": false, "allowEmptyValue": false, "schema": { "type": "string", @@ -139,6 +139,17 @@ "default": "system.cpu" } }, + { + "name": "context", + "in": "query", + "description": "The context of the chart as returned by the /charts call. Note chart or context must be specified", + "required": false, + "allowEmptyValue": false, + "schema": { + "type": "string", + "format": "as returned by /charts" + } + }, { "name": "dimension", "in": "query", @@ -156,7 +167,7 @@ { "name": "after", "in": "query", - "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).", + "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.", "required": true, "allowEmptyValue": false, "schema": { @@ -273,7 +284,8 @@ "unaligned", "match-ids", "match-names", - "showcustomvars" + "showcustomvars", + "allow_past" ] }, "default": [ @@ -328,7 +340,7 @@ "description": "Bad request - the body will include a message stating what is wrong." }, "404": { - "description": "No chart with the given id is found." + "description": "Chart or context is not found. The supplied chart or context will be reported." }, "500": { "description": "Internal server error. This usually means the server is out of memory." @@ -478,7 +490,7 @@ "oneOf": [ { "type": "string", - "enum" : [ + "enum": [ "green", "brightgreen", "yellow", @@ -520,7 +532,7 @@ "oneOf": [ { "type": "string", - "enum" : [ + "enum": [ "green", "brightgreen", "yellow", @@ -551,7 +563,7 @@ "oneOf": [ { "type": "string", - "enum" : [ + "enum": [ "green", "brightgreen", "yellow", @@ -812,7 +824,7 @@ "/alarms": { "get": { "summary": "Get a list of active or raised alarms on the server", - "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.", + "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.", "parameters": [ { "name": "all", @@ -852,7 +864,7 @@ "/alarms_values": { "get": { "summary": "Get a list of active or raised alarms on the server", - "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.", + "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`.", "parameters": [ { "name": "all", diff --git a/web/api/netdata-swagger.yaml b/web/api/netdata-swagger.yaml index b52de2c9dc..8ccf299812 100644 --- a/web/api/netdata-swagger.yaml +++ b/web/api/netdata-swagger.yaml @@ -101,13 +101,21 @@ paths: parameters: - name: chart in: query - description: The id of the chart as returned by the /charts call. - required: true + description: The id of the chart as returned by the /charts call. Note chart or context must be specified + required: false allowEmptyValue: false schema: type: string format: as returned by /charts default: system.cpu + - name: context + in: query + description: The context of the chart as returned by the /charts call. Note chart or context must be specified + required: false + allowEmptyValue: false + schema: + type: string + format: as returned by /charts - name: dimension in: query description: Zero, one or more dimension ids or names, as returned by the /chart @@ -125,11 +133,10 @@ paths: 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)." + 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." required: true allowEmptyValue: false schema: @@ -243,6 +250,7 @@ paths: - match-ids - match-names - showcustomvars + - allow_past default: - seconds - jsonwrap @@ -285,7 +293,7 @@ paths: "400": description: Bad request - the body will include a message stating what is wrong. "404": - description: No chart with the given id is found. + description: Chart or context is not found. The supplied chart or context will be reported. "500": description: Internal server error. This usually means the server is out of memory. diff --git a/web/api/queries/query.c b/web/api/queries/query.c index 73779a6134..91eec84651 100644 --- a/web/api/queries/query.c +++ b/web/api/queries/query.c @@ -740,6 +740,7 @@ static int rrdr_convert_before_after_to_absolute( , int update_every , time_t first_entry_t , time_t last_entry_t + , RRDR_OPTIONS options ) { int absolute_period_requested = -1; long long after_requested, before_requested; @@ -785,10 +786,12 @@ static int rrdr_convert_before_after_to_absolute( // make sure they are within our timeframe if(before_requested > last_entry_t) before_requested = last_entry_t; - if(before_requested < first_entry_t) before_requested = first_entry_t; + if(before_requested < first_entry_t && !(options & RRDR_OPTION_ALLOW_PAST)) + before_requested = first_entry_t; if(after_requested > last_entry_t) after_requested = last_entry_t; - if(after_requested < first_entry_t) after_requested = first_entry_t; + if(after_requested < first_entry_t && !(options & RRDR_OPTION_ALLOW_PAST)) + after_requested = first_entry_t; // check if they are reversed if(after_requested > before_requested) { @@ -1566,8 +1569,6 @@ RRDR *rrd2rrdr( int rrd_update_every; int absolute_period_requested; -// RRDDIM *temp_rd = context_param_list ? context_param_list->rd : NULL; - time_t first_entry_t; time_t last_entry_t; if (context_param_list) { @@ -1581,7 +1582,11 @@ RRDR *rrd2rrdr( rrd_update_every = st->update_every; absolute_period_requested = rrdr_convert_before_after_to_absolute(&after_requested, &before_requested, rrd_update_every, first_entry_t, - last_entry_t); + last_entry_t, options); + if (options & RRDR_OPTION_ALLOW_PAST) + if (first_entry_t > after_requested) + first_entry_t = after_requested; + #ifdef ENABLE_DBENGINE if (st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) { struct rrdeng_region_info *region_info_array; @@ -1597,7 +1602,7 @@ RRDR *rrd2rrdr( /* recalculate query alignment */ absolute_period_requested = rrdr_convert_before_after_to_absolute(&after_requested, &before_requested, rrd_update_every, - first_entry_t, last_entry_t); + first_entry_t, last_entry_t, options); } freez(region_info_array); } @@ -1610,7 +1615,7 @@ RRDR *rrd2rrdr( /* recalculate query alignment */ absolute_period_requested = rrdr_convert_before_after_to_absolute(&after_requested, &before_requested, rrd_update_every, first_entry_t, - last_entry_t); + last_entry_t, options); } return rrd2rrdr_variablestep(st, points_requested, after_requested, before_requested, group_method, resampling_time_requested, options, dimensions, rrd_update_every, diff --git a/web/api/queries/rrdr.h b/web/api/queries/rrdr.h index 2ed96cac46..4d349c3050 100644 --- a/web/api/queries/rrdr.h +++ b/web/api/queries/rrdr.h @@ -23,6 +23,7 @@ typedef enum rrdr_options { RRDR_OPTION_MATCH_IDS = 0x00004000, // when filtering dimensions, match only IDs RRDR_OPTION_MATCH_NAMES = 0x00008000, // when filtering dimensions, match only names RRDR_OPTION_CUSTOM_VARS = 0x00010000, // when wraping response in a JSON, return custom variables in response + RRDR_OPTION_ALLOW_PAST = 0x00020000, // The after parameter can extend in the past before the first entry } RRDR_OPTIONS; typedef enum rrdr_value_flag { diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c index 4f10a681e7..33a2ff6d07 100644 --- a/web/api/web_api_v1.c +++ b/web/api/web_api_v1.c @@ -35,6 +35,7 @@ static struct { , {"match_names" , 0 , RRDR_OPTION_MATCH_NAMES} , {"match-names" , 0 , RRDR_OPTION_MATCH_NAMES} , {"showcustomvars" , 0 , RRDR_OPTION_CUSTOM_VARS} + , {"allow_past" , 0 , RRDR_OPTION_ALLOW_PAST} , { NULL, 0, 0} }; -- cgit v1.2.3