summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorvkalintiris <vasilis@netdata.cloud>2023-03-10 12:20:40 +0200
committerGitHub <noreply@github.com>2023-03-10 12:20:40 +0200
commit37a06960f90c046f21c125c2b4265713da04f851 (patch)
tree54ed00a16dffb010a10242507cadb7140b28975b /web
parenta0652435f0dea126b6603a2467d912ca8a677e36 (diff)
Refactor ML code. (#14659)
* Refactor ML code. This commit introduces only non-functional changes. Originally, the C++ code exposed C functions to be called from the rest of the agent. When we migrated from C++ to C, we did not eliminate these wrapper functions to make the PR easier to understand and keep the total LOC low. This commit removes the wrapper functions and "reclaims" the `ml_` prefix that we used for the public API of the old implementation. Also, the nlohmann Json library has been removed and its functionality was replaced with the equivalent Json functionality that we added in libnetdata's BUFFERs. * Remove missing headers from build systems. * Fix CMake build. * rrddim_free is outside of rrd "internals" now.
Diffstat (limited to 'web')
-rw-r--r--web/api/web_api_v1.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c
index 3dbd41e274..06e9af9c83 100644
--- a/web/api/web_api_v1.c
+++ b/web/api/web_api_v1.c
@@ -1191,7 +1191,7 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb)
#if defined(ENABLE_ML)
buffer_json_member_add_object(wb, "ml-info");
- ml_get_host_info(host, wb);
+ ml_host_get_info(host, wb);
buffer_json_object_close(wb);
#endif
@@ -1206,17 +1206,16 @@ int web_client_api_request_v1_ml_info(RRDHOST *host, struct web_client *w, char
if (!netdata_ready)
return HTTP_RESP_BACKEND_FETCH_FAILED;
- char *s = ml_get_host_runtime_info(host);
- if (!s)
- s = strdupz("{\"error\": \"json string is empty\" }\n");
-
BUFFER *wb = w->response.data;
buffer_flush(wb);
wb->content_type = CT_APPLICATION_JSON;
- buffer_strcat(wb, s);
+
+ buffer_json_initialize(wb, "\"", "\"", 0, true, false);
+ ml_host_get_detection_info(host, wb);
+ buffer_json_finalize(wb);
+
buffer_no_cacheable(wb);
- freez(s);
return HTTP_RESP_OK;
}
@@ -1226,20 +1225,15 @@ int web_client_api_request_v1_ml_models(RRDHOST *host, struct web_client *w, cha
if (!netdata_ready)
return HTTP_RESP_BACKEND_FETCH_FAILED;
- char *s = ml_get_host_models(host);
- if (!s)
- s = strdupz("{\"error\": \"json string is empty\" }\n");
-
BUFFER *wb = w->response.data;
buffer_flush(wb);
wb->content_type = CT_APPLICATION_JSON;
- buffer_strcat(wb, s);
+ ml_host_get_models(host, wb);
buffer_no_cacheable(wb);
- freez(s);
return HTTP_RESP_OK;
}
-#endif
+#endif // ENABLE_ML
inline int web_client_api_request_v1_info(RRDHOST *host, struct web_client *w, char *url) {
(void)url;