openvibers/openvibe.codes Commits
Codes: telemetry flushes each minute and keeps 14 days (#82)
Changes
@@@ -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();@@@ -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 {
@@ -31,9 +31,9 @@ async function start() {
@@ -31,9 +31,9 @@ async function start() {
});
});
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: '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
// 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.
// good keys through outages, exponential backoff, unknown-kid floods throttled, an unref'd timer.
ctx.keys.client.start();
ctx.keys.client.start();
@@ -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 'codes' with a PostgreSQL sink, starts the 30-day
* 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
* 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/boot');
@@ -38,9 +38,9 @@ const { boot } = require('./helpers/boot');
const db = t.ctx.store.db;
const db = t.ctx.store.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), 'codes', 'http.request')", [days]);
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);
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 {