/api/v2 part 8 (#14885)
* configure extent cache size * /api/v2/data responsed with the id of dimensions in result.labels * provide the original units and sts to db.dimensions * updated swagger for the changes
Costa Tsaousis committed
Apr 10, 2023 at 16:24 UTC
4c82a156513f4989cab016d53426eb695ae8d1ca
4 files changed
+130
-191
web/api/formatters/json/json.c
+1
-1
@@ -261,7 +261,7 @@ void rrdr2json_v2(RRDR *r, BUFFER *wb) {
261
if(!rrdr_dimension_should_be_exposed(r->od[d], options))
262
continue;
263
264
- buffer_json_add_array_item_string(wb, string2str(r->dn[d]));
264
+ buffer_json_add_array_item_string(wb, string2str(r->di[d]));
265
i++;
266
}
267
buffer_json_array_close(wb); // labels
web/api/formatters/json_wrapper.c
+38
-30
@@ -950,8 +950,8 @@ static void rrdset_rrdcalc_entries_v2(BUFFER *wb, RRDINSTANCE_ACQUIRED *ria) {
950
}
951
}
952
953
-static void query_target_combined_units_v2(BUFFER *wb, QUERY_TARGET *qt, size_t contexts) {
954
- if(query_target_has_percentage_units(qt)) {
953
+static void query_target_combined_units_v2(BUFFER *wb, QUERY_TARGET *qt, size_t contexts, bool ignore_percentage) {
954
+ if(!ignore_percentage && query_target_has_percentage_units(qt)) {
955
buffer_json_member_add_string(wb, "units", "%");
956
}
957
else if(contexts == 1) {
@@ -1036,11 +1036,11 @@ static void rrdr_grouped_by_array_v2(BUFFER *wb, const char *key, RRDR *r, RRDR_
1036
buffer_json_array_close(wb); // group_by_order
1037
}
1038
1039
-static void rrdr_dimension_units_array_v2(BUFFER *wb, const char *key, RRDR *r, RRDR_OPTIONS options) {
1039
+static void rrdr_dimension_units_array_v2(BUFFER *wb, const char *key, RRDR *r, RRDR_OPTIONS options, bool ignore_percentage) {
1040
if(!r->du)
1041
return;
1042
1043
- bool percentage = query_target_has_percentage_units(r->internal.qt);
1043
+ bool percentage = !ignore_percentage && query_target_has_percentage_units(r->internal.qt);
1044
1045
buffer_json_member_add_array(wb, key);
1046
for(size_t c = 0; c < r->d ; c++) {
@@ -1402,28 +1402,6 @@ void rrdr_json_wrapper_begin2(RRDR *r, BUFFER *wb) {
1402
}
1403
1404
query_target_functions(wb, "functions", r);
1405
-
1406
- buffer_json_member_add_object(wb, "db");
1407
- {
1408
- buffer_json_member_add_uint64(wb, "tiers", storage_tiers);
1409
- buffer_json_member_add_time_t(wb, "update_every", qt->db.minimum_latest_update_every_s);
1410
- buffer_json_member_add_time_t(wb, "first_entry", qt->db.first_time_s);
1411
- buffer_json_member_add_time_t(wb, "last_entry", qt->db.last_time_s);
1412
-
1413
- buffer_json_member_add_array(wb, "per_tier");
1414
- for(size_t tier = 0; tier < storage_tiers ; tier++) {
1415
- buffer_json_add_array_item_object(wb);
1416
- buffer_json_member_add_uint64(wb, "tier", tier);
1417
- buffer_json_member_add_uint64(wb, "queries", qt->db.tiers[tier].queries);
1418
- buffer_json_member_add_uint64(wb, "points", qt->db.tiers[tier].points);
1419
- buffer_json_member_add_time_t(wb, "update_every", qt->db.tiers[tier].update_every);
1420
- buffer_json_member_add_time_t(wb, "first_entry", qt->db.tiers[tier].retention.first_time_s);
1421
- buffer_json_member_add_time_t(wb, "last_entry", qt->db.tiers[tier].retention.last_time_s);
1422
- buffer_json_object_close(wb);
1423
- }
1424
- buffer_json_array_close(wb);
1425
- }
1426
- buffer_json_object_close(wb);
1405
}
1406
1407
//static void annotations_range_for_value_flags(RRDR *r, BUFFER *wb, DATASOURCE_FORMAT format __maybe_unused, RRDR_OPTIONS options, RRDR_VALUE_FLAGS flags, const char *type) {
@@ -1512,6 +1490,37 @@ void rrdr_json_wrapper_end2(RRDR *r, BUFFER *wb) {
1490
DATASOURCE_FORMAT format = qt->request.format;
1491
RRDR_OPTIONS options = qt->window.options;
1492
1493
+ buffer_json_member_add_object(wb, "db");
1494
+ {
1495
+ buffer_json_member_add_uint64(wb, "tiers", storage_tiers);
1496
+ buffer_json_member_add_time_t(wb, "update_every", qt->db.minimum_latest_update_every_s);
1497
+ buffer_json_member_add_time_t(wb, "first_entry", qt->db.first_time_s);
1498
+ buffer_json_member_add_time_t(wb, "last_entry", qt->db.last_time_s);
1499
+
1500
+ query_target_combined_units_v2(wb, qt, r->internal.contexts, true);
1501
+ buffer_json_member_add_object(wb, "dimensions");
1502
+ {
1503
+ rrdr_dimension_ids(wb, "ids", r, options);
1504
+ rrdr_dimension_units_array_v2(wb, "units", r, options, true);
1505
+ rrdr_dimension_query_points_statistics(wb, "sts", r, options, false);
1506
+ }
1507
+ buffer_json_object_close(wb); // dimensions
1508
+
1509
+ buffer_json_member_add_array(wb, "per_tier");
1510
+ for(size_t tier = 0; tier < storage_tiers ; tier++) {
1511
+ buffer_json_add_array_item_object(wb);
1512
+ buffer_json_member_add_uint64(wb, "tier", tier);
1513
+ buffer_json_member_add_uint64(wb, "queries", qt->db.tiers[tier].queries);
1514
+ buffer_json_member_add_uint64(wb, "points", qt->db.tiers[tier].points);
1515
+ buffer_json_member_add_time_t(wb, "update_every", qt->db.tiers[tier].update_every);
1516
+ buffer_json_member_add_time_t(wb, "first_entry", qt->db.tiers[tier].retention.first_time_s);
1517
+ buffer_json_member_add_time_t(wb, "last_entry", qt->db.tiers[tier].retention.last_time_s);
1518
+ buffer_json_object_close(wb);
1519
+ }
1520
+ buffer_json_array_close(wb);
1521
+ }
1522
+ buffer_json_object_close(wb);
1523
+
1524
buffer_json_member_add_object(wb, "view");
1525
{
1526
query_target_title(wb, qt, r->internal.contexts);
@@ -1536,18 +1545,17 @@ void rrdr_json_wrapper_end2(RRDR *r, BUFFER *wb) {
1545
if(options & RRDR_OPTION_RETURN_RAW)
1546
buffer_json_member_add_uint64(wb, "points", rrdr_rows(r));
1547
1539
- query_target_combined_units_v2(wb, qt, r->internal.contexts);
1548
+ query_target_combined_units_v2(wb, qt, r->internal.contexts, false);
1549
query_target_combined_chart_type(wb, qt, r->internal.contexts);
1550
buffer_json_member_add_object(wb, "dimensions");
1551
{
1552
rrdr_grouped_by_array_v2(wb, "grouped_by", r, options);
1553
rrdr_dimension_ids(wb, "ids", r, options);
1554
rrdr_dimension_names(wb, "names", r, options);
1546
- rrdr_dimension_units_array_v2(wb, "units", r, options);
1555
+ rrdr_dimension_units_array_v2(wb, "units", r, options, false);
1556
rrdr_dimension_priority_array_v2(wb, "priorities", r, options);
1557
rrdr_dimension_aggregated_array_v2(wb, "aggregated", r, options);
1549
- rrdr_dimension_query_points_statistics(wb, NULL, r, options, true);
1550
- rrdr_dimension_query_points_statistics(wb, "sts", r, options, false);
1558
+ rrdr_dimension_query_points_statistics(wb, "sts", r, options, true);
1559
rrdr_json_group_by_labels(wb, "labels", r, options);
1560
}
1561
buffer_json_object_close(wb); // dimensions
web/api/netdata-swagger.json
+55
-82
@@ -394,6 +394,7 @@
394
"enum": [
395
"dimension",
396
"instance",
397
+ "percentage-of-instance",
398
"label",
399
"node",
400
"context",
@@ -2994,6 +2995,50 @@
2995
}
2996
}
2997
}
2998
+ },
2999
+ "units": {
3000
+ "description": "The units of the database data\n",
3001
+ "oneOf": [
3002
+ {
3003
+ "type": "string"
3004
+ },
3005
+ {
3006
+ "type": "array",
3007
+ "items": {
3008
+ "type": "string"
3009
+ }
3010
+ }
3011
+ ]
3012
+ },
3013
+ "dimensions": {
3014
+ "type": "object",
3015
+ "properties": {
3016
+ "ids": {
3017
+ "description": "An array with the dimension ids that uniquely identify the dimensions for this query. It is the same with `view.dimensions.ids`.\n",
3018
+ "type": "array",
3019
+ "items": {
3020
+ "type": "string"
3021
+ }
3022
+ },
3023
+ "units": {
3024
+ "description": "An array with the units each dimension has in the database (independent of group-by aggregation that may override the units).\n",
3025
+ "type": "array",
3026
+ "items": {
3027
+ "type": "string"
3028
+ }
3029
+ },
3030
+ "sts": {
3031
+ "description": "Statistics about the data collection points used for each dimension.\n",
3032
+ "oneOf": [
3033
+ {
3034
+ "$ref": "#/components/schemas/jsonwrap2_sts"
3035
+ },
3036
+ {
3037
+ "$ref": "#/components/schemas/jsonwrap2_sts_raw"
3038
+ }
3039
+ ]
3040
+ }
3041
+ }
3042
}
3043
}
3044
},
@@ -3107,13 +3152,6 @@
3152
"type": "string"
3153
}
3154
},
3110
- "units": {
3111
- "description": "An array with the units each dimension has.\n",
3112
- "type": "array",
3113
- "items": {
3114
- "type": "string"
3115
- }
3116
- },
3155
"priorities": {
3156
"description": "An array with the relative priorities of the dimensions.\nNumbers may not be sequential or unique. The application is expected to order by this and then by name.\n",
3157
"type": "array",
@@ -3128,88 +3166,23 @@
3166
"type": "integer"
3167
}
3168
},
3131
- "min": {
3132
- "description": "An array of the minimum value of each dimension across the entire query.\n",
3133
- "type": "array",
3134
- "items": {
3135
- "type": "number"
3136
- }
3137
- },
3138
- "max": {
3139
- "description": "An array of the maximum value of each dimension across the entire query.\n",
3140
- "type": "array",
3141
- "items": {
3142
- "type": "number"
3143
- }
3144
- },
3145
- "avg": {
3146
- "description": "An array of the average value of each dimension across the entire query.\n",
3169
+ "units": {
3170
+ "description": "An array with the units each dimension has.\n",
3171
"type": "array",
3172
"items": {
3149
- "type": "number"
3173
+ "type": "string"
3174
}
3175
},
3176
"sts": {
3153
- "description": "Statistics about the data collection points used for each dimension.\n",
3154
- "type": "object",
3155
- "properties": {
3156
- "min": {
3157
- "description": "An array with the minimum data collection value aggregated to each dimension.\n",
3158
- "type": "array",
3159
- "items": {
3160
- "type": "number"
3161
- }
3177
+ "description": "Statistics about the view points for each dimension.\n",
3178
+ "oneOf": [
3179
+ {
3180
+ "$ref": "#/components/schemas/jsonwrap2_sts"
3181
},
3163
- "max": {
3164
- "description": "An array with the maximum data collection value aggregated to each dimension.\n",
3165
- "type": "array",
3166
- "items": {
3167
- "type": "number"
3168
- }
3169
- },
3170
- "sum": {
3171
- "description": "An array with the sum of all data collection values aggregated to each dimension.\nThis member exists only when option `raw` is given.\n",
3172
- "type": "array",
3173
- "items": {
3174
- "type": "number"
3175
- }
3176
- },
3177
- "cnt": {
3178
- "description": "An array with the count of the data collection values aggregated to each dimension.\nThis member exists only when option `raw` is given.\n",
3179
- "type": "array",
3180
- "items": {
3181
- "type": "number"
3182
- }
3183
- },
3184
- "ars": {
3185
- "description": "An array with the anomaly rate sum of all data collection values aggregated to each dimension.\nThis member exists only when option `raw` is given.\n",
3186
- "type": "array",
3187
- "items": {
3188
- "type": "number"
3189
- }
3190
- },
3191
- "avg": {
3192
- "description": "An array with the average of all data collection values aggregated to each dimension.\nThis member exists only when option `raw` is not given. When option `raw` is given, the average can be calculated by dividing `sum` with `cnt`.\n",
3193
- "type": "array",
3194
- "items": {
3195
- "type": "number"
3196
- }
3197
- },
3198
- "arp": {
3199
- "description": "An array with the average anomaly rate of all data collection values aggregated to each dimension.\nThis member exists only when option `raw` is not given. When option `raw` is given, the average can be calculated by dividing `ars` with `cnt`.\n",
3200
- "type": "array",
3201
- "items": {
3202
- "type": "number"
3203
- }
3204
- },
3205
- "con": {
3206
- "description": "An array with the contribution % of all data collection values aggregated to each dimension.\nThis member exists only when option `raw` is not given. When option `raw` is given, the contribution can be calculated by multiplying `ABS(sum)` with 100.0 and dividing it with the total of the ABS(sum) of all dimensions.\n",
3207
- "type": "array",
3208
- "items": {
3209
- "type": "number"
3210
- }
3182
+ {
3183
+ "$ref": "#/components/schemas/jsonwrap2_sts_raw"
3184
}
3212
- }
3185
+ ]
3186
},
3187
"labels": {
3188
"description": "The labels associated with each dimension in the query.\nThis object is only available when the `group-by-labels` option is given to the query.\n",
web/api/netdata-swagger.yaml
+36
-78
@@ -2192,6 +2192,35 @@ components:
2192
last_entry:
2193
description: |
2194
The maximum unix epoch timestamp available across all metrics that used this tier. This reflects the newest timestamp of the tier's retention.
2195
+ units:
2196
+ description: |
2197
+ The units of the database data
2198
+ oneOf:
2199
+ - type: string
2200
+ - type: array
2201
+ items:
2202
+ type: string
2203
+ dimensions:
2204
+ type: object
2205
+ properties:
2206
+ ids:
2207
+ description: |
2208
+ An array with the dimension ids that uniquely identify the dimensions for this query. It is the same with `view.dimensions.ids`.
2209
+ type: array
2210
+ items:
2211
+ type: string
2212
+ units:
2213
+ description: |
2214
+ An array with the units each dimension has in the database (independent of group-by aggregation that may override the units).
2215
+ type: array
2216
+ items:
2217
+ type: string
2218
+ sts:
2219
+ description: |
2220
+ Statistics about the data collection points used for each dimension.
2221
+ oneOf:
2222
+ - $ref: "#/components/schemas/jsonwrap2_sts"
2223
+ - $ref: "#/components/schemas/jsonwrap2_sts_raw"
2224
view:
2225
type: object
2226
properties:
@@ -2295,12 +2324,6 @@ components:
2324
type: array
2325
items:
2326
type: string
2298
- units:
2299
- description: |
2300
- An array with the units each dimension has.
2301
- type: array
2302
- items:
2303
- type: string
2327
priorities:
2328
description: |
2329
An array with the relative priorities of the dimensions.
@@ -2314,83 +2337,18 @@ components:
2337
type: array
2338
items:
2339
type: integer
2317
- min:
2318
- description: |
2319
- An array of the minimum value of each dimension across the entire query.
2320
- type: array
2321
- items:
2322
- type: number
2323
- max:
2324
- description: |
2325
- An array of the maximum value of each dimension across the entire query.
2326
- type: array
2327
- items:
2328
- type: number
2329
- avg:
2340
+ units:
2341
description: |
2331
- An array of the average value of each dimension across the entire query.
2342
+ An array with the units each dimension has.
2343
type: array
2344
items:
2334
- type: number
2345
+ type: string
2346
sts:
2347
description: |
2337
- Statistics about the data collection points used for each dimension.
2338
- type: object
2339
- properties:
2340
- min:
2341
- description: |
2342
- An array with the minimum data collection value aggregated to each dimension.
2343
- type: array
2344
- items:
2345
- type: number
2346
- max:
2347
- description: |
2348
- An array with the maximum data collection value aggregated to each dimension.
2349
- type: array
2350
- items:
2351
- type: number
2352
- sum:
2353
- description: |
2354
- An array with the sum of all data collection values aggregated to each dimension.
2355
- This member exists only when option `raw` is given.
2356
- type: array
2357
- items:
2358
- type: number
2359
- cnt:
2360
- description: |
2361
- An array with the count of the data collection values aggregated to each dimension.
2362
- This member exists only when option `raw` is given.
2363
- type: array
2364
- items:
2365
- type: number
2366
- ars:
2367
- description: |
2368
- An array with the anomaly rate sum of all data collection values aggregated to each dimension.
2369
- This member exists only when option `raw` is given.
2370
- type: array
2371
- items:
2372
- type: number
2373
- avg:
2374
- description: |
2375
- An array with the average of all data collection values aggregated to each dimension.
2376
- This member exists only when option `raw` is not given. When option `raw` is given, the average can be calculated by dividing `sum` with `cnt`.
2377
- type: array
2378
- items:
2379
- type: number
2380
- arp:
2381
- description: |
2382
- An array with the average anomaly rate of all data collection values aggregated to each dimension.
2383
- This member exists only when option `raw` is not given. When option `raw` is given, the average can be calculated by dividing `ars` with `cnt`.
2384
- type: array
2385
- items:
2386
- type: number
2387
- con:
2388
- description: |
2389
- An array with the contribution % of all data collection values aggregated to each dimension.
2390
- This member exists only when option `raw` is not given. When option `raw` is given, the contribution can be calculated by multiplying `ABS(sum)` with 100.0 and dividing it with the total of the ABS(sum) of all dimensions.
2391
- type: array
2392
- items:
2393
- type: number
2348
+ Statistics about the view points for each dimension.
2349
+ oneOf:
2350
+ - $ref: "#/components/schemas/jsonwrap2_sts"
2351
+ - $ref: "#/components/schemas/jsonwrap2_sts_raw"
2352
labels:
2353
description: |
2354
The labels associated with each dimension in the query.