Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4955945
refactor: Added first pass of logging improvements to query_router
megatnt1122 Sep 10, 2025
afd43f0
chore: Auto-format JavaScript files with Prettier
megatnt1122 Sep 10, 2025
e51df52
style: last minute fixes to incorrect logs
megatnt1122 Sep 10, 2025
591ac26
style:more final changes
megatnt1122 Sep 10, 2025
6b82648
refactor: Added second pass of logging to query_router.js
megatnt1122 Sep 18, 2025
6d51811
chore: Auto-format JavaScript files with Prettier
megatnt1122 Sep 18, 2025
4dea846
Added logger.js
megatnt1122 Sep 22, 2025
9f2e0a5
Merge branch 'refactor-DAPS-1522-Query-Router-Logging-Improvements' o…
megatnt1122 Sep 22, 2025
66ec13f
refactor: Added first pass of logging improvements to query_router
megatnt1122 Sep 10, 2025
07decbf
chore: Auto-format JavaScript files with Prettier
megatnt1122 Sep 10, 2025
b044613
style: last minute fixes to incorrect logs
megatnt1122 Sep 10, 2025
ae8324f
style:more final changes
megatnt1122 Sep 10, 2025
65203e4
refactor: Added second pass of logging to query_router.js
megatnt1122 Sep 18, 2025
65d6797
Added logger.js
megatnt1122 Sep 22, 2025
e77214c
chore: Auto-format JavaScript files with Prettier
megatnt1122 Sep 18, 2025
b2ccee3
style: fixed logger
megatnt1122 Sep 25, 2025
bbbc313
Merge branch 'refactor-DAPS-1522-Query-Router-Logging-Improvements' o…
megatnt1122 Sep 25, 2025
e3d42dc
Apply suggestions from code review
megatnt1122 Oct 6, 2025
26247e2
Removed unneccessary logger file
megatnt1122 Oct 7, 2025
c5525fa
Merge remote-tracking branch 'origin/devel' into refactor-DAPS-1522-Q…
megatnt1122 Oct 7, 2025
d864619
Refactor: Adjusted error handling within logs for more flexability
megatnt1122 Oct 7, 2025
3eb0a29
Submodule update
megatnt1122 Oct 7, 2025
7ef5a4c
refactor: expanded the logs for query router; added tests, adjusted
megatnt1122 Oct 21, 2025
16a97c2
chore: Auto-format JavaScript files with Prettier
megatnt1122 Oct 21, 2025
7356722
Merge remote-tracking branch 'origin/devel' into refactor-DAPS-1522-Q…
megatnt1122 Oct 23, 2025
721db9d
refactor: Final changes to CMakeLists file to add query tests
megatnt1122 Oct 23, 2025
963db8a
refactor: added cleanup after tests
megatnt1122 Oct 27, 2025
04be369
Refactor: adjusted cleanup
megatnt1122 Oct 27, 2025
4eff6d5
Merge branch 'devel' into refactor-DAPS-1522-Query-Router-Logging-Imp…
JoshuaSBrown Oct 28, 2025
09cbd64
Merge branch 'devel' into refactor-DAPS-1522-Query-Router-Logging-Imp…
JoshuaSBrown Oct 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/database/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ if( ENABLE_FOXX_TESTS )
add_test(NAME foxx_user_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_user_router:")
add_test(NAME foxx_task_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_task_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:")
Expand All @@ -52,6 +54,7 @@ if( ENABLE_FOXX_TESTS )
set_tests_properties(foxx_validation_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_task_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")
Expand Down
238 changes: 222 additions & 16 deletions core/database/foxx/api/query_router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,33 @@ const error = require("./lib/error_codes");
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;

//==================== QUERY API FUNCTIONS

router
.post("/create", function (req, res) {
let client = undefined;
let result = undefined;
try {
var result;

g_db._executeTransaction({
collections: {
read: ["u", "uuid", "accn", "admin"],
write: ["q", "owner"],
},
action: function () {
const client = g_lib.getUserFromClientID(req.queryParams.client);
client = g_lib.getUserFromClientID(req.queryParams.client);
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) {
Expand Down Expand Up @@ -82,7 +92,27 @@ router
});

res.send(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) {
logger.logRequestFailure({
client: client?._id,
correlationId: req.headers["x-correlation-id"],
httpVerb: "POST",
routePath: basePath + "/create",
status: "Failure",
description: "Create Query",
extra: result,
error: e,
});

g_lib.handleException(e, res);
}
})
Expand All @@ -106,16 +136,25 @@ router

router
.post("/update", function (req, res) {
let client = undefined;
let result = undefined;
try {
var result;

g_db._executeTransaction({
collections: {
read: ["u", "uuid", "accn", "admin"],
write: ["q", "owner"],
},
action: function () {
const client = g_lib.getUserFromClientID(req.queryParams.client);
client = g_lib.getUserFromClientID(req.queryParams.client);
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);

if (client._id != qry.owner && !client.is_admin) {
Expand Down Expand Up @@ -159,9 +198,27 @@ router
result = qry;
},
});

res.send(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) {
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,
error: e,
});
g_lib.handleException(e, res);
}
})
Expand All @@ -186,9 +243,19 @@ 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);
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) {
throw error.ERR_PERM_DENIED;
Expand All @@ -205,7 +272,27 @@ router
delete qry.lmit;

res.send(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) {
logger.logRequestFailure({
client: client?._id,
correlationId: req.headers["x-correlation-id"],
httpVerb: "GET",
routePath: basePath + "/view",
status: "Failure",
description: "View specified query",
extra: qry,
error: e,
});

g_lib.handleException(e, res);
}
})
Expand All @@ -216,9 +303,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;
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/")) {
Expand All @@ -243,8 +339,28 @@ router
}

g_graph.q.remove(owner._from);
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) {
logger.logRequestFailure({
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],
error: e,
});

g_lib.handleException(e, res);
}
})
Expand All @@ -255,12 +371,21 @@ 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);
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";
var result;

if (req.queryParams.offset != undefined && req.queryParams.count != undefined) {
qry += " limit " + req.queryParams.offset + ", " + req.queryParams.count;
Expand Down Expand Up @@ -292,7 +417,29 @@ router
}

res.send(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: {
queryParams: req.queryParams,
_countTotal: result._countTotal,
},
});
} catch (e) {
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,
error: e,
});
g_lib.handleException(e, res);
}
})
Expand Down Expand Up @@ -504,8 +651,19 @@ 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);
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);

if (client._id != qry.owner && !client.is_admin) {
Expand All @@ -517,10 +675,29 @@ 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);
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) {
logger.logRequestFailure({
client: client?._id,
correlationId: req.headers["x-correlation-id"],
httpVerb: "GET",
routePath: basePath + "/exec",
status: "Failure",
description: "Execute specified queries",
extra: results,
error: e,
});
g_lib.handleException(e, res);
}
})
Expand All @@ -533,17 +710,46 @@ router

router
.post("/exec/direct", function (req, res) {
let results = undefined;
let client = undefined;
try {
const client = g_lib.getUserFromClientID_noexcept(req.queryParams.client);
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,
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);
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) {
logger.logRequestFailure({
client: client?._id,
correlationId: req.headers["x-correlation-id"],
httpVerb: "POST",
routePath: basePath + "/exec/direct",
status: "Failure",
description: "Execute published data search query",
extra: results,
error: e,
});
g_lib.handleException(e, res);
}
})
Expand Down
Loading