mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-24 21:09:47 +00:00
Merge pull request #2084 from rkeulemans/feature/support_since_and_until_in_journald_supervisor_wrapper
Feature: Support `since` and `until` in supervisor journald wrapper
This commit is contained in:
commit
e2383c8cca
10
docs/API.md
10
docs/API.md
@ -1291,5 +1291,15 @@ From an app container:
|
||||
$ curl -X POST -H "Content-Type: application/json" --data '{"follow":true,"all":true}' "$BALENA_SUPERVISOR_ADDRESS/v2/journal-logs?apikey=$BALENA_SUPERVISOR_API_KEY" > log.journal
|
||||
```
|
||||
|
||||
##### since: string
|
||||
> **Introduced in supervisor v14.7.0**
|
||||
Show journal logs since the given `since` timestamp, formats are described here:
|
||||
[https://www.freedesktop.org/software/systemd/man/journalctl.html#-S](https://www.freedesktop.org/software/systemd/man/journalctl.html#-S)
|
||||
|
||||
##### until: string
|
||||
> **Introduced in supervisor v14.7.0**
|
||||
Show journal logs until the given `until` timestamp, formats are described here:
|
||||
[https://www.freedesktop.org/software/systemd/man/journalctl.html#-S](https://www.freedesktop.org/software/systemd/man/journalctl.html#-S)
|
||||
|
||||
An example project using this endpoint can be found
|
||||
[in this repository](https://github.com/balena-io-playground/device-cloud-logging).
|
||||
|
@ -549,6 +549,8 @@ router.post('/v2/journal-logs', (req, res) => {
|
||||
const unit = req.body.unit;
|
||||
const format = req.body.format || 'short';
|
||||
const containerId = req.body.containerId;
|
||||
const since = req.body.since;
|
||||
const until = req.body.until;
|
||||
|
||||
const journald = spawnJournalctl({
|
||||
all,
|
||||
@ -557,6 +559,8 @@ router.post('/v2/journal-logs', (req, res) => {
|
||||
unit,
|
||||
format,
|
||||
containerId,
|
||||
since,
|
||||
until,
|
||||
});
|
||||
res.status(200);
|
||||
// We know stdout will be present
|
||||
|
@ -10,7 +10,8 @@ export function spawnJournalctl(opts: {
|
||||
containerId?: string;
|
||||
format: string;
|
||||
filterString?: string;
|
||||
since?: number;
|
||||
since?: number | string;
|
||||
until?: number | string;
|
||||
}): ChildProcess {
|
||||
const args: string[] = [];
|
||||
if (opts.all) {
|
||||
@ -33,12 +34,11 @@ export function spawnJournalctl(opts: {
|
||||
}
|
||||
if (opts.since != null) {
|
||||
args.push('-S');
|
||||
args.push(
|
||||
new Date(opts.since)
|
||||
.toISOString()
|
||||
.replace(/T/, ' ') // replace T with a space
|
||||
.replace(/\..+/, ''), // delete the dot and everything after
|
||||
);
|
||||
args.push(opts.since.toString());
|
||||
}
|
||||
if (opts.until != null) {
|
||||
args.push('-U');
|
||||
args.push(opts.until.toString());
|
||||
}
|
||||
args.push('-o');
|
||||
args.push(opts.format);
|
||||
|
@ -26,6 +26,8 @@ describe('lib/journald', () => {
|
||||
unit: 'nginx.service',
|
||||
containerId: 'abc123',
|
||||
format: 'json-pretty',
|
||||
since: '2014-03-25 03:59:56.654563',
|
||||
until: '2014-03-25 03:59:59.654563',
|
||||
});
|
||||
|
||||
const expectedCommand = `journalctl`;
|
||||
@ -40,6 +42,10 @@ describe('lib/journald', () => {
|
||||
'10',
|
||||
'-o',
|
||||
'json-pretty',
|
||||
'-S',
|
||||
'2014-03-25 03:59:56.654563',
|
||||
'-U',
|
||||
'2014-03-25 03:59:59.654563',
|
||||
];
|
||||
|
||||
const actualCommand = spawn.firstCall.args[0];
|
||||
|
Loading…
x
Reference in New Issue
Block a user