openvibers/openvibe.billing Commits
Billing: telemetry flushes each minute and keeps 14 days (#64)
Changes
@@@ -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),@@@ -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 {
@@ -63,9 +63,9 @@ const { createPgTelemetrySink, startTelemetryRetention } = require('openvibe-sdk
@@ -63,9 +63,9 @@ const { createPgTelemetrySink, startTelemetryRetention } = require('openvibe-sdk
});
});
server.keepAliveTimeout = 65_000;
server.keepAliveTimeout = 65_000;
// Request telemetry (openvibe-sdk/service, plan T1): one aggregated sample per route template, method and status
// 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
// 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),
// relay and the Network key refresh, drains the HTTP server (requests in flight get Connection: close),
@@ -3,7 +3,7 @@
@@ -3,7 +3,7 @@
* Request telemetry (openvibe-sdk/service, plan T1 step 10): app.js mounts the process-wide telemetryMiddleware (a no-op
* 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
* 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
* 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 assert = require('assert');
const fs = require('fs');
const fs = require('fs');
@@ -38,9 +38,9 @@ const { boot } = require('./helpers/app');
@@ -38,9 +38,9 @@ const { boot } = require('./helpers/app');
const db = t.db;
const db = t.db;
await db.query('DELETE FROM telemetry_samples');
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]);
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);
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);
assert.strictEqual((await db.query('SELECT count(*)::int AS n FROM telemetry_samples')).rows[0].n, 1);
console.log('telemetry ok');
console.log('telemetry ok');
} finally {
} finally {