openvibers/openvibe.quest Commits
Quest: write request telemetry every 15 s, not only at stop (#46)
Changes
@@@ -17,7 +17,7 @@ const { startTelemetryRetention } = require('openvibe-sdk/telemetry');function createLifecycle({ server, ctx, exit, signals, timers = [], extra = [] }) {return gracefulStop({name: 'OpenVibe.Quest', server, deadlineExitCode: 0, exit, signals, deadlineMs: 10_000,-- close: [() => { for (const t of timers) clearInterval(t); }, () => ctx.keys.client.stop(), () => ctx.searchIndex.stop(), async () => { if (ctx.retention) await ctx.retention.stop(); if (ctx.telemetry) await ctx.telemetry.stop(); }, () => ctx.s.close(), ...extra],++ close: [() => { for (const t of timers) clearInterval(t); }, () => ctx.keys.client.stop(), () => ctx.searchIndex.stop(), async () => { clearInterval(ctx.telemetryTick); if (ctx.retention) await ctx.retention.stop(); if (ctx.telemetry) await ctx.telemetry.stop(); }, () => ctx.s.close(), ...extra],});}@@@ -31,6 +31,10 @@ async function start() {server.keepAliveTimeout = 65_000;// telemetry_samples rows older than 30 days go: a minute after start, then daily (openvibe-sdk/telemetry).ctx.retention = startTelemetryRetention({ db: ctx.s.db, log: ctx.log || console });++ // 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();ctx.keys.client.start();ctx.searchIndex.start();@@@ -7,8 +7,16 @@const assert = require('assert');const { pruneTelemetry } = require('openvibe-sdk/telemetry');const { boot, check, done } = require('./helpers/boot');++const fs = require('fs');++const path = require('path');(async () => {++ await check('index.js flushes the collector every 15 s and clears that tick before the last flush on stop', () => {++ const index = fs.readFileSync(path.join(__dirname, '..', 'server', 'index.js'), 'utf8');++ assert.match(index, /ctx\.telemetryTick = setInterval\(\(\) => \{ ctx\.telemetry\.flush\(\)/);++ assert.match(index, /clearInterval\(ctx\.telemetryTick\); if \(ctx\.retention\) await ctx\.retention\.stop\(\); if \(ctx\.telemetry\) await ctx\.telemetry\.stop\(\);/);++ });++const samples = [];const t = await boot({ telemetrySink: async (batch) => { samples.push(...batch); } });const requests = () => samples.filter((s) => s.operation === 'http.request');
@@ -17,7 +17,7 @@ const { startTelemetryRetention } = require('openvibe-sdk/telemetry');
@@ -17,7 +17,7 @@ const { startTelemetryRetention } = require('openvibe-sdk/telemetry');
function createLifecycle({ server, ctx, exit, signals, timers = [], extra = [] }) {
function createLifecycle({ server, ctx, exit, signals, timers = [], extra = [] }) {
return gracefulStop({
return gracefulStop({
name: 'OpenVibe.Quest', server, deadlineExitCode: 0, exit, signals, deadlineMs: 10_000,
name: 'OpenVibe.Quest', server, deadlineExitCode: 0, exit, signals, deadlineMs: 10_000,
- close: [() => { for (const t of timers) clearInterval(t); }, () => ctx.keys.client.stop(), () => ctx.searchIndex.stop(), async () => { if (ctx.retention) await ctx.retention.stop(); if (ctx.telemetry) await ctx.telemetry.stop(); }, () => ctx.s.close(), ...extra],
+ close: [() => { for (const t of timers) clearInterval(t); }, () => ctx.keys.client.stop(), () => ctx.searchIndex.stop(), async () => { clearInterval(ctx.telemetryTick); if (ctx.retention) await ctx.retention.stop(); if (ctx.telemetry) await ctx.telemetry.stop(); }, () => ctx.s.close(), ...extra],
});
});
}
}
@@ -31,6 +31,10 @@ async function start() {
@@ -31,6 +31,10 @@ async function start() {
server.keepAliveTimeout = 65_000;
server.keepAliveTimeout = 65_000;
// telemetry_samples rows older than 30 days go: a minute after start, then daily (openvibe-sdk/telemetry).
// telemetry_samples rows older than 30 days go: a minute after start, then daily (openvibe-sdk/telemetry).
ctx.retention = startTelemetryRetention({ db: ctx.s.db, log: ctx.log || console });
ctx.retention = startTelemetryRetention({ db: ctx.s.db, log: ctx.log || console });
+ // 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();
ctx.keys.client.start();
ctx.keys.client.start();
ctx.searchIndex.start();
ctx.searchIndex.start();
@@ -7,8 +7,16 @@
@@ -7,8 +7,16 @@
const assert = require('assert');
const assert = require('assert');
const { pruneTelemetry } = require('openvibe-sdk/telemetry');
const { pruneTelemetry } = require('openvibe-sdk/telemetry');
const { boot, check, done } = require('./helpers/boot');
const { boot, check, done } = require('./helpers/boot');
+const fs = require('fs');
+const path = require('path');
(async () => {
(async () => {
+ await check('index.js flushes the collector every 15 s and clears that tick before the last flush on stop', () => {
+ const index = fs.readFileSync(path.join(__dirname, '..', 'server', 'index.js'), 'utf8');
+ assert.match(index, /ctx\.telemetryTick = setInterval\(\(\) => \{ ctx\.telemetry\.flush\(\)/);
+ assert.match(index, /clearInterval\(ctx\.telemetryTick\); if \(ctx\.retention\) await ctx\.retention\.stop\(\); if \(ctx\.telemetry\) await ctx\.telemetry\.stop\(\);/);
+ });
+
const samples = [];
const samples = [];
const t = await boot({ telemetrySink: async (batch) => { samples.push(...batch); } });
const t = await boot({ telemetrySink: async (batch) => { samples.push(...batch); } });
const requests = () => samples.filter((s) => s.operation === 'http.request');
const requests = () => samples.filter((s) => s.operation === 'http.request');