From 4955945e96ef19ef90a273fbb3c3d56972c15eaa Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Wed, 10 Sep 2025 13:26:13 -0400 Subject: [PATCH 01/24] refactor: Added first pass of logging improvements to query_router --- core/database/foxx/api/query_router.js | 240 +++++++++++++++++++++++-- 1 file changed, 227 insertions(+), 13 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index 3a3bedbfa..d359eb4b7 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -14,8 +14,9 @@ module.exports = router; router .post("/create", function (req, res) { + let client = undefined; + let result = undefined; try { - var result; g_db._executeTransaction({ collections: { @@ -23,7 +24,17 @@ router write: ["q", "owner"], }, action: function () { - const client = g_lib.getUserFromClientID(req.queryParams.client); + client = g_lib.getUserFromClientID(req.queryParams.client); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/create","|", + "Status:","Started","|", + "Desc:","Create query","|", + "Query:", result, + ); + // Check max number of saved queries if (client.max_sav_qry >= 0) { @@ -81,7 +92,27 @@ router }); res.send(result); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/create","|", + "Status:","Success","|", + "Desc:","Create query","|", + "Query:", result, + ); } catch (e) { + console.error( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/create","|", + "Status:","Failure","|", + "Desc:","Create query", "|", + "Query:", result, "|", + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace", + ); g_lib.handleException(e, res); } }) @@ -105,8 +136,9 @@ router router .post("/update", function (req, res) { + let client = undefined; + let result = undefined; try { - var result; g_db._executeTransaction({ collections: { @@ -114,7 +146,17 @@ router write: ["q", "owner"], }, action: function () { - const client = g_lib.getUserFromClientID(req.queryParams.client); + client = g_lib.getUserFromClientID(req.queryParams.client); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/update","|", + "Status:","Started","|", + "Desc:","Update a saved query", "|", + "Query:", result + ); + var qry = g_db.q.document(req.body.id); if (client._id != qry.owner && !client.is_admin) { @@ -160,7 +202,27 @@ router }); res.send(result); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/update","|", + "Status:","Success","|", + "Desc:","Update a saved query", "|", + "Query:", result, + ); } catch (e) { + console.error( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/update","|", + "Status:","Failure","|", + "Desc:","Update a saved query", "|", + "Query:", result, "|", + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace" + ); g_lib.handleException(e, res); } }) @@ -185,9 +247,20 @@ router router .get("/view", function (req, res) { + let client = undefined; + let qry = undefined; try { - const client = g_lib.getUserFromClientID(req.queryParams.client); - var qry = g_db.q.document(req.queryParams.id); + client = g_lib.getUserFromClientID(req.queryParams.client); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/view","|", + "Status:","Started","|", + "Desc:","View specified query", "|", + "Query:", qry, + ); + qry = g_db.q.document(req.queryParams.id); if (client._id != qry.owner && !client.is_admin) { throw g_lib.ERR_PERM_DENIED; @@ -204,7 +277,27 @@ router delete qry.lmit; res.send(qry); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/view","|", + "Status:","Success","|", + "Desc:","View specified query", "|", + "Query:", qry, + ); } catch (e) { + console.error( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/view","|", + "Status:","Failure","|", + "Desc:","View specified query", "|", + "Query:", qry, "|", + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace" + ); g_lib.handleException(e, res); } }) @@ -215,9 +308,18 @@ router router .get("/delete", function (req, res) { + let client = undefined; try { - const client = g_lib.getUserFromClientID(req.queryParams.client); + client = g_lib.getUserFromClientID(req.queryParams.client); var owner; + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/delete","|", + "Status:","Started","|", + "Desc:","Delete specified query" + ); for (var i in req.queryParams.ids) { if (!req.queryParams.ids[i].startsWith("q/")) { @@ -242,8 +344,27 @@ router } g_graph.q.remove(owner._from); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/delete","|", + "Status:","Success","|", + "Desc:","Delete specified query", "|", + "Query:",req.queryParams.ids[i], + ); } } catch (e) { + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/delete","|", + "Status:","Failure","|", + "Desc:","Delete specified query", + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace" + ); g_lib.handleException(e, res); } }) @@ -254,12 +375,22 @@ router router .get("/list", function (req, res) { + let client = undefined; + let result = undefined; try { - const client = g_lib.getUserFromClientID(req.queryParams.client); + client = g_lib.getUserFromClientID(req.queryParams.client); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/list","|", + "Status:","Started","|", + "Desc:","List client saved queries", "|", + "Query:", result, + ); var qry = "for v in 1..1 inbound @user owner filter is_same_collection('q',v) sort v.title"; - var result; if (req.queryParams.offset != undefined && req.queryParams.count != undefined) { qry += " limit " + req.queryParams.offset + ", " + req.queryParams.count; @@ -291,7 +422,27 @@ router } res.send(result); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/list","|", + "Status:","Success","|", + "Desc:","List client saved queries", "|", + "Query:", result, + ); } catch (e) { + console.error( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/list","|", + "Status:","Failure","|", + "Desc:","List client saved queries", "|", + "Query:", result, "|", + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace" + ); g_lib.handleException(e, res); } }) @@ -301,7 +452,7 @@ router .summary("List client saved queries") .description("List client saved queries"); -function execQuery(client, mode, published, orig_query) { +function execQuery(client, mode, published, orig_query) { var col_chk = true, ctxt = client._id; let query = { @@ -503,8 +654,20 @@ function execQuery(client, mode, published, orig_query) { router .get("/exec", function (req, res) { + let client = undefined; + let results = undefined; try { - const client = g_lib.getUserFromClientID(req.queryParams.client); + client = g_lib.getUserFromClientID(req.queryParams.client); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/exec","|", + "Status:","Started","|", + "Desc:","Execute specified queries", "|", + "Query Result:", results, + ); + var qry = g_db.q.document(req.queryParams.id); if (client._id != qry.owner && !client.is_admin) { @@ -516,10 +679,30 @@ router qry.params.cnt = req.queryParams.count; } - var results = execQuery(client, qry.query.mode, qry.query.published, qry); + results = execQuery(client, qry.query.mode, qry.query.published, qry); res.send(results); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/exec","|", + "Status:","Success","|", + "Desc:","Execute specified queries", "|", + "Query Result:", results, + ); } catch (e) { + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/exec","|", + "Status:","Failure","|", + "Desc:","Execute specified queries", "|", + "Query Result:", results, + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace" + ); g_lib.handleException(e, res); } }) @@ -532,17 +715,48 @@ router router .post("/exec/direct", function (req, res) { + let results = undefined; try { const client = g_lib.getUserFromClientID_noexcept(req.queryParams.client); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","POST","|", + "Route:","/exec/direct","|", + "Status:","Started","|", + "Desc:","Execute published data search query", "|", + "Query Result:", results, + ); const query = { ...req.body, params: JSON.parse(req.body.params), }; - var results = execQuery(client, req.body.mode, req.body.published, query); + results = execQuery(client, req.body.mode, req.body.published, query); res.send(results); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","POST","|", + "Route:","/exec","|", + "Status:","Started","|", + "Desc:","Execute data search query", "|", + "Query Result:", results, + ); + } catch (e) { + console.error( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","POST","|", + "Route:","/exec/direct","|", + "Status:","Failure","|", + "Desc:","Execute data search query", "|", + "Query Result:", results, + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace" + ); g_lib.handleException(e, res); } }) From afd43f011004c9832cf27bf81827bf1d4dec550a Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Wed, 10 Sep 2025 17:28:45 +0000 Subject: [PATCH 02/24] chore: Auto-format JavaScript files with Prettier --- core/database/foxx/api/query_router.js | 618 ++++++++++++++++++------- 1 file changed, 454 insertions(+), 164 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index d359eb4b7..b916705f9 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -17,7 +17,6 @@ router let client = undefined; let result = undefined; try { - g_db._executeTransaction({ collections: { read: ["u", "uuid", "accn", "admin"], @@ -26,16 +25,28 @@ router action: function () { client = g_lib.getUserFromClientID(req.queryParams.client); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/create","|", - "Status:","Started","|", - "Desc:","Create query","|", - "Query:", result, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/create", + "|", + "Status:", + "Started", + "|", + "Desc:", + "Create query", + "|", + "Query:", + result, ); - // Check max number of saved queries if (client.max_sav_qry >= 0) { var count = g_db @@ -93,25 +104,55 @@ router res.send(result); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/create","|", - "Status:","Success","|", - "Desc:","Create query","|", - "Query:", result, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/create", + "|", + "Status:", + "Success", + "|", + "Desc:", + "Create query", + "|", + "Query:", + result, ); } catch (e) { console.error( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/create","|", - "Status:","Failure","|", - "Desc:","Create query", "|", - "Query:", result, "|", - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace", + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/create", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "Create query", + "|", + "Query:", + result, + "|", + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } @@ -139,7 +180,6 @@ router let client = undefined; let result = undefined; try { - g_db._executeTransaction({ collections: { read: ["u", "uuid", "accn", "admin"], @@ -148,13 +188,26 @@ router action: function () { client = g_lib.getUserFromClientID(req.queryParams.client); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/update","|", - "Status:","Started","|", - "Desc:","Update a saved query", "|", - "Query:", result + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/update", + "|", + "Status:", + "Started", + "|", + "Desc:", + "Update a saved query", + "|", + "Query:", + result, ); var qry = g_db.q.document(req.body.id); @@ -203,25 +256,55 @@ router res.send(result); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/update","|", - "Status:","Success","|", - "Desc:","Update a saved query", "|", - "Query:", result, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/update", + "|", + "Status:", + "Success", + "|", + "Desc:", + "Update a saved query", + "|", + "Query:", + result, ); } catch (e) { console.error( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/update","|", - "Status:","Failure","|", - "Desc:","Update a saved query", "|", - "Query:", result, "|", - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/update", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "Update a saved query", + "|", + "Query:", + result, + "|", + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } @@ -252,13 +335,26 @@ router try { client = g_lib.getUserFromClientID(req.queryParams.client); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/view","|", - "Status:","Started","|", - "Desc:","View specified query", "|", - "Query:", qry, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/view", + "|", + "Status:", + "Started", + "|", + "Desc:", + "View specified query", + "|", + "Query:", + qry, ); qry = g_db.q.document(req.queryParams.id); @@ -278,25 +374,55 @@ router res.send(qry); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/view","|", - "Status:","Success","|", - "Desc:","View specified query", "|", - "Query:", qry, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/view", + "|", + "Status:", + "Success", + "|", + "Desc:", + "View specified query", + "|", + "Query:", + qry, ); } catch (e) { console.error( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/view","|", - "Status:","Failure","|", - "Desc:","View specified query", "|", - "Query:", qry, "|", - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/view", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "View specified query", + "|", + "Query:", + qry, + "|", + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } @@ -313,12 +439,23 @@ router client = g_lib.getUserFromClientID(req.queryParams.client); var owner; console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/delete","|", - "Status:","Started","|", - "Desc:","Delete specified query" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/delete", + "|", + "Status:", + "Started", + "|", + "Desc:", + "Delete specified query", ); for (var i in req.queryParams.ids) { @@ -345,25 +482,52 @@ router g_graph.q.remove(owner._from); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/delete","|", - "Status:","Success","|", - "Desc:","Delete specified query", "|", - "Query:",req.queryParams.ids[i], + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/delete", + "|", + "Status:", + "Success", + "|", + "Desc:", + "Delete specified query", + "|", + "Query:", + req.queryParams.ids[i], ); } } catch (e) { console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/delete","|", - "Status:","Failure","|", - "Desc:","Delete specified query", - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/delete", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "Delete specified query", + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } @@ -380,13 +544,26 @@ router try { client = g_lib.getUserFromClientID(req.queryParams.client); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/list","|", - "Status:","Started","|", - "Desc:","List client saved queries", "|", - "Query:", result, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/list", + "|", + "Status:", + "Started", + "|", + "Desc:", + "List client saved queries", + "|", + "Query:", + result, ); var qry = @@ -423,25 +600,55 @@ router res.send(result); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/list","|", - "Status:","Success","|", - "Desc:","List client saved queries", "|", - "Query:", result, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/list", + "|", + "Status:", + "Success", + "|", + "Desc:", + "List client saved queries", + "|", + "Query:", + result, ); } catch (e) { console.error( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/list","|", - "Status:","Failure","|", - "Desc:","List client saved queries", "|", - "Query:", result, "|", - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/list", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "List client saved queries", + "|", + "Query:", + result, + "|", + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } @@ -452,7 +659,7 @@ router .summary("List client saved queries") .description("List client saved queries"); -function execQuery(client, mode, published, orig_query) { +function execQuery(client, mode, published, orig_query) { var col_chk = true, ctxt = client._id; let query = { @@ -659,13 +866,26 @@ router try { client = g_lib.getUserFromClientID(req.queryParams.client); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/exec","|", - "Status:","Started","|", - "Desc:","Execute specified queries", "|", - "Query Result:", results, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/exec", + "|", + "Status:", + "Started", + "|", + "Desc:", + "Execute specified queries", + "|", + "Query Result:", + results, ); var qry = g_db.q.document(req.queryParams.id); @@ -683,25 +903,54 @@ router res.send(results); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/exec","|", - "Status:","Success","|", - "Desc:","Execute specified queries", "|", - "Query Result:", results, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/exec", + "|", + "Status:", + "Success", + "|", + "Desc:", + "Execute specified queries", + "|", + "Query Result:", + results, ); } catch (e) { console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/exec","|", - "Status:","Failure","|", - "Desc:","Execute specified queries", "|", - "Query Result:", results, - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/exec", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "Execute specified queries", + "|", + "Query Result:", + results, + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } @@ -719,13 +968,26 @@ router try { const client = g_lib.getUserFromClientID_noexcept(req.queryParams.client); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","POST","|", - "Route:","/exec/direct","|", - "Status:","Started","|", - "Desc:","Execute published data search query", "|", - "Query Result:", results, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "POST", + "|", + "Route:", + "/exec/direct", + "|", + "Status:", + "Started", + "|", + "Desc:", + "Execute published data search query", + "|", + "Query Result:", + results, ); const query = { @@ -736,26 +998,54 @@ router res.send(results); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","POST","|", - "Route:","/exec","|", - "Status:","Started","|", - "Desc:","Execute data search query", "|", - "Query Result:", results, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "POST", + "|", + "Route:", + "/exec", + "|", + "Status:", + "Started", + "|", + "Desc:", + "Execute data search query", + "|", + "Query Result:", + results, ); - } catch (e) { console.error( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","POST","|", - "Route:","/exec/direct","|", - "Status:","Failure","|", - "Desc:","Execute data search query", "|", - "Query Result:", results, - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "POST", + "|", + "Route:", + "/exec/direct", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "Execute data search query", + "|", + "Query Result:", + results, + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } From e51df524b7a8f18a60ce35f1549c7583089b495e Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Wed, 10 Sep 2025 14:50:04 -0400 Subject: [PATCH 03/24] style: last minute fixes to incorrect logs --- core/database/foxx/api/query_router.js | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index b916705f9..43588243b 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -32,7 +32,7 @@ router req.headers["x-correlation-id"], "|", "HTTP:", - "GET", + "POST", "|", "Route:", "/create", @@ -42,9 +42,6 @@ router "|", "Desc:", "Create query", - "|", - "Query:", - result, ); // Check max number of saved queries @@ -195,7 +192,7 @@ router req.headers["x-correlation-id"], "|", "HTTP:", - "GET", + "POST", "|", "Route:", "/update", @@ -205,9 +202,6 @@ router "|", "Desc:", "Update a saved query", - "|", - "Query:", - result, ); var qry = g_db.q.document(req.body.id); @@ -352,9 +346,6 @@ router "|", "Desc:", "View specified query", - "|", - "Query:", - qry, ); qry = g_db.q.document(req.queryParams.id); @@ -561,9 +552,6 @@ router "|", "Desc:", "List client saved queries", - "|", - "Query:", - result, ); var qry = @@ -883,9 +871,6 @@ router "|", "Desc:", "Execute specified queries", - "|", - "Query Result:", - results, ); var qry = g_db.q.document(req.queryParams.id); @@ -985,9 +970,6 @@ router "|", "Desc:", "Execute published data search query", - "|", - "Query Result:", - results, ); const query = { From 591ac26b230ddcf3f5406d5318745d6da7fd45c4 Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Wed, 10 Sep 2025 15:14:16 -0400 Subject: [PATCH 04/24] style:more final changes --- core/database/foxx/api/query_router.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index 43588243b..f7ac2d53a 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -108,7 +108,7 @@ router req.headers["x-correlation-id"], "|", "HTTP:", - "GET", + "POST", "|", "Route:", "/create", @@ -131,7 +131,7 @@ router req.headers["x-correlation-id"], "|", "HTTP:", - "GET", + "POST", "|", "Route:", "/create", @@ -257,7 +257,7 @@ router req.headers["x-correlation-id"], "|", "HTTP:", - "GET", + "POST", "|", "Route:", "/update", @@ -280,7 +280,7 @@ router req.headers["x-correlation-id"], "|", "HTTP:", - "GET", + "POST", "|", "Route:", "/update", From 6b82648692565832c0092bedf4bc16f04a7c245c Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Thu, 18 Sep 2025 12:46:16 -0400 Subject: [PATCH 05/24] refactor: Added second pass of logging to query_router.js --- core/database/foxx/api/query_router.js | 688 ++++++++----------------- 1 file changed, 207 insertions(+), 481 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index f7ac2d53a..020b007e3 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -7,6 +7,8 @@ const joi = require("joi"); const g_db = require("@arangodb").db; const g_graph = require("@arangodb/general-graph")._graph("sdmsg"); const g_lib = require("./support"); +const logger = require("./lib/logger"); +const basePath = "qry"; module.exports = router; @@ -24,26 +26,15 @@ router }, action: function () { client = g_lib.getUserFromClientID(req.queryParams.client); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/create", - "|", - "Status:", - "Started", - "|", - "Desc:", - "Create query", - ); - + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/create", + status: "Started", + description: "Create Query", + }); + // Check max number of saved queries if (client.max_sav_qry >= 0) { var count = g_db @@ -100,57 +91,28 @@ router }); res.send(result); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/create", - "|", - "Status:", - "Success", - "|", - "Desc:", - "Create query", - "|", - "Query:", - result, - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/create", + status: "Success", + description: "Create Query", + extra: result + }); } catch (e) { - console.error( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/create", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "Create query", - "|", - "Query:", - result, - "|", - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); + logger.logRequestFailure({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/create", + status: "Failure", + description: "Create Query", + extra: result, + message: e.message, + stack: e.stack + }); + g_lib.handleException(e, res); } }) @@ -184,25 +146,14 @@ router }, action: function () { client = g_lib.getUserFromClientID(req.queryParams.client); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/update", - "|", - "Status:", - "Started", - "|", - "Desc:", - "Update a saved query", - ); + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/update", + status: "Started", + description: "Update a saved query", + }); var qry = g_db.q.document(req.body.id); @@ -247,59 +198,28 @@ router result = qry; }, }); - res.send(result); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/update", - "|", - "Status:", - "Success", - "|", - "Desc:", - "Update a saved query", - "|", - "Query:", - result, - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/update", + status: "Success", + description: "Update a saved query", + extra: result + }); } catch (e) { - console.error( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/update", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "Update a saved query", - "|", - "Query:", - result, - "|", - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); + logger.logRequestFailure({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/update", + status: "Failure", + description: "Update a saved query", + extra: result, + message: e.message, + stack: e.stack + }); g_lib.handleException(e, res); } }) @@ -328,25 +248,14 @@ router let qry = undefined; try { client = g_lib.getUserFromClientID(req.queryParams.client); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/view", - "|", - "Status:", - "Started", - "|", - "Desc:", - "View specified query", - ); + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/view", + status: "Started", + description: "View specified query", + }); qry = g_db.q.document(req.queryParams.id); if (client._id != qry.owner && !client.is_admin) { @@ -364,57 +273,28 @@ router delete qry.lmit; res.send(qry); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/view", - "|", - "Status:", - "Success", - "|", - "Desc:", - "View specified query", - "|", - "Query:", - qry, - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/view", + status: "Success", + description: "View specified query", + extra: qry + }); } catch (e) { - console.error( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/view", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "View specified query", - "|", - "Query:", - qry, - "|", - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); + logger.logRequestFailure({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/view", + status: "Failure", + description: "View specified query", + extra: qry, + message: e.message, + stack: e.stack + }); + g_lib.handleException(e, res); } }) @@ -429,25 +309,14 @@ router try { client = g_lib.getUserFromClientID(req.queryParams.client); var owner; - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/delete", - "|", - "Status:", - "Started", - "|", - "Desc:", - "Delete specified query", - ); + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/delete", + status: "Started", + description: "Delete specified query", + }); for (var i in req.queryParams.ids) { if (!req.queryParams.ids[i].startsWith("q/")) { @@ -472,54 +341,29 @@ router } g_graph.q.remove(owner._from); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/delete", - "|", - "Status:", - "Success", - "|", - "Desc:", - "Delete specified query", - "|", - "Query:", - req.queryParams.ids[i], - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/delete", + status: "Success", + description: "Delete specified query", + extra: req.queryParams.ids[i] + }); } } catch (e) { - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/delete", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "Delete specified query", - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/delete", + status: "Failure", + description: "Delete specified query", + extra: req.queryParams.ids[i], + message: e.message, + stack: e.stack + }); + g_lib.handleException(e, res); } }) @@ -534,25 +378,14 @@ router let result = undefined; try { client = g_lib.getUserFromClientID(req.queryParams.client); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/list", - "|", - "Status:", - "Started", - "|", - "Desc:", - "List client saved queries", - ); + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/list", + status: "Started", + description: "List client saved queries", + }); var qry = "for v in 1..1 inbound @user owner filter is_same_collection('q',v) sort v.title"; @@ -587,58 +420,28 @@ router } res.send(result); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/list", - "|", - "Status:", - "Success", - "|", - "Desc:", - "List client saved queries", - "|", - "Query:", - result, - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/list", + status: "Success", + description: "List client saved queries", + extra: result + }); } catch (e) { - console.error( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/list", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "List client saved queries", - "|", - "Query:", - result, - "|", - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); - g_lib.handleException(e, res); + logger.logRequestFailure({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/list", + status: "Failure", + description: "List client saved queries", + extra: result, + message: e.message, + stack: e.stack + }); + g_lib.handleException(e, res); } }) .queryParam("client", joi.string().required(), "Client ID") @@ -853,25 +656,14 @@ router let results = undefined; try { client = g_lib.getUserFromClientID(req.queryParams.client); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/exec", - "|", - "Status:", - "Started", - "|", - "Desc:", - "Execute specified queries", - ); + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/exec", + status: "Started", + description: "Execute specified queries", + }); var qry = g_db.q.document(req.queryParams.id); @@ -887,56 +679,28 @@ router results = execQuery(client, qry.query.mode, qry.query.published, qry); res.send(results); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/exec", - "|", - "Status:", - "Success", - "|", - "Desc:", - "Execute specified queries", - "|", - "Query Result:", - results, - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/exec", + status: "Success", + description: "Execute specified queries", + extra: results + }); + } catch (e) { - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/exec", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "Execute specified queries", - "|", - "Query Result:", - results, - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); + logger.logRequestFailure({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/exec", + status: "Failure", + description: "Execute specified queries", + extra: results, + message: e.message, + stack: e.stack + }); g_lib.handleException(e, res); } }) @@ -950,27 +714,17 @@ router router .post("/exec/direct", function (req, res) { let results = undefined; + let client = undefined; try { - const client = g_lib.getUserFromClientID_noexcept(req.queryParams.client); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/exec/direct", - "|", - "Status:", - "Started", - "|", - "Desc:", - "Execute published data search query", - ); + client = g_lib.getUserFromClientID_noexcept(req.queryParams.client); + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/exec/direct", + status: "Started", + description: "Execute published data search query", + }); const query = { ...req.body, @@ -979,56 +733,28 @@ router results = execQuery(client, req.body.mode, req.body.published, query); res.send(results); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/exec", - "|", - "Status:", - "Started", - "|", - "Desc:", - "Execute data search query", - "|", - "Query Result:", - results, - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/exec/direct", + status: "Success", + description: "Execute published data search query", + extra: results + }); + } catch (e) { - console.error( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/exec/direct", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "Execute data search query", - "|", - "Query Result:", - results, - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); + logger.logRequestFailure({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/exec/direct", + status: "Success", + description: "Execute published data search query", + extra: results, + message: e.message, + stack: e.stack + }); g_lib.handleException(e, res); } }) From 6d51811fe9c71227b6fb68611d9d5c32811920f2 Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Thu, 18 Sep 2025 16:54:54 +0000 Subject: [PATCH 06/24] chore: Auto-format JavaScript files with Prettier --- core/database/foxx/api/query_router.js | 36 ++++++++++++-------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index 020b007e3..b30985811 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -34,7 +34,7 @@ router status: "Started", description: "Create Query", }); - + // Check max number of saved queries if (client.max_sav_qry >= 0) { var count = g_db @@ -98,7 +98,7 @@ router routePath: basePath + "/create", status: "Success", description: "Create Query", - extra: result + extra: result, }); } catch (e) { logger.logRequestFailure({ @@ -110,9 +110,9 @@ router description: "Create Query", extra: result, message: e.message, - stack: e.stack + stack: e.stack, }); - + g_lib.handleException(e, res); } }) @@ -206,7 +206,7 @@ router routePath: basePath + "/update", status: "Success", description: "Update a saved query", - extra: result + extra: result, }); } catch (e) { logger.logRequestFailure({ @@ -218,7 +218,7 @@ router description: "Update a saved query", extra: result, message: e.message, - stack: e.stack + stack: e.stack, }); g_lib.handleException(e, res); } @@ -280,7 +280,7 @@ router routePath: basePath + "/view", status: "Success", description: "View specified query", - extra: qry + extra: qry, }); } catch (e) { logger.logRequestFailure({ @@ -292,7 +292,7 @@ router description: "View specified query", extra: qry, message: e.message, - stack: e.stack + stack: e.stack, }); g_lib.handleException(e, res); @@ -348,7 +348,7 @@ router routePath: basePath + "/delete", status: "Success", description: "Delete specified query", - extra: req.queryParams.ids[i] + extra: req.queryParams.ids[i], }); } } catch (e) { @@ -361,7 +361,7 @@ router description: "Delete specified query", extra: req.queryParams.ids[i], message: e.message, - stack: e.stack + stack: e.stack, }); g_lib.handleException(e, res); @@ -427,7 +427,7 @@ router routePath: basePath + "/list", status: "Success", description: "List client saved queries", - extra: result + extra: result, }); } catch (e) { logger.logRequestFailure({ @@ -439,9 +439,9 @@ router description: "List client saved queries", extra: result, message: e.message, - stack: e.stack + stack: e.stack, }); - g_lib.handleException(e, res); + g_lib.handleException(e, res); } }) .queryParam("client", joi.string().required(), "Client ID") @@ -686,9 +686,8 @@ router routePath: basePath + "/exec", status: "Success", description: "Execute specified queries", - extra: results + extra: results, }); - } catch (e) { logger.logRequestFailure({ client: client?._id, @@ -699,7 +698,7 @@ router description: "Execute specified queries", extra: results, message: e.message, - stack: e.stack + stack: e.stack, }); g_lib.handleException(e, res); } @@ -740,9 +739,8 @@ router routePath: basePath + "/exec/direct", status: "Success", description: "Execute published data search query", - extra: results + extra: results, }); - } catch (e) { logger.logRequestFailure({ client: client?._id, @@ -753,7 +751,7 @@ router description: "Execute published data search query", extra: results, message: e.message, - stack: e.stack + stack: e.stack, }); g_lib.handleException(e, res); } From 4dea84611d3504e29eccd8fd10dbdbc1ed3650cb Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Mon, 22 Sep 2025 10:20:06 -0400 Subject: [PATCH 07/24] Added logger.js --- core/database/foxx/api/lib/logger.js | 93 ++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 core/database/foxx/api/lib/logger.js diff --git a/core/database/foxx/api/lib/logger.js b/core/database/foxx/api/lib/logger.js new file mode 100644 index 000000000..368c5b8f5 --- /dev/null +++ b/core/database/foxx/api/lib/logger.js @@ -0,0 +1,93 @@ +"use strict"; + +function logRequestSuccess({ + client, + correlationId, + httpVerb, + routePath, + status, + description, + extra, +}) { + // helper to pad fields + const pad = (label, value, length = 20) => + `${label}: ${value || "unknown"}`.padEnd(length, " "); + + console.info( + pad("Client", client) + + " | " + + pad("Correlation_ID", correlationId) + + " | " + + pad("HTTP", httpVerb) + + " | " + + pad("Route", routePath) + + " | " + + pad("Status", status) + + " | " + + pad("Desc", description) + + "|" + + pad("Extra", typeof extra === "object" ? JSON.stringify(extra) : extra), + ); +} + +function logRequestFailure({ + client, + correlationId, + httpVerb, + routePath, + status, + description, + extra, + message, + stack, +}) { + // helper to pad fields + const pad = (label, value, length = 20) => + `${label}: ${value || "unknown"}`.padEnd(length, " "); + console.error( + pad("Client", client) + + " | " + + pad("Correlation_ID", correlationId) + + " | " + + pad("HTTP", httpVerb) + + " | " + + pad("Route", routePath) + + " | " + + pad("Status", status) + + " | " + + pad("Desc", description) + + "|" + + pad("Extra", typeof extra === "object" ? JSON.stringify(extra) : extra) + + "|" + + pad("Err", message) + + "|" + + pad("Stack", stack), + ); +} + +function logRequestStarted({ client, correlationId, httpVerb, routePath, status, description }) { + // helper to pad fields + const pad = (label, value, length = 20) => + `${label}: ${value || "unknown"}`.padEnd(length, " "); + + console.info( + pad("Client", client) + + " | " + + pad("Correlation_ID", correlationId) + + " | " + + pad("HTTP", httpVerb) + + " | " + + pad("Route", routePath) + + " | " + + pad("Status", status) + + " | " + + pad("Desc", description), + ); +} + +// Export the functions +module.exports = { + logRequestSuccess, + logRequestFailure, + logRequestStarted, +}; From 66ec13ffc6e4cda51e75b15a73b4b94a61c1ceb7 Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Wed, 10 Sep 2025 13:26:13 -0400 Subject: [PATCH 08/24] refactor: Added first pass of logging improvements to query_router --- core/database/foxx/api/query_router.js | 240 +++++++++++++++++++++++-- 1 file changed, 227 insertions(+), 13 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index 3a3bedbfa..d359eb4b7 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -14,8 +14,9 @@ module.exports = router; router .post("/create", function (req, res) { + let client = undefined; + let result = undefined; try { - var result; g_db._executeTransaction({ collections: { @@ -23,7 +24,17 @@ router write: ["q", "owner"], }, action: function () { - const client = g_lib.getUserFromClientID(req.queryParams.client); + client = g_lib.getUserFromClientID(req.queryParams.client); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/create","|", + "Status:","Started","|", + "Desc:","Create query","|", + "Query:", result, + ); + // Check max number of saved queries if (client.max_sav_qry >= 0) { @@ -81,7 +92,27 @@ router }); res.send(result); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/create","|", + "Status:","Success","|", + "Desc:","Create query","|", + "Query:", result, + ); } catch (e) { + console.error( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/create","|", + "Status:","Failure","|", + "Desc:","Create query", "|", + "Query:", result, "|", + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace", + ); g_lib.handleException(e, res); } }) @@ -105,8 +136,9 @@ router router .post("/update", function (req, res) { + let client = undefined; + let result = undefined; try { - var result; g_db._executeTransaction({ collections: { @@ -114,7 +146,17 @@ router write: ["q", "owner"], }, action: function () { - const client = g_lib.getUserFromClientID(req.queryParams.client); + client = g_lib.getUserFromClientID(req.queryParams.client); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/update","|", + "Status:","Started","|", + "Desc:","Update a saved query", "|", + "Query:", result + ); + var qry = g_db.q.document(req.body.id); if (client._id != qry.owner && !client.is_admin) { @@ -160,7 +202,27 @@ router }); res.send(result); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/update","|", + "Status:","Success","|", + "Desc:","Update a saved query", "|", + "Query:", result, + ); } catch (e) { + console.error( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/update","|", + "Status:","Failure","|", + "Desc:","Update a saved query", "|", + "Query:", result, "|", + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace" + ); g_lib.handleException(e, res); } }) @@ -185,9 +247,20 @@ router router .get("/view", function (req, res) { + let client = undefined; + let qry = undefined; try { - const client = g_lib.getUserFromClientID(req.queryParams.client); - var qry = g_db.q.document(req.queryParams.id); + client = g_lib.getUserFromClientID(req.queryParams.client); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/view","|", + "Status:","Started","|", + "Desc:","View specified query", "|", + "Query:", qry, + ); + qry = g_db.q.document(req.queryParams.id); if (client._id != qry.owner && !client.is_admin) { throw g_lib.ERR_PERM_DENIED; @@ -204,7 +277,27 @@ router delete qry.lmit; res.send(qry); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/view","|", + "Status:","Success","|", + "Desc:","View specified query", "|", + "Query:", qry, + ); } catch (e) { + console.error( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/view","|", + "Status:","Failure","|", + "Desc:","View specified query", "|", + "Query:", qry, "|", + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace" + ); g_lib.handleException(e, res); } }) @@ -215,9 +308,18 @@ router router .get("/delete", function (req, res) { + let client = undefined; try { - const client = g_lib.getUserFromClientID(req.queryParams.client); + client = g_lib.getUserFromClientID(req.queryParams.client); var owner; + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/delete","|", + "Status:","Started","|", + "Desc:","Delete specified query" + ); for (var i in req.queryParams.ids) { if (!req.queryParams.ids[i].startsWith("q/")) { @@ -242,8 +344,27 @@ router } g_graph.q.remove(owner._from); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/delete","|", + "Status:","Success","|", + "Desc:","Delete specified query", "|", + "Query:",req.queryParams.ids[i], + ); } } catch (e) { + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/delete","|", + "Status:","Failure","|", + "Desc:","Delete specified query", + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace" + ); g_lib.handleException(e, res); } }) @@ -254,12 +375,22 @@ router router .get("/list", function (req, res) { + let client = undefined; + let result = undefined; try { - const client = g_lib.getUserFromClientID(req.queryParams.client); + client = g_lib.getUserFromClientID(req.queryParams.client); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/list","|", + "Status:","Started","|", + "Desc:","List client saved queries", "|", + "Query:", result, + ); var qry = "for v in 1..1 inbound @user owner filter is_same_collection('q',v) sort v.title"; - var result; if (req.queryParams.offset != undefined && req.queryParams.count != undefined) { qry += " limit " + req.queryParams.offset + ", " + req.queryParams.count; @@ -291,7 +422,27 @@ router } res.send(result); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/list","|", + "Status:","Success","|", + "Desc:","List client saved queries", "|", + "Query:", result, + ); } catch (e) { + console.error( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/list","|", + "Status:","Failure","|", + "Desc:","List client saved queries", "|", + "Query:", result, "|", + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace" + ); g_lib.handleException(e, res); } }) @@ -301,7 +452,7 @@ router .summary("List client saved queries") .description("List client saved queries"); -function execQuery(client, mode, published, orig_query) { +function execQuery(client, mode, published, orig_query) { var col_chk = true, ctxt = client._id; let query = { @@ -503,8 +654,20 @@ function execQuery(client, mode, published, orig_query) { router .get("/exec", function (req, res) { + let client = undefined; + let results = undefined; try { - const client = g_lib.getUserFromClientID(req.queryParams.client); + client = g_lib.getUserFromClientID(req.queryParams.client); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/exec","|", + "Status:","Started","|", + "Desc:","Execute specified queries", "|", + "Query Result:", results, + ); + var qry = g_db.q.document(req.queryParams.id); if (client._id != qry.owner && !client.is_admin) { @@ -516,10 +679,30 @@ router qry.params.cnt = req.queryParams.count; } - var results = execQuery(client, qry.query.mode, qry.query.published, qry); + results = execQuery(client, qry.query.mode, qry.query.published, qry); res.send(results); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/exec","|", + "Status:","Success","|", + "Desc:","Execute specified queries", "|", + "Query Result:", results, + ); } catch (e) { + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","GET","|", + "Route:","/exec","|", + "Status:","Failure","|", + "Desc:","Execute specified queries", "|", + "Query Result:", results, + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace" + ); g_lib.handleException(e, res); } }) @@ -532,17 +715,48 @@ router router .post("/exec/direct", function (req, res) { + let results = undefined; try { const client = g_lib.getUserFromClientID_noexcept(req.queryParams.client); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","POST","|", + "Route:","/exec/direct","|", + "Status:","Started","|", + "Desc:","Execute published data search query", "|", + "Query Result:", results, + ); const query = { ...req.body, params: JSON.parse(req.body.params), }; - var results = execQuery(client, req.body.mode, req.body.published, query); + results = execQuery(client, req.body.mode, req.body.published, query); res.send(results); + console.info( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","POST","|", + "Route:","/exec","|", + "Status:","Started","|", + "Desc:","Execute data search query", "|", + "Query Result:", results, + ); + } catch (e) { + console.error( + "Client:", client?._id || "unknown","|", + "Correlation_ID:", req.headers['x-correlation-id'],"|", + "HTTP:","POST","|", + "Route:","/exec/direct","|", + "Status:","Failure","|", + "Desc:","Execute data search query", "|", + "Query Result:", results, + "Err:", e.message || e, "|", + "Stack:", e.stack || "No Stack Trace" + ); g_lib.handleException(e, res); } }) From 07decbfe60c1ecb88fa8e2357f18e3bc476db972 Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Wed, 10 Sep 2025 17:28:45 +0000 Subject: [PATCH 09/24] chore: Auto-format JavaScript files with Prettier --- core/database/foxx/api/query_router.js | 618 ++++++++++++++++++------- 1 file changed, 454 insertions(+), 164 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index d359eb4b7..b916705f9 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -17,7 +17,6 @@ router let client = undefined; let result = undefined; try { - g_db._executeTransaction({ collections: { read: ["u", "uuid", "accn", "admin"], @@ -26,16 +25,28 @@ router action: function () { client = g_lib.getUserFromClientID(req.queryParams.client); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/create","|", - "Status:","Started","|", - "Desc:","Create query","|", - "Query:", result, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/create", + "|", + "Status:", + "Started", + "|", + "Desc:", + "Create query", + "|", + "Query:", + result, ); - // Check max number of saved queries if (client.max_sav_qry >= 0) { var count = g_db @@ -93,25 +104,55 @@ router res.send(result); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/create","|", - "Status:","Success","|", - "Desc:","Create query","|", - "Query:", result, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/create", + "|", + "Status:", + "Success", + "|", + "Desc:", + "Create query", + "|", + "Query:", + result, ); } catch (e) { console.error( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/create","|", - "Status:","Failure","|", - "Desc:","Create query", "|", - "Query:", result, "|", - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace", + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/create", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "Create query", + "|", + "Query:", + result, + "|", + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } @@ -139,7 +180,6 @@ router let client = undefined; let result = undefined; try { - g_db._executeTransaction({ collections: { read: ["u", "uuid", "accn", "admin"], @@ -148,13 +188,26 @@ router action: function () { client = g_lib.getUserFromClientID(req.queryParams.client); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/update","|", - "Status:","Started","|", - "Desc:","Update a saved query", "|", - "Query:", result + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/update", + "|", + "Status:", + "Started", + "|", + "Desc:", + "Update a saved query", + "|", + "Query:", + result, ); var qry = g_db.q.document(req.body.id); @@ -203,25 +256,55 @@ router res.send(result); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/update","|", - "Status:","Success","|", - "Desc:","Update a saved query", "|", - "Query:", result, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/update", + "|", + "Status:", + "Success", + "|", + "Desc:", + "Update a saved query", + "|", + "Query:", + result, ); } catch (e) { console.error( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/update","|", - "Status:","Failure","|", - "Desc:","Update a saved query", "|", - "Query:", result, "|", - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/update", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "Update a saved query", + "|", + "Query:", + result, + "|", + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } @@ -252,13 +335,26 @@ router try { client = g_lib.getUserFromClientID(req.queryParams.client); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/view","|", - "Status:","Started","|", - "Desc:","View specified query", "|", - "Query:", qry, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/view", + "|", + "Status:", + "Started", + "|", + "Desc:", + "View specified query", + "|", + "Query:", + qry, ); qry = g_db.q.document(req.queryParams.id); @@ -278,25 +374,55 @@ router res.send(qry); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/view","|", - "Status:","Success","|", - "Desc:","View specified query", "|", - "Query:", qry, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/view", + "|", + "Status:", + "Success", + "|", + "Desc:", + "View specified query", + "|", + "Query:", + qry, ); } catch (e) { console.error( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/view","|", - "Status:","Failure","|", - "Desc:","View specified query", "|", - "Query:", qry, "|", - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/view", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "View specified query", + "|", + "Query:", + qry, + "|", + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } @@ -313,12 +439,23 @@ router client = g_lib.getUserFromClientID(req.queryParams.client); var owner; console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/delete","|", - "Status:","Started","|", - "Desc:","Delete specified query" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/delete", + "|", + "Status:", + "Started", + "|", + "Desc:", + "Delete specified query", ); for (var i in req.queryParams.ids) { @@ -345,25 +482,52 @@ router g_graph.q.remove(owner._from); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/delete","|", - "Status:","Success","|", - "Desc:","Delete specified query", "|", - "Query:",req.queryParams.ids[i], + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/delete", + "|", + "Status:", + "Success", + "|", + "Desc:", + "Delete specified query", + "|", + "Query:", + req.queryParams.ids[i], ); } } catch (e) { console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/delete","|", - "Status:","Failure","|", - "Desc:","Delete specified query", - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/delete", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "Delete specified query", + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } @@ -380,13 +544,26 @@ router try { client = g_lib.getUserFromClientID(req.queryParams.client); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/list","|", - "Status:","Started","|", - "Desc:","List client saved queries", "|", - "Query:", result, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/list", + "|", + "Status:", + "Started", + "|", + "Desc:", + "List client saved queries", + "|", + "Query:", + result, ); var qry = @@ -423,25 +600,55 @@ router res.send(result); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/list","|", - "Status:","Success","|", - "Desc:","List client saved queries", "|", - "Query:", result, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/list", + "|", + "Status:", + "Success", + "|", + "Desc:", + "List client saved queries", + "|", + "Query:", + result, ); } catch (e) { console.error( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/list","|", - "Status:","Failure","|", - "Desc:","List client saved queries", "|", - "Query:", result, "|", - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/list", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "List client saved queries", + "|", + "Query:", + result, + "|", + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } @@ -452,7 +659,7 @@ router .summary("List client saved queries") .description("List client saved queries"); -function execQuery(client, mode, published, orig_query) { +function execQuery(client, mode, published, orig_query) { var col_chk = true, ctxt = client._id; let query = { @@ -659,13 +866,26 @@ router try { client = g_lib.getUserFromClientID(req.queryParams.client); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/exec","|", - "Status:","Started","|", - "Desc:","Execute specified queries", "|", - "Query Result:", results, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/exec", + "|", + "Status:", + "Started", + "|", + "Desc:", + "Execute specified queries", + "|", + "Query Result:", + results, ); var qry = g_db.q.document(req.queryParams.id); @@ -683,25 +903,54 @@ router res.send(results); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/exec","|", - "Status:","Success","|", - "Desc:","Execute specified queries", "|", - "Query Result:", results, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/exec", + "|", + "Status:", + "Success", + "|", + "Desc:", + "Execute specified queries", + "|", + "Query Result:", + results, ); } catch (e) { console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","GET","|", - "Route:","/exec","|", - "Status:","Failure","|", - "Desc:","Execute specified queries", "|", - "Query Result:", results, - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "GET", + "|", + "Route:", + "/exec", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "Execute specified queries", + "|", + "Query Result:", + results, + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } @@ -719,13 +968,26 @@ router try { const client = g_lib.getUserFromClientID_noexcept(req.queryParams.client); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","POST","|", - "Route:","/exec/direct","|", - "Status:","Started","|", - "Desc:","Execute published data search query", "|", - "Query Result:", results, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "POST", + "|", + "Route:", + "/exec/direct", + "|", + "Status:", + "Started", + "|", + "Desc:", + "Execute published data search query", + "|", + "Query Result:", + results, ); const query = { @@ -736,26 +998,54 @@ router res.send(results); console.info( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","POST","|", - "Route:","/exec","|", - "Status:","Started","|", - "Desc:","Execute data search query", "|", - "Query Result:", results, + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "POST", + "|", + "Route:", + "/exec", + "|", + "Status:", + "Started", + "|", + "Desc:", + "Execute data search query", + "|", + "Query Result:", + results, ); - } catch (e) { console.error( - "Client:", client?._id || "unknown","|", - "Correlation_ID:", req.headers['x-correlation-id'],"|", - "HTTP:","POST","|", - "Route:","/exec/direct","|", - "Status:","Failure","|", - "Desc:","Execute data search query", "|", - "Query Result:", results, - "Err:", e.message || e, "|", - "Stack:", e.stack || "No Stack Trace" + "Client:", + client?._id || "unknown", + "|", + "Correlation_ID:", + req.headers["x-correlation-id"], + "|", + "HTTP:", + "POST", + "|", + "Route:", + "/exec/direct", + "|", + "Status:", + "Failure", + "|", + "Desc:", + "Execute data search query", + "|", + "Query Result:", + results, + "Err:", + e.message || e, + "|", + "Stack:", + e.stack || "No Stack Trace", ); g_lib.handleException(e, res); } From b0446135e7b977436d477b09b90fe0ecbfbb190c Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Wed, 10 Sep 2025 14:50:04 -0400 Subject: [PATCH 10/24] style: last minute fixes to incorrect logs --- core/database/foxx/api/query_router.js | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index b916705f9..43588243b 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -32,7 +32,7 @@ router req.headers["x-correlation-id"], "|", "HTTP:", - "GET", + "POST", "|", "Route:", "/create", @@ -42,9 +42,6 @@ router "|", "Desc:", "Create query", - "|", - "Query:", - result, ); // Check max number of saved queries @@ -195,7 +192,7 @@ router req.headers["x-correlation-id"], "|", "HTTP:", - "GET", + "POST", "|", "Route:", "/update", @@ -205,9 +202,6 @@ router "|", "Desc:", "Update a saved query", - "|", - "Query:", - result, ); var qry = g_db.q.document(req.body.id); @@ -352,9 +346,6 @@ router "|", "Desc:", "View specified query", - "|", - "Query:", - qry, ); qry = g_db.q.document(req.queryParams.id); @@ -561,9 +552,6 @@ router "|", "Desc:", "List client saved queries", - "|", - "Query:", - result, ); var qry = @@ -883,9 +871,6 @@ router "|", "Desc:", "Execute specified queries", - "|", - "Query Result:", - results, ); var qry = g_db.q.document(req.queryParams.id); @@ -985,9 +970,6 @@ router "|", "Desc:", "Execute published data search query", - "|", - "Query Result:", - results, ); const query = { From ae8324f92b522c6d6664c6c8a3d51c4efa32157b Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Wed, 10 Sep 2025 15:14:16 -0400 Subject: [PATCH 11/24] style:more final changes --- core/database/foxx/api/query_router.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index 43588243b..f7ac2d53a 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -108,7 +108,7 @@ router req.headers["x-correlation-id"], "|", "HTTP:", - "GET", + "POST", "|", "Route:", "/create", @@ -131,7 +131,7 @@ router req.headers["x-correlation-id"], "|", "HTTP:", - "GET", + "POST", "|", "Route:", "/create", @@ -257,7 +257,7 @@ router req.headers["x-correlation-id"], "|", "HTTP:", - "GET", + "POST", "|", "Route:", "/update", @@ -280,7 +280,7 @@ router req.headers["x-correlation-id"], "|", "HTTP:", - "GET", + "POST", "|", "Route:", "/update", From 65203e43a378dae57e48e4be77b3517147db9e17 Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Thu, 18 Sep 2025 12:46:16 -0400 Subject: [PATCH 12/24] refactor: Added second pass of logging to query_router.js --- core/database/foxx/api/query_router.js | 688 ++++++++----------------- 1 file changed, 207 insertions(+), 481 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index f7ac2d53a..020b007e3 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -7,6 +7,8 @@ const joi = require("joi"); const g_db = require("@arangodb").db; const g_graph = require("@arangodb/general-graph")._graph("sdmsg"); const g_lib = require("./support"); +const logger = require("./lib/logger"); +const basePath = "qry"; module.exports = router; @@ -24,26 +26,15 @@ router }, action: function () { client = g_lib.getUserFromClientID(req.queryParams.client); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/create", - "|", - "Status:", - "Started", - "|", - "Desc:", - "Create query", - ); - + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/create", + status: "Started", + description: "Create Query", + }); + // Check max number of saved queries if (client.max_sav_qry >= 0) { var count = g_db @@ -100,57 +91,28 @@ router }); res.send(result); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/create", - "|", - "Status:", - "Success", - "|", - "Desc:", - "Create query", - "|", - "Query:", - result, - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/create", + status: "Success", + description: "Create Query", + extra: result + }); } catch (e) { - console.error( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/create", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "Create query", - "|", - "Query:", - result, - "|", - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); + logger.logRequestFailure({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/create", + status: "Failure", + description: "Create Query", + extra: result, + message: e.message, + stack: e.stack + }); + g_lib.handleException(e, res); } }) @@ -184,25 +146,14 @@ router }, action: function () { client = g_lib.getUserFromClientID(req.queryParams.client); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/update", - "|", - "Status:", - "Started", - "|", - "Desc:", - "Update a saved query", - ); + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/update", + status: "Started", + description: "Update a saved query", + }); var qry = g_db.q.document(req.body.id); @@ -247,59 +198,28 @@ router result = qry; }, }); - res.send(result); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/update", - "|", - "Status:", - "Success", - "|", - "Desc:", - "Update a saved query", - "|", - "Query:", - result, - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/update", + status: "Success", + description: "Update a saved query", + extra: result + }); } catch (e) { - console.error( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/update", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "Update a saved query", - "|", - "Query:", - result, - "|", - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); + logger.logRequestFailure({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/update", + status: "Failure", + description: "Update a saved query", + extra: result, + message: e.message, + stack: e.stack + }); g_lib.handleException(e, res); } }) @@ -328,25 +248,14 @@ router let qry = undefined; try { client = g_lib.getUserFromClientID(req.queryParams.client); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/view", - "|", - "Status:", - "Started", - "|", - "Desc:", - "View specified query", - ); + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/view", + status: "Started", + description: "View specified query", + }); qry = g_db.q.document(req.queryParams.id); if (client._id != qry.owner && !client.is_admin) { @@ -364,57 +273,28 @@ router delete qry.lmit; res.send(qry); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/view", - "|", - "Status:", - "Success", - "|", - "Desc:", - "View specified query", - "|", - "Query:", - qry, - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/view", + status: "Success", + description: "View specified query", + extra: qry + }); } catch (e) { - console.error( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/view", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "View specified query", - "|", - "Query:", - qry, - "|", - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); + logger.logRequestFailure({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/view", + status: "Failure", + description: "View specified query", + extra: qry, + message: e.message, + stack: e.stack + }); + g_lib.handleException(e, res); } }) @@ -429,25 +309,14 @@ router try { client = g_lib.getUserFromClientID(req.queryParams.client); var owner; - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/delete", - "|", - "Status:", - "Started", - "|", - "Desc:", - "Delete specified query", - ); + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/delete", + status: "Started", + description: "Delete specified query", + }); for (var i in req.queryParams.ids) { if (!req.queryParams.ids[i].startsWith("q/")) { @@ -472,54 +341,29 @@ router } g_graph.q.remove(owner._from); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/delete", - "|", - "Status:", - "Success", - "|", - "Desc:", - "Delete specified query", - "|", - "Query:", - req.queryParams.ids[i], - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/delete", + status: "Success", + description: "Delete specified query", + extra: req.queryParams.ids[i] + }); } } catch (e) { - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/delete", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "Delete specified query", - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/delete", + status: "Failure", + description: "Delete specified query", + extra: req.queryParams.ids[i], + message: e.message, + stack: e.stack + }); + g_lib.handleException(e, res); } }) @@ -534,25 +378,14 @@ router let result = undefined; try { client = g_lib.getUserFromClientID(req.queryParams.client); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/list", - "|", - "Status:", - "Started", - "|", - "Desc:", - "List client saved queries", - ); + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/list", + status: "Started", + description: "List client saved queries", + }); var qry = "for v in 1..1 inbound @user owner filter is_same_collection('q',v) sort v.title"; @@ -587,58 +420,28 @@ router } res.send(result); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/list", - "|", - "Status:", - "Success", - "|", - "Desc:", - "List client saved queries", - "|", - "Query:", - result, - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/list", + status: "Success", + description: "List client saved queries", + extra: result + }); } catch (e) { - console.error( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/list", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "List client saved queries", - "|", - "Query:", - result, - "|", - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); - g_lib.handleException(e, res); + logger.logRequestFailure({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/list", + status: "Failure", + description: "List client saved queries", + extra: result, + message: e.message, + stack: e.stack + }); + g_lib.handleException(e, res); } }) .queryParam("client", joi.string().required(), "Client ID") @@ -853,25 +656,14 @@ router let results = undefined; try { client = g_lib.getUserFromClientID(req.queryParams.client); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/exec", - "|", - "Status:", - "Started", - "|", - "Desc:", - "Execute specified queries", - ); + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/exec", + status: "Started", + description: "Execute specified queries", + }); var qry = g_db.q.document(req.queryParams.id); @@ -887,56 +679,28 @@ router results = execQuery(client, qry.query.mode, qry.query.published, qry); res.send(results); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/exec", - "|", - "Status:", - "Success", - "|", - "Desc:", - "Execute specified queries", - "|", - "Query Result:", - results, - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/exec", + status: "Success", + description: "Execute specified queries", + extra: results + }); + } catch (e) { - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "GET", - "|", - "Route:", - "/exec", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "Execute specified queries", - "|", - "Query Result:", - results, - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); + logger.logRequestFailure({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "GET", + routePath: basePath + "/exec", + status: "Failure", + description: "Execute specified queries", + extra: results, + message: e.message, + stack: e.stack + }); g_lib.handleException(e, res); } }) @@ -950,27 +714,17 @@ router router .post("/exec/direct", function (req, res) { let results = undefined; + let client = undefined; try { - const client = g_lib.getUserFromClientID_noexcept(req.queryParams.client); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/exec/direct", - "|", - "Status:", - "Started", - "|", - "Desc:", - "Execute published data search query", - ); + client = g_lib.getUserFromClientID_noexcept(req.queryParams.client); + logger.logRequestStarted({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/exec/direct", + status: "Started", + description: "Execute published data search query", + }); const query = { ...req.body, @@ -979,56 +733,28 @@ router results = execQuery(client, req.body.mode, req.body.published, query); res.send(results); - console.info( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/exec", - "|", - "Status:", - "Started", - "|", - "Desc:", - "Execute data search query", - "|", - "Query Result:", - results, - ); + logger.logRequestSuccess({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/exec/direct", + status: "Success", + description: "Execute published data search query", + extra: results + }); + } catch (e) { - console.error( - "Client:", - client?._id || "unknown", - "|", - "Correlation_ID:", - req.headers["x-correlation-id"], - "|", - "HTTP:", - "POST", - "|", - "Route:", - "/exec/direct", - "|", - "Status:", - "Failure", - "|", - "Desc:", - "Execute data search query", - "|", - "Query Result:", - results, - "Err:", - e.message || e, - "|", - "Stack:", - e.stack || "No Stack Trace", - ); + logger.logRequestFailure({ + client: client?._id, + correlationId: req.headers["x-correlation-id"], + httpVerb: "POST", + routePath: basePath + "/exec/direct", + status: "Success", + description: "Execute published data search query", + extra: results, + message: e.message, + stack: e.stack + }); g_lib.handleException(e, res); } }) From 65d6797ad6db7e1e473e6d7b377cd2f16bb56d36 Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Mon, 22 Sep 2025 10:20:06 -0400 Subject: [PATCH 13/24] Added logger.js --- core/database/foxx/api/lib/logger.js | 93 ++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 core/database/foxx/api/lib/logger.js diff --git a/core/database/foxx/api/lib/logger.js b/core/database/foxx/api/lib/logger.js new file mode 100644 index 000000000..368c5b8f5 --- /dev/null +++ b/core/database/foxx/api/lib/logger.js @@ -0,0 +1,93 @@ +"use strict"; + +function logRequestSuccess({ + client, + correlationId, + httpVerb, + routePath, + status, + description, + extra, +}) { + // helper to pad fields + const pad = (label, value, length = 20) => + `${label}: ${value || "unknown"}`.padEnd(length, " "); + + console.info( + pad("Client", client) + + " | " + + pad("Correlation_ID", correlationId) + + " | " + + pad("HTTP", httpVerb) + + " | " + + pad("Route", routePath) + + " | " + + pad("Status", status) + + " | " + + pad("Desc", description) + + "|" + + pad("Extra", typeof extra === "object" ? JSON.stringify(extra) : extra), + ); +} + +function logRequestFailure({ + client, + correlationId, + httpVerb, + routePath, + status, + description, + extra, + message, + stack, +}) { + // helper to pad fields + const pad = (label, value, length = 20) => + `${label}: ${value || "unknown"}`.padEnd(length, " "); + console.error( + pad("Client", client) + + " | " + + pad("Correlation_ID", correlationId) + + " | " + + pad("HTTP", httpVerb) + + " | " + + pad("Route", routePath) + + " | " + + pad("Status", status) + + " | " + + pad("Desc", description) + + "|" + + pad("Extra", typeof extra === "object" ? JSON.stringify(extra) : extra) + + "|" + + pad("Err", message) + + "|" + + pad("Stack", stack), + ); +} + +function logRequestStarted({ client, correlationId, httpVerb, routePath, status, description }) { + // helper to pad fields + const pad = (label, value, length = 20) => + `${label}: ${value || "unknown"}`.padEnd(length, " "); + + console.info( + pad("Client", client) + + " | " + + pad("Correlation_ID", correlationId) + + " | " + + pad("HTTP", httpVerb) + + " | " + + pad("Route", routePath) + + " | " + + pad("Status", status) + + " | " + + pad("Desc", description), + ); +} + +// Export the functions +module.exports = { + logRequestSuccess, + logRequestFailure, + logRequestStarted, +}; From e77214c5cbae8a1479befd4bfdf1dbde3823f907 Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Thu, 18 Sep 2025 16:54:54 +0000 Subject: [PATCH 14/24] chore: Auto-format JavaScript files with Prettier --- core/database/foxx/api/query_router.js | 36 ++++++++++++-------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index 020b007e3..b30985811 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -34,7 +34,7 @@ router status: "Started", description: "Create Query", }); - + // Check max number of saved queries if (client.max_sav_qry >= 0) { var count = g_db @@ -98,7 +98,7 @@ router routePath: basePath + "/create", status: "Success", description: "Create Query", - extra: result + extra: result, }); } catch (e) { logger.logRequestFailure({ @@ -110,9 +110,9 @@ router description: "Create Query", extra: result, message: e.message, - stack: e.stack + stack: e.stack, }); - + g_lib.handleException(e, res); } }) @@ -206,7 +206,7 @@ router routePath: basePath + "/update", status: "Success", description: "Update a saved query", - extra: result + extra: result, }); } catch (e) { logger.logRequestFailure({ @@ -218,7 +218,7 @@ router description: "Update a saved query", extra: result, message: e.message, - stack: e.stack + stack: e.stack, }); g_lib.handleException(e, res); } @@ -280,7 +280,7 @@ router routePath: basePath + "/view", status: "Success", description: "View specified query", - extra: qry + extra: qry, }); } catch (e) { logger.logRequestFailure({ @@ -292,7 +292,7 @@ router description: "View specified query", extra: qry, message: e.message, - stack: e.stack + stack: e.stack, }); g_lib.handleException(e, res); @@ -348,7 +348,7 @@ router routePath: basePath + "/delete", status: "Success", description: "Delete specified query", - extra: req.queryParams.ids[i] + extra: req.queryParams.ids[i], }); } } catch (e) { @@ -361,7 +361,7 @@ router description: "Delete specified query", extra: req.queryParams.ids[i], message: e.message, - stack: e.stack + stack: e.stack, }); g_lib.handleException(e, res); @@ -427,7 +427,7 @@ router routePath: basePath + "/list", status: "Success", description: "List client saved queries", - extra: result + extra: result, }); } catch (e) { logger.logRequestFailure({ @@ -439,9 +439,9 @@ router description: "List client saved queries", extra: result, message: e.message, - stack: e.stack + stack: e.stack, }); - g_lib.handleException(e, res); + g_lib.handleException(e, res); } }) .queryParam("client", joi.string().required(), "Client ID") @@ -686,9 +686,8 @@ router routePath: basePath + "/exec", status: "Success", description: "Execute specified queries", - extra: results + extra: results, }); - } catch (e) { logger.logRequestFailure({ client: client?._id, @@ -699,7 +698,7 @@ router description: "Execute specified queries", extra: results, message: e.message, - stack: e.stack + stack: e.stack, }); g_lib.handleException(e, res); } @@ -740,9 +739,8 @@ router routePath: basePath + "/exec/direct", status: "Success", description: "Execute published data search query", - extra: results + extra: results, }); - } catch (e) { logger.logRequestFailure({ client: client?._id, @@ -753,7 +751,7 @@ router description: "Execute published data search query", extra: results, message: e.message, - stack: e.stack + stack: e.stack, }); g_lib.handleException(e, res); } From b2ccee3a35b8d746073981c65caaf37c38709cfa Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Thu, 25 Sep 2025 14:00:36 -0400 Subject: [PATCH 15/24] style: fixed logger --- core/database/foxx/api/lib/logger.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/database/foxx/api/lib/logger.js b/core/database/foxx/api/lib/logger.js index 368c5b8f5..8039c3bca 100644 --- a/core/database/foxx/api/lib/logger.js +++ b/core/database/foxx/api/lib/logger.js @@ -25,7 +25,7 @@ function logRequestSuccess({ pad("Status", status) + " | " + pad("Desc", description) + - "|" + + " | " + pad("Extra", typeof extra === "object" ? JSON.stringify(extra) : extra), ); } @@ -56,11 +56,11 @@ function logRequestFailure({ pad("Status", status) + " | " + pad("Desc", description) + - "|" + + " | " + pad("Extra", typeof extra === "object" ? JSON.stringify(extra) : extra) + - "|" + + " | " + pad("Err", message) + - "|" + + " | " + pad("Stack", stack), ); } From e3d42dcebec0db34cb050b71f24a4cbe090ec056 Mon Sep 17 00:00:00 2001 From: Austin Hampton <44103380+megatnt1122@users.noreply.github.com> Date: Mon, 6 Oct 2025 15:27:50 -0400 Subject: [PATCH 16/24] Apply suggestions from code review Co-authored-by: Joshua S Brown --- core/database/foxx/api/query_router.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index b30985811..ddba78808 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -352,7 +352,7 @@ router }); } } catch (e) { - logger.logRequestSuccess({ + logger.logRequestFailure({ client: client?._id, correlationId: req.headers["x-correlation-id"], httpVerb: "GET", @@ -747,7 +747,7 @@ router correlationId: req.headers["x-correlation-id"], httpVerb: "POST", routePath: basePath + "/exec/direct", - status: "Success", + status: "Failure", description: "Execute published data search query", extra: results, message: e.message, From 26247e2a35e83f0c681eca918b66d4aa2856452e Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Tue, 7 Oct 2025 10:51:45 -0400 Subject: [PATCH 17/24] Removed unneccessary logger file --- core/database/foxx/api/lib/logger.js | 93 ---------------------------- external/DataFedDependencies | 2 +- 2 files changed, 1 insertion(+), 94 deletions(-) delete mode 100644 core/database/foxx/api/lib/logger.js diff --git a/core/database/foxx/api/lib/logger.js b/core/database/foxx/api/lib/logger.js deleted file mode 100644 index 8039c3bca..000000000 --- a/core/database/foxx/api/lib/logger.js +++ /dev/null @@ -1,93 +0,0 @@ -"use strict"; - -function logRequestSuccess({ - client, - correlationId, - httpVerb, - routePath, - status, - description, - extra, -}) { - // helper to pad fields - const pad = (label, value, length = 20) => - `${label}: ${value || "unknown"}`.padEnd(length, " "); - - console.info( - pad("Client", client) + - " | " + - pad("Correlation_ID", correlationId) + - " | " + - pad("HTTP", httpVerb) + - " | " + - pad("Route", routePath) + - " | " + - pad("Status", status) + - " | " + - pad("Desc", description) + - " | " + - pad("Extra", typeof extra === "object" ? JSON.stringify(extra) : extra), - ); -} - -function logRequestFailure({ - client, - correlationId, - httpVerb, - routePath, - status, - description, - extra, - message, - stack, -}) { - // helper to pad fields - const pad = (label, value, length = 20) => - `${label}: ${value || "unknown"}`.padEnd(length, " "); - console.error( - pad("Client", client) + - " | " + - pad("Correlation_ID", correlationId) + - " | " + - pad("HTTP", httpVerb) + - " | " + - pad("Route", routePath) + - " | " + - pad("Status", status) + - " | " + - pad("Desc", description) + - " | " + - pad("Extra", typeof extra === "object" ? JSON.stringify(extra) : extra) + - " | " + - pad("Err", message) + - " | " + - pad("Stack", stack), - ); -} - -function logRequestStarted({ client, correlationId, httpVerb, routePath, status, description }) { - // helper to pad fields - const pad = (label, value, length = 20) => - `${label}: ${value || "unknown"}`.padEnd(length, " "); - - console.info( - pad("Client", client) + - " | " + - pad("Correlation_ID", correlationId) + - " | " + - pad("HTTP", httpVerb) + - " | " + - pad("Route", routePath) + - " | " + - pad("Status", status) + - " | " + - pad("Desc", description), - ); -} - -// Export the functions -module.exports = { - logRequestSuccess, - logRequestFailure, - logRequestStarted, -}; diff --git a/external/DataFedDependencies b/external/DataFedDependencies index eee5cfb8d..b3528638d 160000 --- a/external/DataFedDependencies +++ b/external/DataFedDependencies @@ -1 +1 @@ -Subproject commit eee5cfb8dac44b806f2a78526603cb363bc2a002 +Subproject commit b3528638dc7e78633b60b607fd0227aa5862bf53 From d864619305bcce24300c63a2eb59523b70a1a0dc Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Tue, 7 Oct 2025 11:08:41 -0400 Subject: [PATCH 18/24] Refactor: Adjusted error handling within logs for more flexability --- core/database/foxx/api/query_router.js | 21 +++++++-------------- external/DataFedDependencies | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index d18c9412d..8685ca92e 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -110,8 +110,7 @@ router status: "Failure", description: "Create Query", extra: result, - message: e.message, - stack: e.stack, + error: e, }); g_lib.handleException(e, res); @@ -218,8 +217,7 @@ router status: "Failure", description: "Update a saved query", extra: result, - message: e.message, - stack: e.stack, + error: e, }); g_lib.handleException(e, res); } @@ -292,8 +290,7 @@ router status: "Failure", description: "View specified query", extra: qry, - message: e.message, - stack: e.stack, + error: e, }); g_lib.handleException(e, res); @@ -361,8 +358,7 @@ router status: "Failure", description: "Delete specified query", extra: req.queryParams.ids[i], - message: e.message, - stack: e.stack, + error: e, }); g_lib.handleException(e, res); @@ -439,8 +435,7 @@ router status: "Failure", description: "List client saved queries", extra: result, - message: e.message, - stack: e.stack, + error: e, }); g_lib.handleException(e, res); } @@ -698,8 +693,7 @@ router status: "Failure", description: "Execute specified queries", extra: results, - message: e.message, - stack: e.stack, + error: e, }); g_lib.handleException(e, res); } @@ -751,8 +745,7 @@ router status: "Failure", description: "Execute published data search query", extra: results, - message: e.message, - stack: e.stack, + error: e, }); g_lib.handleException(e, res); } diff --git a/external/DataFedDependencies b/external/DataFedDependencies index 57483e1cd..b3528638d 160000 --- a/external/DataFedDependencies +++ b/external/DataFedDependencies @@ -1 +1 @@ -Subproject commit 57483e1cd4eac9d84162dd7202e72fe353728361 +Subproject commit b3528638dc7e78633b60b607fd0227aa5862bf53 From 3eb0a29a0b317d83cbb94a8c0ff5b0aabec2e855 Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Tue, 7 Oct 2025 14:45:12 -0400 Subject: [PATCH 19/24] Submodule update --- external/DataFedDependencies | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/DataFedDependencies b/external/DataFedDependencies index b3528638d..57483e1cd 160000 --- a/external/DataFedDependencies +++ b/external/DataFedDependencies @@ -1 +1 @@ -Subproject commit b3528638dc7e78633b60b607fd0227aa5862bf53 +Subproject commit 57483e1cd4eac9d84162dd7202e72fe353728361 From 7ef5a4c0370af0d9db74804e7f37e69f8454e574 Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Tue, 21 Oct 2025 11:43:08 -0400 Subject: [PATCH 20/24] refactor: expanded the logs for query router; added tests, adjusted cmakelist --- core/database/CMakeLists.txt | 2 + core/database/foxx/api/query_router.js | 5 +- core/database/foxx/tests/query_router.test.js | 159 ++++++++++++++++++ 3 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 core/database/foxx/tests/query_router.test.js diff --git a/core/database/CMakeLists.txt b/core/database/CMakeLists.txt index 17bdd6da1..758c2325e 100644 --- a/core/database/CMakeLists.txt +++ b/core/database/CMakeLists.txt @@ -21,6 +21,7 @@ if( ENABLE_FOXX_TESTS ) add_test(NAME foxx_version COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_version") add_test(NAME foxx_support COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_support") add_test(NAME foxx_user_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_user_router") + add_test(NAME foxx_query_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_query_router") add_test(NAME foxx_authz_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_authz_router") add_test(NAME foxx_unit_user_token COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_user_token") add_test(NAME foxx_unit_user_model COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_user_model") @@ -38,6 +39,7 @@ if( ENABLE_FOXX_TESTS ) set_tests_properties(foxx_repo PROPERTIES FIXTURES_REQUIRED Foxx) set_tests_properties(foxx_path PROPERTIES FIXTURES_REQUIRED Foxx) set_tests_properties(foxx_user_router PROPERTIES FIXTURES_REQUIRED "Foxx;FoxxDBFixtures") + set_tests_properties(foxx_query_router PROPERTIES FIXTURES_REQUIRED Foxx) set_tests_properties(foxx_unit_user_token PROPERTIES FIXTURES_REQUIRED Foxx) set_tests_properties(foxx_unit_user_model PROPERTIES FIXTURES_REQUIRED "Foxx;FoxxDBFixtures") set_tests_properties(foxx_unit_globus_collection_model PROPERTIES FIXTURES_REQUIRED "Foxx;FoxxDBFixtures") diff --git a/core/database/foxx/api/query_router.js b/core/database/foxx/api/query_router.js index 8685ca92e..30de93454 100644 --- a/core/database/foxx/api/query_router.js +++ b/core/database/foxx/api/query_router.js @@ -424,7 +424,10 @@ router routePath: basePath + "/list", status: "Success", description: "List client saved queries", - extra: result, + extra: { + queryParams: req.queryParams, + _countTotal: result._countTotal, + }, }); } catch (e) { logger.logRequestFailure({ diff --git a/core/database/foxx/tests/query_router.test.js b/core/database/foxx/tests/query_router.test.js new file mode 100644 index 000000000..5069e6283 --- /dev/null +++ b/core/database/foxx/tests/query_router.test.js @@ -0,0 +1,159 @@ +"use strict"; +// NOTE: completion of tests requires successful run of user_fixture.js script + +// Need to pull enum from support +const g_lib = require("../api/support"); + +// Integration test of API +const { expect } = require("chai"); +const request = require("@arangodb/request"); +const { baseUrl } = module.context; +const { db } = require("@arangodb"); + +const qry_base_url = `${baseUrl}/qry`; + +describe("unit_query_router: the Foxx microservice qry_router endpoints", () => { + beforeEach(() => { + const collections = [ "u", "qry"]; + collections.forEach((name) => { + let col = db._collection(name); + if (col) { + col.truncate(); // truncate after ensuring collection exists + } else { + db._create(name); // create if it doesn’t exist + } + }); + }); + +it("should successfully run the create route", () => { + db.u.save({ + _key: "fakeUser", + _id: "u/fakeUser", + name: "fake user", + name_first: "fake", + name_last: "user", + is_admin: true, + max_coll: 50, + max_proj: 10, + max_sav_qry: 20, + email: "fakeuser@gmail.com", + }); + + // Arrange + const request_string = `${qry_base_url}/create?client=u/fakeUser`; + + const body = { + title: "My Query", + qry_begin: "FOR i IN something", + qry_end: "RETURN i", + qry_filter: "", + params: {}, + limit: 10, + query: {}, // adjust if necessary + }; + + const response = request.post(request_string, { + json: true, + body: body, + headers: { + "x-correlation-id": "test-correlation-id" + } + }); + + // Assert + expect(response.status).to.equal(200); + }); + +it("should fail running the create route", () => { + db.u.save({ + _key: "fakeUser", + _id: "u/fakeUser", + name: "fake user", + name_first: "fake", + name_last: "user", + is_admin: true, + max_coll: 50, + max_proj: 10, + max_sav_qry: 20, + email: "fakeuser@gmail.com", + }); + + // Arrange + const request_string = `${qry_base_url}/create?client=u/wellthiswasunexpected`; + + const body = { + title: "My Query", + qry_begin: "FOR i IN something", + qry_end: "RETURN i", + qry_filter: "", + params: {}, + limit: 10, + query: {}, // adjust if necessary + }; + + const response = request.post(request_string, { + json: true, + body: body, + headers: { + "x-correlation-id": "test-correlation-id" + } + }); + + // Assert + expect(response.status).to.equal(400); + }); + + it("should return a list of saved queries for a valid user", () => { + // arrange + const fakeUser = { + _key: "fakeUser", + _id: "u/fakeUser", + name: "Fake User", + email: "fakeuser@datadev.org", + is_admin: false, + max_coll: 5, + max_proj: 5, + max_sav_qry: 10, + }; + + db.u.save(fakeUser); + + // Save the query and the edge between the query and the user + var request_string = `${qry_base_url}/create?client=u/fakeUser`; + + var body = { + title: "Test Query Title", + qry_begin: "FOR i IN something", + qry_end: "RETURN i", + qry_filter: "", + params: {}, + limit: 10, + query: {}, // adjust if necessary + }; + + var response = request.post(request_string, { + json: true, + body: body, + headers: { + "x-correlation-id": "test-correlation-id" + } + }); + + + request_string = `${qry_base_url}/list?client=u/fakeUser`; + + // act + response = request.get(request_string, { + headers: { + "x-correlation-id": "test-correlation-id" + } + }); + + var parsed = JSON.parse(response.body); + console.log("Response body:", response.body); + // assert + expect(response.status).to.equal(200); + expect(parsed).to.be.an("array"); + expect(parsed.length).to.be.greaterThan(0); +}); +}); From 16a97c25b849440d53cb59f6d0b979ef8997175c Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Tue, 21 Oct 2025 15:44:26 +0000 Subject: [PATCH 21/24] chore: Auto-format JavaScript files with Prettier --- core/database/foxx/tests/query_router.test.js | 237 +++++++++--------- 1 file changed, 118 insertions(+), 119 deletions(-) diff --git a/core/database/foxx/tests/query_router.test.js b/core/database/foxx/tests/query_router.test.js index 5069e6283..584624af8 100644 --- a/core/database/foxx/tests/query_router.test.js +++ b/core/database/foxx/tests/query_router.test.js @@ -14,7 +14,7 @@ const qry_base_url = `${baseUrl}/qry`; describe("unit_query_router: the Foxx microservice qry_router endpoints", () => { beforeEach(() => { - const collections = [ "u", "qry"]; + const collections = ["u", "qry"]; collections.forEach((name) => { let col = db._collection(name); if (col) { @@ -25,135 +25,134 @@ describe("unit_query_router: the Foxx microservice qry_router endpoints", () => }); }); -it("should successfully run the create route", () => { - db.u.save({ - _key: "fakeUser", - _id: "u/fakeUser", - name: "fake user", - name_first: "fake", - name_last: "user", - is_admin: true, - max_coll: 50, - max_proj: 10, - max_sav_qry: 20, - email: "fakeuser@gmail.com", - }); + it("should successfully run the create route", () => { + db.u.save({ + _key: "fakeUser", + _id: "u/fakeUser", + name: "fake user", + name_first: "fake", + name_last: "user", + is_admin: true, + max_coll: 50, + max_proj: 10, + max_sav_qry: 20, + email: "fakeuser@gmail.com", + }); - // Arrange - const request_string = `${qry_base_url}/create?client=u/fakeUser`; - - const body = { - title: "My Query", - qry_begin: "FOR i IN something", - qry_end: "RETURN i", - qry_filter: "", - params: {}, - limit: 10, - query: {}, // adjust if necessary - }; - - const response = request.post(request_string, { - json: true, - body: body, - headers: { - "x-correlation-id": "test-correlation-id" - } - }); + // Arrange + const request_string = `${qry_base_url}/create?client=u/fakeUser`; + + const body = { + title: "My Query", + qry_begin: "FOR i IN something", + qry_end: "RETURN i", + qry_filter: "", + params: {}, + limit: 10, + query: {}, // adjust if necessary + }; + + const response = request.post(request_string, { + json: true, + body: body, + headers: { + "x-correlation-id": "test-correlation-id", + }, + }); - // Assert - expect(response.status).to.equal(200); + // Assert + expect(response.status).to.equal(200); }); -it("should fail running the create route", () => { - db.u.save({ - _key: "fakeUser", - _id: "u/fakeUser", - name: "fake user", - name_first: "fake", - name_last: "user", - is_admin: true, - max_coll: 50, - max_proj: 10, - max_sav_qry: 20, - email: "fakeuser@gmail.com", - }); + it("should fail running the create route", () => { + db.u.save({ + _key: "fakeUser", + _id: "u/fakeUser", + name: "fake user", + name_first: "fake", + name_last: "user", + is_admin: true, + max_coll: 50, + max_proj: 10, + max_sav_qry: 20, + email: "fakeuser@gmail.com", + }); - // Arrange - const request_string = `${qry_base_url}/create?client=u/wellthiswasunexpected`; - - const body = { - title: "My Query", - qry_begin: "FOR i IN something", - qry_end: "RETURN i", - qry_filter: "", - params: {}, - limit: 10, - query: {}, // adjust if necessary - }; - - const response = request.post(request_string, { - json: true, - body: body, - headers: { - "x-correlation-id": "test-correlation-id" - } - }); + // Arrange + const request_string = `${qry_base_url}/create?client=u/wellthiswasunexpected`; + + const body = { + title: "My Query", + qry_begin: "FOR i IN something", + qry_end: "RETURN i", + qry_filter: "", + params: {}, + limit: 10, + query: {}, // adjust if necessary + }; + + const response = request.post(request_string, { + json: true, + body: body, + headers: { + "x-correlation-id": "test-correlation-id", + }, + }); - // Assert - expect(response.status).to.equal(400); + // Assert + expect(response.status).to.equal(400); }); it("should return a list of saved queries for a valid user", () => { - // arrange - const fakeUser = { - _key: "fakeUser", - _id: "u/fakeUser", - name: "Fake User", - email: "fakeuser@datadev.org", - is_admin: false, - max_coll: 5, - max_proj: 5, - max_sav_qry: 10, - }; - - db.u.save(fakeUser); - - // Save the query and the edge between the query and the user - var request_string = `${qry_base_url}/create?client=u/fakeUser`; - - var body = { - title: "Test Query Title", - qry_begin: "FOR i IN something", - qry_end: "RETURN i", - qry_filter: "", - params: {}, - limit: 10, - query: {}, // adjust if necessary - }; - - var response = request.post(request_string, { - json: true, - body: body, - headers: { - "x-correlation-id": "test-correlation-id" - } - }); + // arrange + const fakeUser = { + _key: "fakeUser", + _id: "u/fakeUser", + name: "Fake User", + email: "fakeuser@datadev.org", + is_admin: false, + max_coll: 5, + max_proj: 5, + max_sav_qry: 10, + }; + + db.u.save(fakeUser); + + // Save the query and the edge between the query and the user + var request_string = `${qry_base_url}/create?client=u/fakeUser`; + + var body = { + title: "Test Query Title", + qry_begin: "FOR i IN something", + qry_end: "RETURN i", + qry_filter: "", + params: {}, + limit: 10, + query: {}, // adjust if necessary + }; + + var response = request.post(request_string, { + json: true, + body: body, + headers: { + "x-correlation-id": "test-correlation-id", + }, + }); + request_string = `${qry_base_url}/list?client=u/fakeUser`; - request_string = `${qry_base_url}/list?client=u/fakeUser`; + // act + response = request.get(request_string, { + headers: { + "x-correlation-id": "test-correlation-id", + }, + }); - // act - response = request.get(request_string, { - headers: { - "x-correlation-id": "test-correlation-id" - } + var parsed = JSON.parse(response.body); + console.log("Response body:", response.body); + // assert + expect(response.status).to.equal(200); + expect(parsed).to.be.an("array"); + expect(parsed.length).to.be.greaterThan(0); }); - - var parsed = JSON.parse(response.body); - console.log("Response body:", response.body); - // assert - expect(response.status).to.equal(200); - expect(parsed).to.be.an("array"); - expect(parsed.length).to.be.greaterThan(0); -}); }); From 721db9de9cb177002ba47ecc0a3e4f0971516cb5 Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Thu, 23 Oct 2025 10:25:00 -0400 Subject: [PATCH 22/24] refactor: Final changes to CMakeLists file to add query tests --- core/database/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/database/CMakeLists.txt b/core/database/CMakeLists.txt index a82d2498f..d95eaf8ba 100644 --- a/core/database/CMakeLists.txt +++ b/core/database/CMakeLists.txt @@ -26,8 +26,9 @@ if( ENABLE_FOXX_TESTS ) add_test(NAME foxx_path COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_path:") add_test(NAME foxx_version COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_version:") add_test(NAME foxx_support COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_support:") - add_test(NAME foxx_user_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_user_router:") add_test(NAME foxx_authz_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_authz_router:") + add_test(NAME foxx_user_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_user_router:") + add_test(NAME foxx_query_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_query_router:") add_test(NAME foxx_unit_user_token COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_user_token:") add_test(NAME foxx_unit_user_model COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_user_model:") add_test(NAME foxx_unit_globus_collection_model COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_globus_collection_model:") From 963db8a8b71a72f81330bba97aca6c59d2128ee7 Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Mon, 27 Oct 2025 09:40:45 -0400 Subject: [PATCH 23/24] refactor: added cleanup after tests --- core/database/foxx/tests/query_router.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/database/foxx/tests/query_router.test.js b/core/database/foxx/tests/query_router.test.js index 584624af8..707cbdd4d 100644 --- a/core/database/foxx/tests/query_router.test.js +++ b/core/database/foxx/tests/query_router.test.js @@ -13,6 +13,14 @@ const { db } = require("@arangodb"); const qry_base_url = `${baseUrl}/qry`; describe("unit_query_router: the Foxx microservice qry_router endpoints", () => { + after(function () { + const collections = ["u", "task"]; + collections.forEach((name) => { + let col = db._collection(name); + if (col) col.truncate(); + }); + }); + beforeEach(() => { const collections = ["u", "qry"]; collections.forEach((name) => { From 04be36960891a746c7ddc136a9b8fb584eae243e Mon Sep 17 00:00:00 2001 From: Austin Hampton Date: Mon, 27 Oct 2025 09:54:30 -0400 Subject: [PATCH 24/24] Refactor: adjusted cleanup --- core/database/foxx/tests/query_router.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/database/foxx/tests/query_router.test.js b/core/database/foxx/tests/query_router.test.js index 707cbdd4d..b075e6790 100644 --- a/core/database/foxx/tests/query_router.test.js +++ b/core/database/foxx/tests/query_router.test.js @@ -14,7 +14,7 @@ const qry_base_url = `${baseUrl}/qry`; describe("unit_query_router: the Foxx microservice qry_router endpoints", () => { after(function () { - const collections = ["u", "task"]; + const collections = ["u", "qry"]; collections.forEach((name) => { let col = db._collection(name); if (col) col.truncate();