Clean up host labels in API responses (#7616)
* Remove host labels from the Swagger specification * Remove host labels from the api responses
Vladimir Kobal committed
Jan 6, 2020 at 17:34 UTC
8cf58891941b7c4c4b1f35f6e9b6db770eb878ab
8 files changed
+9
-139
database/rrdvar.c
+1
-4
@@ -296,10 +296,7 @@ void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *buf) {
296
helper.counter = 0;
297
avl_traverse_lock(&st->rrdfamily->rrdvar_root_index, single_variable2json, (void *)&helper);
298
299
- buffer_sprintf(buf, "\n\t},\n\t\"host\": \"%s\",", host->hostname);
300
- buffer_strcat(buf, "\n\t\"labels\": {\n");
301
- host_labels2json(st->rrdhost, buf, 2);
302
- buffer_strcat(buf, "\t},\n\t\"host_variables\": {");
299
+ buffer_sprintf(buf, "\n\t},\n\t\"host\": \"%s\",\n\t\"host_variables\": {", host->hostname);
300
helper.counter = 0;
301
avl_traverse_lock(&host->rrdvar_root_index, single_variable2json, (void *)&helper);
302
health/health_json.c
+1
-5
@@ -304,12 +304,8 @@ void health_alarms2json(RRDHOST *host, BUFFER *wb, int all) {
304
// for(rt = host->templates; rt ; rt = rt->next)
305
// health_rrdcalctemplate2json_nolock(wb, rt);
306
307
- buffer_strcat(wb, "\n\t},");
307
+ buffer_strcat(wb, "\n\t}\n}\n");
308
rrdhost_unlock(host);
309
-
310
- buffer_strcat(wb, "\n\t\"labels\": {\n");
311
- host_labels2json(host, wb, 2);
312
- buffer_strcat(wb, "\t}\n}\n");
309
}
310
311
web/api/formatters/charts2json.c
+1
-6
@@ -56,6 +56,7 @@ void charts2json(RRDHOST *host, BUFFER *wb) {
56
",\n\t\"history\": %ld"
57
",\n\t\"memory_mode\": \"%s\""
58
",\n\t\"custom_info\": \"%s\""
59
+ ",\n\t\"charts\": {"
60
, host->hostname
61
, host->program_version
62
, get_release_channel()
@@ -67,12 +68,6 @@ void charts2json(RRDHOST *host, BUFFER *wb) {
68
, custom_dashboard_info_js_filename
69
);
70
70
- buffer_strcat(wb, ",\n\t\"labels\": {\n");
71
- host_labels2json(host, wb, 2);
72
- buffer_strcat(wb, "\t}");
73
-
74
- buffer_strcat(wb, ",\n\t\"charts\": {");
75
-
71
c = 0;
72
rrdhost_rdlock(host);
73
rrdset_foreach_read(st, host) {
web/api/formatters/json_wrapper.c
+4
-23
@@ -26,35 +26,16 @@ void rrdr_json_wrapper_begin(RRDR *r, BUFFER *wb, uint32_t format, RRDR_OPTIONS
26
" %sapi%s: 1,\n"
27
" %sid%s: %s%s%s,\n"
28
" %sname%s: %s%s%s,\n"
29
- , kq, kq
30
- , kq, kq, sq, r->st->id, sq
31
- , kq, kq, sq, r->st->name, sq);
32
-
33
- RRDHOST *host = r->st->rrdhost;
34
- buffer_sprintf(wb, " %slabels%s: {\n", kq, kq);
35
-
36
- int count = 0;
37
- netdata_rwlock_rdlock(&host->labels_rwlock);
38
- for (struct label *label = host->labels; label; label = label->next) {
39
- if(count > 0) buffer_strcat(wb, ",\n");
40
-
41
- char value[CONFIG_MAX_VALUE * 2 + 1];
42
- escape_json_string(value, label->value, CONFIG_MAX_VALUE * 2);
43
- buffer_sprintf(wb, " %s%s%s: %s%s%s", kq, label->key, kq, sq, value, sq);
44
-
45
- count++;
46
- }
47
- netdata_rwlock_unlock(&host->labels_rwlock);
48
-
49
- buffer_strcat(wb, "\n },\n");
50
-
51
- buffer_sprintf(wb, " %sview_update_every%s: %d,\n"
29
+ " %sview_update_every%s: %d,\n"
30
" %supdate_every%s: %d,\n"
31
" %sfirst_entry%s: %u,\n"
32
" %slast_entry%s: %u,\n"
33
" %sbefore%s: %u,\n"
34
" %safter%s: %u,\n"
35
" %sdimension_names%s: ["
36
+ , kq, kq
37
+ , kq, kq, sq, r->st->id, sq
38
+ , kq, kq, sq, r->st->name, sq
39
, kq, kq, r->update_every
40
, kq, kq, r->st->update_every
41
, kq, kq, (uint32_t)rrdset_first_entry_t(r->st)
web/api/formatters/rrdset2json.c
+1
-5
@@ -73,11 +73,7 @@ void rrdset2json(RRDSET *st, BUFFER *wb, size_t *dimensions_count, size_t *memor
73
if(dimensions_count) *dimensions_count += dimensions;
74
if(memory_used) *memory_used += memory;
75
76
- buffer_strcat(wb, "\n\t\t\t},\n\t\t\t\"labels\": {\n");
77
- host_labels2json(st->rrdhost, wb, 4);
78
- buffer_strcat(wb, "\t\t\t}");
79
-
80
- buffer_sprintf(wb, ",\n\t\t\t\"chart_variables\": ");
76
+ buffer_sprintf(wb, "\n\t\t\t},\n\t\t\t\"chart_variables\": ");
77
health_api_v1_chart_custom_variables2json(st, wb);
78
79
buffer_strcat(wb, ",\n\t\t\t\"green\": ");
web/api/netdata-swagger.json
-55
@@ -1079,17 +1079,6 @@
1079
"type": "number",
1080
"description": "The default update frequency of the netdata server. All charts have an update frequency equal or bigger than this."
1081
},
1082
- "labels": {
1083
- "type": "object",
1084
- "description": "List of host labels.",
1085
- "properties": {
1086
- "app": {
1087
- "type": "string",
1088
- "description": "Host label.",
1089
- "example": "netdata"
1090
- }
1091
- }
1092
- },
1082
"charts": {
1083
"type": "object",
1084
"description": "An object containing all the chart objects available at the netdata server. This is used as an indexed array. The key of each chart object is the id of the chart.",
@@ -1192,17 +1181,6 @@
1181
}
1182
}
1183
},
1195
- "labels": {
1196
- "type": "object",
1197
- "description": "List of host labels.",
1198
- "properties": {
1199
- "app": {
1200
- "type": "string",
1201
- "description": "Host label.",
1202
- "example": "netdata"
1203
- }
1204
- }
1205
- },
1184
"chart_variables": {
1185
"type": "object",
1186
"additionalProperties": {
@@ -1244,17 +1222,6 @@
1222
"type": "string",
1223
"description": "The host containing the chart."
1224
},
1247
- "labels": {
1248
- "type": "object",
1249
- "description": "List of host labels.",
1250
- "properties": {
1251
- "app": {
1252
- "type": "string",
1253
- "description": "Host label.",
1254
- "example": "netdata"
1255
- }
1256
- }
1257
- },
1225
"chart_variables": {
1226
"type": "object",
1227
"additionalProperties": {
@@ -1321,17 +1288,6 @@
1288
"type": "string",
1289
"description": "The name of the chart."
1290
},
1324
- "labels": {
1325
- "type": "object",
1326
- "description": "List of host labels.",
1327
- "properties": {
1328
- "app": {
1329
- "type": "string",
1330
- "description": "Host label.",
1331
- "example": "netdata"
1332
- }
1333
- }
1334
- },
1291
"update_every": {
1292
"type": "number",
1293
"description": "The update frequency of this chart, in seconds. One value every this amount of time is kept in the round robin database (indepedently of the current view)."
@@ -1739,17 +1695,6 @@
1695
}
1696
}
1697
}
1742
- },
1743
- "labels": {
1744
- "type": "object",
1745
- "description": "List of host labels.",
1746
- "properties": {
1747
- "app": {
1748
- "type": "string",
1749
- "description": "Host label.",
1750
- "example": "netdata"
1751
- }
1752
- }
1698
}
1699
}
1700
},
web/api/netdata-swagger.yaml
-40
@@ -878,14 +878,6 @@ components:
878
type: number
879
description: The default update frequency of the netdata server. All charts have
880
an update frequency equal or bigger than this.
881
- labels:
882
- type: object
883
- description: List of host labels.
884
- properties:
885
- app:
886
- type: string
887
- description: Host label.
888
- example: netdata
881
charts:
882
type: object
883
description: An object containing all the chart objects available at the netdata
@@ -979,14 +971,6 @@ components:
971
name:
972
type: string
973
description: The name of the dimension
982
- labels:
983
- type: object
984
- description: List of host labels.
985
- properties:
986
- app:
987
- type: string
988
- description: Host label.
989
- example: netdata
974
chart_variables:
975
type: object
976
additionalProperties:
@@ -1018,14 +1002,6 @@ components:
1002
host:
1003
type: string
1004
description: The host containing the chart.
1021
- labels:
1022
- type: object
1023
- description: List of host labels.
1024
- properties:
1025
- app:
1026
- type: string
1027
- description: Host label.
1028
- example: netdata
1005
chart_variables:
1006
type: object
1007
additionalProperties:
@@ -1073,14 +1049,6 @@ components:
1049
name:
1050
type: string
1051
description: The name of the chart.
1076
- labels:
1077
- type: object
1078
- description: List of host labels.
1079
- properties:
1080
- app:
1081
- type: string
1082
- description: Host label.
1083
- example: netdata
1052
update_every:
1053
type: number
1054
description: The update frequency of this chart, in seconds. One value every this
@@ -1373,14 +1341,6 @@ components:
1341
format: nullable
1342
value:
1343
type: number
1376
- labels:
1377
- type: object
1378
- description: List of host labels.
1379
- properties:
1380
- app:
1381
- type: string
1382
- description: Host label.
1383
- example: netdata
1344
alarm_log_entry:
1345
type: object
1346
properties:
web/api/web_api_v1.c
+1
-1
@@ -822,7 +822,7 @@ inline int web_client_api_request_v1_info(RRDHOST *host, struct web_client *w, c
822
buffer_sprintf(wb, "\t\"container\": \"%s\",\n", (host->system_info->container) ? host->system_info->container : "");
823
buffer_sprintf(wb, "\t\"container_detection\": \"%s\",\n", (host->system_info->container_detection) ? host->system_info->container_detection : "");
824
825
- buffer_strcat(wb, "\t\"labels\": {\n");
825
+ buffer_strcat(wb, "\t\"host_labels\": {\n");
826
host_labels2json(host, wb, 2);
827
buffer_strcat(wb, "\t},\n");
828