openvibers/openvibe.blog Commits
Blog: write request telemetry every 15 s, not only at stop (#53)
Changes
@@@ -17,7 +17,7 @@ const { startSubscriptions } = require('openvibe-sdk/account-data');function createLifecycle({ server, ctx, exit, signals, extra = [] }) {return gracefulStop({name: 'Blog', server, deadlineExitCode: 0, exit, signals,-- stop: [() => ctx.telemetry.stop(), () => ctx.worker.stop(), () => ctx.changelog.stop(), ...extra],++ stop: [() => { clearInterval(ctx.telemetryTick); return ctx.telemetry.stop(); }, () => ctx.worker.stop(), () => ctx.changelog.stop(), ...extra],close: [() => ctx.outbox.stop(), () => ctx.store.close()],});}@@@ -33,6 +33,10 @@ async function start() {server.keepAliveTimeout = 65_000;ctx.outbox.start();ctx.worker.start();++ // The request collector aggregates in memory and has no timer of its own (openvibe-sdk 0.46 createHttpTelemetry):++ // this tick writes each 15-second interval's samples; the stop clears it and flushes once more.++ ctx.telemetryTick = setInterval(() => { ctx.telemetry.flush().catch(() => {}); }, 15_000);++ ctx.telemetryTick.unref();// The network changelog and patch notes run where the worker runs (one process).if (config.worker.enabled) ctx.changelog.start();@@@ -17,7 +17,10 @@ const read = (p) => fs.readFileSync(path.join(__dirname, '..', p), 'utf8');assert.match(app, /createHttpTelemetry\(\{[^}]*service: 'blog'/s);assert.match(app, /app\.use\(telemetry\.middleware\(\)\)/);assert.match(app, /ctx\.telemetry = telemetry/);-- assert.match(read('server/index.js'), /stop: \[\(\) => ctx\.telemetry\.stop\(\),/);++ const index = read('server/index.js');++ assert.match(index, /stop: \[\(\) => \{ clearInterval\(ctx\.telemetryTick\); return ctx\.telemetry\.stop\(\); \},/);++ // The collector has no timer of its own (openvibe-sdk 0.46): index.js flushes it every 15 s.++ assert.match(index, /ctx\.telemetryTick = setInterval\(\(\) => \{ ctx\.telemetry\.flush\(\)/);});const samples = [];
@@ -17,7 +17,7 @@ const { startSubscriptions } = require('openvibe-sdk/account-data');
@@ -17,7 +17,7 @@ const { startSubscriptions } = require('openvibe-sdk/account-data');
function createLifecycle({ server, ctx, exit, signals, extra = [] }) {
function createLifecycle({ server, ctx, exit, signals, extra = [] }) {
return gracefulStop({
return gracefulStop({
name: 'Blog', server, deadlineExitCode: 0, exit, signals,
name: 'Blog', server, deadlineExitCode: 0, exit, signals,
- stop: [() => ctx.telemetry.stop(), () => ctx.worker.stop(), () => ctx.changelog.stop(), ...extra],
+ stop: [() => { clearInterval(ctx.telemetryTick); return ctx.telemetry.stop(); }, () => ctx.worker.stop(), () => ctx.changelog.stop(), ...extra],
close: [() => ctx.outbox.stop(), () => ctx.store.close()],
close: [() => ctx.outbox.stop(), () => ctx.store.close()],
});
});
}
}
@@ -33,6 +33,10 @@ async function start() {
@@ -33,6 +33,10 @@ async function start() {
server.keepAliveTimeout = 65_000;
server.keepAliveTimeout = 65_000;
ctx.outbox.start();
ctx.outbox.start();
ctx.worker.start();
ctx.worker.start();
+ // The request collector aggregates in memory and has no timer of its own (openvibe-sdk 0.46 createHttpTelemetry):
+ // this tick writes each 15-second interval's samples; the stop clears it and flushes once more.
+ ctx.telemetryTick = setInterval(() => { ctx.telemetry.flush().catch(() => {}); }, 15_000);
+ ctx.telemetryTick.unref();
// The network changelog and patch notes run where the worker runs (one process).
// The network changelog and patch notes run where the worker runs (one process).
if (config.worker.enabled) ctx.changelog.start();
if (config.worker.enabled) ctx.changelog.start();
@@ -17,7 +17,10 @@ const read = (p) => fs.readFileSync(path.join(__dirname, '..', p), 'utf8');
@@ -17,7 +17,10 @@ const read = (p) => fs.readFileSync(path.join(__dirname, '..', p), 'utf8');
assert.match(app, /createHttpTelemetry\(\{[^}]*service: 'blog'/s);
assert.match(app, /createHttpTelemetry\(\{[^}]*service: 'blog'/s);
assert.match(app, /app\.use\(telemetry\.middleware\(\)\)/);
assert.match(app, /app\.use\(telemetry\.middleware\(\)\)/);
assert.match(app, /ctx\.telemetry = telemetry/);
assert.match(app, /ctx\.telemetry = telemetry/);
- assert.match(read('server/index.js'), /stop: \[\(\) => ctx\.telemetry\.stop\(\),/);
+ const index = read('server/index.js');
+ assert.match(index, /stop: \[\(\) => \{ clearInterval\(ctx\.telemetryTick\); return ctx\.telemetry\.stop\(\); \},/);
+ // The collector has no timer of its own (openvibe-sdk 0.46): index.js flushes it every 15 s.
+ assert.match(index, /ctx\.telemetryTick = setInterval\(\(\) => \{ ctx\.telemetry\.flush\(\)/);
});
});
const samples = [];
const samples = [];