openvibers/openvibe.billing Commits

Billing: telemetry flushes each minute and keeps 14 days (#64)

OP OpenVibers committed 29 days ago · 74643de575 · 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 a5cd829..7148bea 100644
---- a/server/index.js
++++ b/server/index.js
@@@ -63,9 +63,9 @@ const { createPgTelemetrySink, startTelemetryRetention } = require('openvibe-sdk
});
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: 'billing', sink: createPgTelemetrySink({ db: ctx.db, log: console }), skipPrefixes: ['/shared'] });
-- const telemetryRetention = startTelemetryRetention({ db: ctx.db, log: console });
++ // class each minute, stored in this service's telemetry_samples table; rows older than 14 days go daily.
++ telemetry.init({ service: 'billing', sink: createPgTelemetrySink({ db: ctx.db, log: console }), skipPrefixes: ['/shared'], intervalMs: 60_000 });
++ const telemetryRetention = startTelemetryRetention({ db: ctx.db, log: console, olderThanDays: 14 });
// SIGTERM/SIGINT (openvibe-sdk/service): the kit installs the handlers, stops the job timers, the outbox
// relay and the Network key refresh, drains the HTTP server (requests in flight get Connection: close),
ddiff --git a/test/telemetry.test.js b/test/telemetry.test.js
iindex 9aadda2..57157a9 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 'billing' 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/app');
const db = t.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), 'billing', '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 {