Skip to content

Commit 9a42837

Browse files
authored
[DAPS-1522] Version Router Logging Improvements (#1758)
1 parent 752a4fe commit 9a42837

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

core/database/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ if( ENABLE_FOXX_TESTS )
2828
add_test(NAME foxx_version COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_version:")
2929
add_test(NAME foxx_support COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_support:")
3030
add_test(NAME foxx_user_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_user_router:")
31+
add_test(NAME foxx_version_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_version_router:")
3132
add_test(NAME foxx_tag_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_tag_router:")
3233
add_test(NAME foxx_task_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_task_router:")
3334
add_test(NAME foxx_authz_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_authz_router:")
@@ -54,6 +55,7 @@ if( ENABLE_FOXX_TESTS )
5455
set_tests_properties(foxx_validation_repo PROPERTIES FIXTURES_REQUIRED Foxx)
5556
set_tests_properties(foxx_path PROPERTIES FIXTURES_REQUIRED Foxx)
5657
set_tests_properties(foxx_user_router PROPERTIES FIXTURES_REQUIRED "Foxx;FoxxDBFixtures")
58+
set_tests_properties(foxx_version_router PROPERTIES FIXTURES_REQUIRED Foxx)
5759
set_tests_properties(foxx_tag_router PROPERTIES FIXTURES_REQUIRED Foxx)
5860
set_tests_properties(foxx_query_router PROPERTIES FIXTURES_REQUIRED Foxx)
5961
set_tests_properties(foxx_task_router PROPERTIES FIXTURES_REQUIRED Foxx)

core/database/foxx/api/version_router.js.in

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const router = createRouter();
55
const joi = require('joi');
66
const g_db = require('@arangodb').db;
77
const g_lib = require('./support');
8+
const logger = require("./lib/logger");
9+
const basePath = "";
810

911
module.exports = router;
1012

@@ -14,6 +16,14 @@ module.exports = router;
1416

1517
router.get('/version', function(req, res) {
1618
try {
19+
logger.logRequestStarted({
20+
client: "anonymous",
21+
correlationId: req.headers["x-correlation-id"],
22+
httpVerb: "GET",
23+
routePath: basePath + "/version",
24+
status: "Started",
25+
description: "Get version numbers",
26+
});
1727
res.send({
1828
"release_year": @DATAFED_RELEASE_YEAR@,
1929
"release_month": @DATAFED_RELEASE_MONTH@,
@@ -27,7 +37,26 @@ router.get('/version', function(req, res) {
2737
"component_minor": @DATAFED_FOXX_MINOR@,
2838
"component_patch": @DATAFED_FOXX_PATCH@
2939
});
40+
logger.logRequestSuccess({
41+
client: "anonymous",
42+
correlationId: req.headers["x-correlation-id"],
43+
httpVerb: "GET",
44+
routePath: basePath + "/version",
45+
status: "Success",
46+
description: "Get version numbers",
47+
extra: null
48+
});
3049
} catch (e) {
50+
logger.logRequestFailure({
51+
client: "anonymous",
52+
correlationId: req.headers["x-correlation-id"],
53+
httpVerb: "GET",
54+
routePath: basePath + "/version",
55+
status: "Failure",
56+
description: "Get version numbers",
57+
extra: null,
58+
error: e
59+
});
3160
g_lib.handleException(e, res);
3261
}
3362
})
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"use strict";
2+
3+
const { expect } = require("chai");
4+
const request = require("@arangodb/request");
5+
const { baseUrl } = module.context;
6+
const { db } = require("@arangodb");
7+
8+
// (replace “myrouter” with the actual base path)
9+
const base_url = `${baseUrl}/`;
10+
11+
after(function () {
12+
// cleanup collections if needed
13+
const collections = [
14+
/* list collections to truncate */
15+
];
16+
collections.forEach((name) => {
17+
let col = db._collection(name);
18+
if (col) col.truncate();
19+
});
20+
});
21+
22+
describe("unit_version_router: the Foxx microservice version/ endpoint", () => {
23+
beforeEach(() => {
24+
// ensure collections exist & trimmed/initialized
25+
const collections = [
26+
/* list collections */
27+
];
28+
collections.forEach((name) => {
29+
let col = db._collection(name);
30+
if (col) {
31+
col.truncate();
32+
} else {
33+
db._create(name);
34+
}
35+
});
36+
});
37+
38+
it("should succeed when valid parameters given", () => {
39+
// arrange: setup fixture data
40+
// e.g., db.u.save({...}); db.mycoll.save({...});
41+
// TODO: insert required documents
42+
43+
// arrange: build request string
44+
const request_string = `${base_url}/version`;
45+
46+
// act
47+
const response = request.get(request_string);
48+
49+
// assert
50+
expect(response.status).to.equal(200);
51+
// additional assertions on response body (if needed)
52+
});
53+
});

0 commit comments

Comments
 (0)