Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db1e2e7ec9 | ||
|
|
789e5651c8 | ||
|
|
2c1eb712f2 | ||
|
|
39d28fb9e7 |
No files matched your search
@@ -94,7 +94,7 @@
|
|||||||
if (meta) {
|
if (meta) {
|
||||||
stats =
|
stats =
|
||||||
'<span>CPU: ' + esc(meta.cpus || '?') + ' cores</span>' +
|
'<span>CPU: ' + esc(meta.cpus || '?') + ' cores</span>' +
|
||||||
'<span>RAM: ' + fmt.bytes(meta.totalMem - meta.freeMem) + ' / ' + fmt.bytes(meta.totalMem) + '</span>' +
|
'<span>RAM: ' + fmt.bytes(meta.totalMem - (typeof meta.availableMem === 'number' ? meta.availableMem : meta.freeMem)) + ' / ' + fmt.bytes(meta.totalMem) + '</span>' +
|
||||||
'<span>Tasks: ' + esc(meta.activeTasks || 0) + '/' + esc(meta.maxConcurrentTasks || 0) + '</span>';
|
'<span>Tasks: ' + esc(meta.activeTasks || 0) + '/' + esc(meta.maxConcurrentTasks || 0) + '</span>';
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -45,11 +45,6 @@
|
|||||||
browser dialogs finds no call sites in this file. */
|
browser dialogs finds no call sites in this file. */
|
||||||
const askConfirm = Pulse.confirm;
|
const askConfirm = Pulse.confirm;
|
||||||
|
|
||||||
function isAutomatedRun(e) {
|
|
||||||
const by = (e && e.started_by) || '';
|
|
||||||
return by.indexOf('gandalf:') === 0 || by.indexOf('scheduler:') === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function execName(e) {
|
function execName(e) {
|
||||||
return (e && e.workflow_name) || '[Quick Command]';
|
return (e && e.workflow_name) || '[Quick Command]';
|
||||||
}
|
}
|
||||||
@@ -81,11 +76,12 @@
|
|||||||
const offset = append ? st.offset : 0;
|
const offset = append ? st.offset : 0;
|
||||||
const params = new URLSearchParams({ limit: String(LIMIT), offset: String(offset) });
|
const params = new URLSearchParams({ limit: String(LIMIT), offset: String(offset) });
|
||||||
if (view === 'manual') params.set('hide_internal', 'true');
|
if (view === 'manual') params.set('hide_internal', 'true');
|
||||||
|
if (view === 'automated') params.set('only_internal', 'true'); // server-side (#4)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await Pulse.api.get('/api/executions?' + params.toString());
|
const data = await Pulse.api.get('/api/executions?' + params.toString());
|
||||||
const raw = (data && data.executions) || [];
|
const raw = (data && data.executions) || [];
|
||||||
const rows = view === 'automated' ? raw.filter(isAutomatedRun) : raw;
|
const rows = raw;
|
||||||
|
|
||||||
st.rows = append ? st.rows.concat(rows) : rows;
|
st.rows = append ? st.rows.concat(rows) : rows;
|
||||||
st.offset = offset + raw.length; // page over raw server rows
|
st.offset = offset + raw.length; // page over raw server rows
|
||||||
@@ -114,7 +110,7 @@
|
|||||||
const term = searchTerm();
|
const term = searchTerm();
|
||||||
const status = statusTerm();
|
const status = statusTerm();
|
||||||
return state[view].rows.filter((e) => {
|
return state[view].rows.filter((e) => {
|
||||||
if (status && e.status !== status) return false;
|
if (status && displayStatus(e) !== status) return false;
|
||||||
if (term) {
|
if (term) {
|
||||||
const name = execName(e).toLowerCase();
|
const name = execName(e).toLowerCase();
|
||||||
const id = String(e.id || '').toLowerCase();
|
const id = String(e.id || '').toLowerCase();
|
||||||
@@ -127,11 +123,13 @@
|
|||||||
function countLabel(view) {
|
function countLabel(view) {
|
||||||
const st = state[view];
|
const st = state[view];
|
||||||
if (!st.loaded) return '';
|
if (!st.loaded) return '';
|
||||||
/* Manual is a straight server-side filter, so `total` is exact.
|
// Both tabs filter on the server, so `total` is exact (#4).
|
||||||
Automated is filtered client-side over the loaded page, so only the
|
return '(' + st.total + ')';
|
||||||
loaded rows are known: mark it with a + when more pages exist. */
|
}
|
||||||
if (view === 'manual') return '(' + st.total + ')';
|
|
||||||
return '(' + st.rows.length + (st.hasMore ? '+' : '') + ')';
|
// 'waiting' when a running execution is blocked on a prompt (#3).
|
||||||
|
function displayStatus(e) {
|
||||||
|
return e.status === 'running' && e.waiting_for_input ? 'waiting' : e.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
function rowHtml(e) {
|
function rowHtml(e) {
|
||||||
@@ -157,7 +155,7 @@
|
|||||||
return '<tr class="' + cls.join(' ') + '" data-action="' + action + '"' +
|
return '<tr class="' + cls.join(' ') + '" data-action="' + action + '"' +
|
||||||
' data-execution-id="' + esc(e.id) + '" tabindex="0">' +
|
' data-execution-id="' + esc(e.id) + '" tabindex="0">' +
|
||||||
check +
|
check +
|
||||||
'<td data-label="Status"><span class="' + Pulse.fmt.status(e.status) + '">' + esc(e.status) + '</span></td>' +
|
'<td data-label="Status"><span class="' + Pulse.fmt.status(displayStatus(e)) + '">' + esc(displayStatus(e)) + '</span></td>' +
|
||||||
'<td data-label="Name"><strong>' + esc(execName(e)) + '</strong></td>' +
|
'<td data-label="Name"><strong>' + esc(execName(e)) + '</strong></td>' +
|
||||||
'<td data-label="Started by">' + esc(e.started_by || '') + '</td>' +
|
'<td data-label="Started by">' + esc(e.started_by || '') + '</td>' +
|
||||||
'<td data-label="Started">' + esc(Pulse.fmt.dateTime(e.started_at)) + '</td>' +
|
'<td data-label="Started">' + esc(Pulse.fmt.dateTime(e.started_at)) + '</td>' +
|
||||||
|
|||||||
@@ -16,9 +16,16 @@
|
|||||||
return worker.metadata;
|
return worker.metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used memory: total minus what's available (cache counts as available, #30).
|
||||||
|
// Workers that predate availableMem report only freeMem.
|
||||||
|
function usedMem(meta) {
|
||||||
|
const avail = typeof meta.availableMem === 'number' ? meta.availableMem : meta.freeMem;
|
||||||
|
return meta.totalMem - avail;
|
||||||
|
}
|
||||||
|
|
||||||
function memPct(meta) {
|
function memPct(meta) {
|
||||||
if (!meta || !meta.totalMem) return 0;
|
if (!meta || !meta.totalMem) return 0;
|
||||||
return ((meta.totalMem - meta.freeMem) / meta.totalMem * 100);
|
return (usedMem(meta) / meta.totalMem * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadAvgText(meta) {
|
function loadAvgText(meta) {
|
||||||
@@ -65,7 +72,7 @@
|
|||||||
'<div class="lt-kv-val" data-wk-system>' + (meta ? esc((meta.platform || 'N/A') + ' ' + (meta.arch || '') + ' | ' + (meta.cpus || '?') + ' CPU cores') : 'N/A') + '</div>' +
|
'<div class="lt-kv-val" data-wk-system>' + (meta ? esc((meta.platform || 'N/A') + ' ' + (meta.arch || '') + ' | ' + (meta.cpus || '?') + ' CPU cores') : 'N/A') + '</div>' +
|
||||||
'<div class="lt-kv-key">Memory</div>' +
|
'<div class="lt-kv-key">Memory</div>' +
|
||||||
'<div class="lt-kv-val" data-wk-memory>' +
|
'<div class="lt-kv-val" data-wk-memory>' +
|
||||||
(meta ? esc(fmt.bytes(meta.totalMem - meta.freeMem) + ' / ' + fmt.bytes(meta.totalMem) + ' (' + pct + '% used)') : 'N/A') +
|
(meta ? esc(fmt.bytes(usedMem(meta)) + ' / ' + fmt.bytes(meta.totalMem) + ' (' + pct + '% used)') : 'N/A') +
|
||||||
'<div class="lt-progress"><div class="lt-progress-bar" data-wk-membar style="width:' + (meta ? pct : 0) + '%"></div></div>' +
|
'<div class="lt-progress"><div class="lt-progress-bar" data-wk-membar style="width:' + (meta ? pct : 0) + '%"></div></div>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'<div class="lt-kv-key">Load Avg</div>' +
|
'<div class="lt-kv-key">Load Avg</div>' +
|
||||||
@@ -124,7 +131,7 @@
|
|||||||
const memory = card.querySelector('[data-wk-memory]');
|
const memory = card.querySelector('[data-wk-memory]');
|
||||||
if (memory) {
|
if (memory) {
|
||||||
const bar = memory.querySelector('[data-wk-membar]');
|
const bar = memory.querySelector('[data-wk-membar]');
|
||||||
const text = meta ? (fmt.bytes(meta.totalMem - meta.freeMem) + ' / ' + fmt.bytes(meta.totalMem) + ' (' + pct + '% used)') : 'N/A';
|
const text = meta ? (fmt.bytes(usedMem(meta)) + ' / ' + fmt.bytes(meta.totalMem) + ' (' + pct + '% used)') : 'N/A';
|
||||||
if (memory.firstChild && memory.firstChild.nodeType === Node.TEXT_NODE) {
|
if (memory.firstChild && memory.firstChild.nodeType === Node.TEXT_NODE) {
|
||||||
memory.firstChild.textContent = text;
|
memory.firstChild.textContent = text;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1656,6 +1656,10 @@ app.get('/api/executions', authenticateSSO, async (req, res) => {
|
|||||||
if (req.query.hide_internal === 'true') {
|
if (req.query.hide_internal === 'true') {
|
||||||
conditions.push("e.started_by NOT LIKE 'gandalf:%' AND e.started_by NOT LIKE 'scheduler:%'");
|
conditions.push("e.started_by NOT LIKE 'gandalf:%' AND e.started_by NOT LIKE 'scheduler:%'");
|
||||||
}
|
}
|
||||||
|
// The Automated tab's own filter, so it pages and counts on the server too (#4).
|
||||||
|
if (req.query.only_internal === 'true') {
|
||||||
|
conditions.push("(e.started_by LIKE 'gandalf:%' OR e.started_by LIKE 'scheduler:%')");
|
||||||
|
}
|
||||||
// New filters
|
// New filters
|
||||||
if (req.query.status) {
|
if (req.query.status) {
|
||||||
conditions.push('e.status = ?');
|
conditions.push('e.status = ?');
|
||||||
@@ -1701,6 +1705,9 @@ app.get('/api/executions', authenticateSSO, async (req, res) => {
|
|||||||
);
|
);
|
||||||
const total = countRows[0].total;
|
const total = countRows[0].total;
|
||||||
|
|
||||||
|
// Blocked on a prompt (#3): the status stays 'running', so say so explicitly.
|
||||||
|
for (const r of rows) r.waiting_for_input = _executionPrompts.has(r.id);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
executions: rows,
|
executions: rows,
|
||||||
total,
|
total,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// The contract Gandalf depends on (gandalf/monitor.py PulseClient.run_command):
|
// The contract Gandalf depends on (gandalf/monitor.py PulseClient.run_command):
|
||||||
// POST /api/internal/command -> {execution_id}; poll GET /api/internal/executions/:id
|
// POST /api/internal/command -> {execution_id}; poll GET /api/internal/executions/:id
|
||||||
// until status is 'completed' (stdout read from the command_result log) or 'failed'.
|
// until status is 'completed' (stdout read from the command_result log) or 'failed'.
|
||||||
const { gandalf, workerByName, waitForExecution, commandResult } = require('./helpers');
|
const { gandalf, sso, workerByName, waitForExecution, commandResult } = require('./helpers');
|
||||||
|
|
||||||
let workerId;
|
let workerId;
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
@@ -53,3 +53,15 @@ test('an unknown execution id is a 404', async () => {
|
|||||||
const r = await gandalf('GET', '/api/internal/executions/00000000-0000-0000-0000-000000000000');
|
const r = await gandalf('GET', '/api/internal/executions/00000000-0000-0000-0000-000000000000');
|
||||||
expect(r.status).toBe(404);
|
expect(r.status).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('the Automated and Manual views filter on the server (#4)', async () => {
|
||||||
|
const submit = await gandalf('POST', '/api/internal/command', { worker_id: workerId, command: 'echo automated' });
|
||||||
|
await waitForExecution(submit.json.execution_id);
|
||||||
|
const auto = (await sso('GET', '/api/executions?only_internal=true&limit=200')).json;
|
||||||
|
const manual = (await sso('GET', '/api/executions?hide_internal=true&limit=200')).json;
|
||||||
|
const automated = by => /^(gandalf|scheduler):/.test(by || '');
|
||||||
|
expect(auto.executions.length).toBeGreaterThan(0);
|
||||||
|
expect(auto.executions.every(e => automated(e.started_by))).toBe(true);
|
||||||
|
expect(manual.executions.some(e => automated(e.started_by))).toBe(false);
|
||||||
|
expect(auto.executions.some(e => e.id === submit.json.execution_id)).toBe(true);
|
||||||
|
});
|
||||||
@@ -216,3 +216,14 @@ test('an unanswered prompt fails the execution instead of continuing (#21)', asy
|
|||||||
expect(logs(ex, 'prompt_timeout')).toHaveLength(1);
|
expect(logs(ex, 'prompt_timeout')).toHaveLength(1);
|
||||||
expect(outputs(ex)).toEqual([]);
|
expect(outputs(ex)).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('the execution list marks runs waiting on a prompt (#3)', async () => {
|
||||||
|
const id = await start(await createWorkflow([
|
||||||
|
{ id: 'ask', type: 'prompt', message: 'Proceed?', options: ['Yes'] },
|
||||||
|
]));
|
||||||
|
const row = async () => ((await sso('GET', '/api/executions?limit=100')).json.executions || []).find(e => e.id === id);
|
||||||
|
await waitFor(async () => (await row())?.waiting_for_input === true, { what: 'the list to show it waiting' });
|
||||||
|
await sso('POST', `/api/executions/${id}/respond`, { response: 'Yes' });
|
||||||
|
await waitForExecution(id);
|
||||||
|
expect((await row()).waiting_for_input).toBe(false);
|
||||||
|
});
|
||||||
@@ -42,3 +42,19 @@ test('an invalid workflow definition is rejected with a message', async ({ page,
|
|||||||
await expect(page.locator('#wf-list tr', { hasText: 'Broken definition' })).toHaveCount(0);
|
await expect(page.locator('#wf-list tr', { hasText: 'Broken definition' })).toHaveCount(0);
|
||||||
expect(problems).toEqual([]); // rejected in the browser, so no failed request either
|
expect(problems).toEqual([]); // rejected in the browser, so no failed request either
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a run waiting on a prompt shows as waiting, and the Waiting filter finds it (#3)', async ({ page, request }) => {
|
||||||
|
const created = await request.post('/api/workflows', { data: { name: `UI wait ${Date.now()}`, definition: { steps: [
|
||||||
|
{ id: 'ask', type: 'prompt', message: 'Proceed?', options: ['Yes'] },
|
||||||
|
] } } });
|
||||||
|
const wf = (await created.json()).id;
|
||||||
|
const ex = (await (await request.post('/api/executions', { data: { workflow_id: wf } })).json()).id;
|
||||||
|
|
||||||
|
await page.goto('/executions');
|
||||||
|
const row = page.locator(`#ex-list-manual .ex-row[data-execution-id="${ex}"]`);
|
||||||
|
await expect(row.locator('td[data-label="Status"]')).toHaveText('waiting');
|
||||||
|
await page.locator('#ex-status').selectOption('waiting');
|
||||||
|
await expect(row).toBeVisible();
|
||||||
|
|
||||||
|
await request.post(`/api/executions/${ex}/respond`, { data: { response: 'Yes' } });
|
||||||
|
});
|
||||||
@@ -198,3 +198,14 @@ describe('connection resilience (#1, #29)', () => {
|
|||||||
expect(w.connectWebSocket).toHaveBeenCalled();
|
expect(w.connectWebSocket).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('availableMemory (#30)', () => {
|
||||||
|
const { availableMemory } = require('../worker/worker');
|
||||||
|
test('reads MemAvailable (page cache counts as available), in bytes', () => {
|
||||||
|
const meminfo = 'MemTotal: 524288 kB\nMemFree: 4460 kB\nMemAvailable: 459733 kB\n';
|
||||||
|
expect(availableMemory(meminfo)).toBe(459733 * 1024);
|
||||||
|
});
|
||||||
|
test('falls back to os.freemem() without a MemAvailable line', () => {
|
||||||
|
expect(availableMemory('MemTotal: 1 kB\n')).toBe(require('os').freemem());
|
||||||
|
});
|
||||||
|
});
|
||||||
+14
-1
@@ -69,6 +69,18 @@ function detectVersion(dir = __dirname) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Memory a new process could actually get (#30). os.freemem() leaves out the page
|
||||||
|
// cache, so a healthy Linux box looks almost full; MemAvailable counts reclaimable
|
||||||
|
// cache as available. Falls back to freemem where /proc/meminfo has no such line.
|
||||||
|
function availableMemory(meminfo) {
|
||||||
|
try {
|
||||||
|
const text = meminfo !== undefined ? meminfo : require('fs').readFileSync('/proc/meminfo', 'utf8');
|
||||||
|
const m = /^MemAvailable:\s+(\d+)\s+kB/m.exec(text);
|
||||||
|
if (m) return Number(m[1]) * 1024;
|
||||||
|
} catch { /* not Linux */ }
|
||||||
|
return os.freemem();
|
||||||
|
}
|
||||||
|
|
||||||
// Reconnect delay after `attempt` consecutive failures: 1 s doubling to 60 s, with up
|
// Reconnect delay after `attempt` consecutive failures: 1 s doubling to 60 s, with up
|
||||||
// to 20% jitter so a fleet of workers doesn't reconnect in lockstep (#29).
|
// to 20% jitter so a fleet of workers doesn't reconnect in lockstep (#29).
|
||||||
function reconnectDelay(attempt, random = Math.random) {
|
function reconnectDelay(attempt, random = Math.random) {
|
||||||
@@ -138,6 +150,7 @@ class PulseWorker {
|
|||||||
cpus: os.cpus().length,
|
cpus: os.cpus().length,
|
||||||
totalMem: os.totalmem(),
|
totalMem: os.totalmem(),
|
||||||
freeMem: os.freemem(),
|
freeMem: os.freemem(),
|
||||||
|
availableMem: availableMemory(),
|
||||||
uptime: os.uptime(),
|
uptime: os.uptime(),
|
||||||
loadavg: os.loadavg(),
|
loadavg: os.loadavg(),
|
||||||
activeTasks: this.activeTasks,
|
activeTasks: this.activeTasks,
|
||||||
@@ -369,7 +382,7 @@ class PulseWorker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { PulseWorker, detectVersion, runCommand, reconnectDelay };
|
module.exports = { PulseWorker, detectVersion, runCommand, reconnectDelay, availableMemory };
|
||||||
|
|
||||||
// Start only when run directly (node worker.js), so tests can load the class.
|
// Start only when run directly (node worker.js), so tests can load the class.
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
|
|||||||
Reference in new issue
Block a user