openvibers/openvibe.codes Commits

Codes: telemetry flushes each minute and keeps 14 days (#82)

OP OpenVibers committed 29 days ago · e44421c05c · 2 files, +6 −6

The request telemetry added earlier today flushed every 15 s and kept 30 days. The idle gauges alone write three rows per flush. Measured in production, that is about 650 rows an hour at about 270 B each including the indexes. At 30 days that's about 470k rows and 125 MB per service, roughly 4.4 GB across the estate on a disk with 16 GB free.

This changes it to one flush a minute and 14 days of retention: about 55k rows and 15 MB per service.

- The collector's interval (the tick, or `intervalMs` for `createHttpTelemetry` and `telemetry.init`) is 60 s.
- `startTelemetryRetention` passes `olderThanDays: 14`.
- The comments and `test/telemetry.test.js` follow: the retention check inserts rows 20 days and 1 day old and expects one deleted with `olderThanDays: 14`.

Applied migrations are unchanged (their comment still says 30 days; a migration that has run is never edited).

Changes

ddiff --git a/server/index.js b/server/index.js
iindex 911b787..03e020f 100644
---- a/server/index.js
++++ b/server/index.js
@@@ -31,9 +31,9 @@ async function start() {
});
server.keepAliveTimeout = 65_000;
// Request telemetry (openvibe-sdk/service, plan T1): one aggregated sample per route template, method and status
-- // class each 15 s, stored in this service's telemetry_samples table; rows older than 30 days go daily.
-- telemetry.init({ service: 'codes', sink: createPgTelemetrySink({ db: ctx.store.db, log: console }), skipPrefixes: ['/shared'] });
-- ctx.telemetryRetention = startTelemetryRetention({ db: ctx.store.db, log: console });
++ // class each minute, stored in this service's telemetry_samples table; rows older than 14 days go daily.
++ telemetry.init({ service: 'codes', sink: createPgTelemetrySink({ db: ctx.store.db, log: console }), skipPrefixes: ['/shared'], intervalMs: 60_000 });
++ ctx.telemetryRetention = startTelemetryRetention({ db: ctx.store.db, log: console, olderThanDays: 14 });
// Keep the JWKS cache fresh in the background (openvibe-sdk/auth): one client per URL, the last
// good keys through outages, exponential backoff, unknown-kid floods throttled, an unref'd timer.
ctx.keys.client.start();
ddiff --git a/test/telemetry.test.js b/test/telemetry.test.js
iindex 76e7ba6..195260a 100644
---- a/test/telemetry.test.js
++++ b/test/telemetry.test.js
@@@ -3,7 +3,7 @@
* Request telemetry (openvibe-sdk/service, plan T1 step 10): app.js mounts the process-wide telemetryMiddleware (a no-op
* until init), server/index.js calls telemetry.init() for service 'codes' with a PostgreSQL sink, starts the 30-day
* retention and flushes on stop. Five hits on one route flush as ONE aggregated http.request sample; /metrics and
-- * /shared make none; the retention deletes only rows older than 30 days.
++ * /shared make none; the retention deletes only rows older than 14 days.
*/
const assert = require('assert');
const fs = require('fs');
@@@ -38,9 +38,9 @@ const { boot } = require('./helpers/boot');
const db = t.ctx.store.db;
await db.query('DELETE FROM telemetry_samples');
const insert = (days) => db.query("INSERT INTO telemetry_samples (at, service, operation) VALUES (now() - make_interval(days => $1), 'codes', 'http.request')", [days]);
-- await insert(45);
++ await insert(20);
await insert(1);
-- assert.strictEqual(await pruneTelemetry({ db }), 1);
++ assert.strictEqual(await pruneTelemetry({ db, olderThanDays: 14 }), 1);
assert.strictEqual((await db.query('SELECT count(*)::int AS n FROM telemetry_samples')).rows[0].n, 1);
console.log('telemetry ok');
} finally {