Skip to content

Commit 2be3378

Browse files
authored
[VET-5756] feat: add support for fetching endpoint log archive (#313)
* feat: add support for fetching endpoint log archive * doc: add comment for server logs method * fix: use jest eslint env * refactor: reorder assertions * doc: add server.logs documentation
1 parent 5559d5b commit 2be3378

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,16 @@ Expects the following parameters:
268268

269269
Returns [`Promise<HTTP.Body>`](#body)
270270

271+
#### <a name="logs">`server.logs(conn)`</a>
272+
273+
Retrieves a zip file containing log information for an endpoint.
274+
275+
Expects the following parameters:
276+
277+
- conn ([`Connection`](#connection))
278+
279+
Returns [`Promise<Response>`](#response)
280+
271281
## <a name="db">db</a>
272282

273283
#### <a name="create">`db.create(conn, database, databaseOptions, options, params)`</a>

lib/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ declare namespace Stardog {
130130
* properties, but you can specify `names` to return specific ones.
131131
*/
132132
function properties(conn: Connection, names?: string[]): Promise<HTTP.Body>;
133+
134+
/**
135+
* Retrieves a zip file containing log information for an endpoint.
136+
*/
137+
function logs(conn: Connection): Promise<Response>;
133138
}
134139

135140
/** Stardog database actions. */

lib/server.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,18 @@ const properties = (conn, names = []) => {
4242
).then(httpBody);
4343
};
4444

45+
const logs = conn => {
46+
const headers = conn.headers();
47+
const response = fetch(conn.request('admin', 'logs'), {
48+
headers,
49+
});
50+
51+
return response;
52+
};
53+
4554
module.exports = {
4655
shutdown,
4756
status,
4857
properties,
58+
logs,
4959
};

test/serverLogs.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-env jest */
2+
3+
const { server } = require('../lib');
4+
const { ConnectionFactory } = require('./setup-database');
5+
6+
describe('server.logs()', () => {
7+
let conn;
8+
9+
beforeEach(() => {
10+
conn = ConnectionFactory();
11+
});
12+
13+
it('should retrieve a JS response object containing the logs zip file', () =>
14+
server.logs(conn).then(response => {
15+
expect(response.status).toBe(200);
16+
17+
return response.arrayBuffer().then(buffer => {
18+
expect(buffer).toBeTruthy();
19+
expect(buffer.byteLength).toBeGreaterThan(0);
20+
});
21+
}));
22+
});

0 commit comments

Comments
 (0)