@noego/telemetry 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/cli/telemetry_bin.cjs +57 -57
  2. package/dist/cli/telemetry_bin.cjs.map +1 -1
  3. package/dist/cli/telemetry_bin.js +57 -57
  4. package/dist/cli/telemetry_bin.js.map +1 -1
  5. package/dist/cli/telemetry_cli.cjs +57 -57
  6. package/dist/cli/telemetry_cli.cjs.map +1 -1
  7. package/dist/cli/telemetry_cli.d.cts +3 -3
  8. package/dist/cli/telemetry_cli.d.ts +3 -3
  9. package/dist/cli/telemetry_cli.js +57 -57
  10. package/dist/cli/telemetry_cli.js.map +1 -1
  11. package/dist/core/index.d.cts +5 -5
  12. package/dist/core/index.d.ts +5 -5
  13. package/dist/index.d.cts +6 -6
  14. package/dist/index.d.ts +6 -6
  15. package/dist/{maintenance_coordinator.types-B-bZUNvw.d.cts → maintenance_coordinator.types-C4ULi4A4.d.cts} +2 -2
  16. package/dist/{maintenance_coordinator.types-CBA5y74b.d.ts → maintenance_coordinator.types-ikUrRXmO.d.ts} +2 -2
  17. package/dist/{metric_definition_contract-l4i4SaAp.d.ts → metric_definition_contract-BYtnODhu.d.ts} +1 -1
  18. package/dist/{metric_definition_contract-BR6a_GzF.d.cts → metric_definition_contract-DfhhmTZ1.d.cts} +1 -1
  19. package/dist/node/index.cjs +57 -57
  20. package/dist/node/index.cjs.map +1 -1
  21. package/dist/node/index.d.cts +5 -5
  22. package/dist/node/index.d.ts +5 -5
  23. package/dist/node/index.js +57 -57
  24. package/dist/node/index.js.map +1 -1
  25. package/dist/{query.types-DySoqYop.d.ts → query.types-DU5v7vM0.d.ts} +7 -0
  26. package/dist/{query.types-Bntwh6KF.d.cts → query.types-DuYWbFFe.d.cts} +7 -0
  27. package/dist/sqlite/index.cjs +34 -57
  28. package/dist/sqlite/index.cjs.map +1 -1
  29. package/dist/sqlite/index.d.cts +3 -3
  30. package/dist/sqlite/index.d.ts +3 -3
  31. package/dist/sqlite/index.js +34 -57
  32. package/dist/sqlite/index.js.map +1 -1
  33. package/dist/{storage.types-DjuUMinz.d.cts → storage.types-Bji_pWqr.d.cts} +1 -1
  34. package/dist/{storage.types-BTCGVxOM.d.ts → storage.types-k7oElEB3.d.ts} +1 -1
  35. package/dist/{telemetry_configuration_parser-C7Et_gwG.d.ts → telemetry_configuration_parser-BZ8Nvnle.d.ts} +3 -2
  36. package/dist/{telemetry_configuration_parser-R-niZQRZ.d.cts → telemetry_configuration_parser-CgSN7R6A.d.cts} +3 -2
  37. package/dist/testing/index.d.cts +2 -2
  38. package/dist/testing/index.d.ts +2 -2
  39. package/migrations/1785073006031_raw_events_level_index.down.sql +1 -0
  40. package/migrations/1785073006031_raw_events_level_index.up.sql +5 -0
  41. package/native/noego_telemetry_native.node +0 -0
  42. package/package.json +1 -1
@@ -1,8 +1,8 @@
1
- import { R as ResolvedTelemetryConfiguration, S as SqliteTargetConfiguration, T as TimelineQuery, b as TimelineQueryResponse, c as TelemetryQueryError, d as MetricQuery, e as MetricQueryResponse } from '../query.types-Bntwh6KF.cjs';
1
+ import { R as ResolvedTelemetryConfiguration, S as SqliteTargetConfiguration, T as TimelineQuery, b as TimelineQueryResponse, c as TelemetryQueryError, d as MetricQuery, e as MetricQueryResponse } from '../query.types-DuYWbFFe.cjs';
2
2
  import { T as TelemetryResult } from '../result.types-171Huujb.cjs';
3
- import { N as NodeTelemetryConfigurationParser } from '../telemetry_configuration_parser-R-niZQRZ.cjs';
3
+ import { N as NodeTelemetryConfigurationParser } from '../telemetry_configuration_parser-CgSN7R6A.cjs';
4
4
  import '../envelope.types-rOLpWXRC.cjs';
5
- import '../metric_definition_contract-BR6a_GzF.cjs';
5
+ import '../metric_definition_contract-DfhhmTZ1.cjs';
6
6
 
7
7
  type TelemetryCliStructuredFormat = 'table' | 'json' | 'jsonl' | 'csv';
8
8
  type TelemetryCliSessionMode = 'query' | 'maintenance';
@@ -1,8 +1,8 @@
1
- import { R as ResolvedTelemetryConfiguration, S as SqliteTargetConfiguration, T as TimelineQuery, b as TimelineQueryResponse, c as TelemetryQueryError, d as MetricQuery, e as MetricQueryResponse } from '../query.types-DySoqYop.js';
1
+ import { R as ResolvedTelemetryConfiguration, S as SqliteTargetConfiguration, T as TimelineQuery, b as TimelineQueryResponse, c as TelemetryQueryError, d as MetricQuery, e as MetricQueryResponse } from '../query.types-DU5v7vM0.js';
2
2
  import { T as TelemetryResult } from '../result.types-171Huujb.js';
3
- import { N as NodeTelemetryConfigurationParser } from '../telemetry_configuration_parser-C7Et_gwG.js';
3
+ import { N as NodeTelemetryConfigurationParser } from '../telemetry_configuration_parser-BZ8Nvnle.js';
4
4
  import '../envelope.types-rOLpWXRC.js';
5
- import '../metric_definition_contract-l4i4SaAp.js';
5
+ import '../metric_definition_contract-BYtnODhu.js';
6
6
 
7
7
  type TelemetryCliStructuredFormat = 'table' | 'json' | 'jsonl' | 'csv';
8
8
  type TelemetryCliSessionMode = 'query' | 'maintenance';
@@ -220,6 +220,7 @@ var TelemetryTableMap = class _TelemetryTableMap {
220
220
  rawEventsOccurredIndex: this.indexName(mapping.rawEvents, "occurred"),
221
221
  rawEventsConversationIndex: this.indexName(mapping.rawEvents, "conversation"),
222
222
  rawEventsLabelIndex: this.indexName(mapping.rawEvents, "label"),
223
+ rawEventsLevelIndex: this.indexName(mapping.rawEvents, "level"),
223
224
  metricSamplesTimeIndex: this.indexName(mapping.metricSamples, "time"),
224
225
  metricSamplesEventIndex: this.indexName(mapping.metricSamples, "event"),
225
226
  metricRollupsTimeIndex: this.indexName(mapping.metricRollups, "time")
@@ -394,6 +395,7 @@ var SqliteTargetSchema = z.object({
394
395
  raw: DurationSchema,
395
396
  lateArrival: DurationSchema.optional(),
396
397
  samples: DurationSchema.optional(),
398
+ levels: z.record(z.string().min(1), DurationSchema).optional(),
397
399
  rollups: z.array(
398
400
  z.object({
399
401
  resolution: DurationSchema,
@@ -536,6 +538,7 @@ var NodeTelemetryConfigurationParser = class {
536
538
  true
537
539
  );
538
540
  const samplesMs = target.retention.samples === void 0 ? rawMs + lateArrivalMs : this.durations.parse(target.retention.samples, `${field}.retention.samples`);
541
+ const levelMs = this.resolveLevelRetention(target.retention.levels, field);
539
542
  const rollups = target.retention.rollups.map(
540
543
  (tier, tierIndex) => Object.freeze({
541
544
  resolutionMs: this.durations.parse(
@@ -570,6 +573,7 @@ var NodeTelemetryConfigurationParser = class {
570
573
  rawMs,
571
574
  lateArrivalMs,
572
575
  samplesMs,
576
+ levelMs,
573
577
  rollups: Object.freeze(rollups)
574
578
  }),
575
579
  maintenance: Object.freeze({
@@ -600,6 +604,26 @@ var NodeTelemetryConfigurationParser = class {
600
604
  }
601
605
  return resolved;
602
606
  }
607
+ resolveLevelRetention(levels, field) {
608
+ if (levels === void 0) {
609
+ return Object.freeze({});
610
+ }
611
+ const resolved = {};
612
+ for (const [level, duration] of Object.entries(levels)) {
613
+ const normalized = level.trim().toLowerCase();
614
+ if (normalized.length === 0) {
615
+ throw new Error(`${field}.retention.levels contains an empty level name`);
616
+ }
617
+ if (resolved[normalized] !== void 0) {
618
+ throw new Error(`${field}.retention.levels declares "${normalized}" more than once`);
619
+ }
620
+ resolved[normalized] = this.durations.parse(
621
+ duration,
622
+ `${field}.retention.levels.${normalized}`
623
+ );
624
+ }
625
+ return Object.freeze(resolved);
626
+ }
603
627
  validateRetention(target, field) {
604
628
  const retention = target.retention;
605
629
  const requiredSamplesMs = retention.rawMs + retention.lateArrivalMs;
@@ -3363,73 +3387,49 @@ var TelemetryRepository = class {
3363
3387
  lastSequence: sample.sequence
3364
3388
  };
3365
3389
  }
3390
+ /**
3391
+ * Raw retention is purely time-based, matching the native collector: every
3392
+ * expired row goes in one set-based statement per level band. No page size,
3393
+ * no row cap, and no rollup-completion gate — metric samples are extracted at
3394
+ * ingest and retained on their own clock, so dropping a raw row costs no
3395
+ * metric fidelity, and no row can outlive its window waiting on a rollup.
3396
+ */
3366
3397
  createRawEventRetentionStep(nowMs) {
3367
- const cutoffMs = nowMs - this.options.retention.rawMs;
3368
3398
  const table = this.options.tableMap.quoted("rawEvents");
3369
- const readFirstPage = this.options.connection.prepare(
3370
- `SELECT producer_id, sequence, event_id, occurred_at_ms, monotonic_ns,
3371
- source, process_kind, level, label, conversation_id,
3372
- conversation_id_kind, correlation_id, metadata_json, schema_version
3373
- FROM ${table}
3374
- WHERE target_id = ? AND occurred_at_ms < ?
3375
- ORDER BY occurred_at_ms ASC, producer_id ASC, sequence ASC
3376
- LIMIT ${RETENTION_PAGE_SIZE}`
3377
- );
3378
- const readNextPage = this.options.connection.prepare(
3379
- `SELECT producer_id, sequence, event_id, occurred_at_ms, monotonic_ns,
3380
- source, process_kind, level, label, conversation_id,
3381
- conversation_id_kind, correlation_id, metadata_json, schema_version
3382
- FROM ${table}
3383
- WHERE target_id = ? AND occurred_at_ms < ?
3384
- AND (occurred_at_ms, producer_id, sequence) > (?, ?, ?)
3385
- ORDER BY occurred_at_ms ASC, producer_id ASC, sequence ASC
3386
- LIMIT ${RETENTION_PAGE_SIZE}`
3399
+ const levelMs = this.options.retention.levelMs ?? {};
3400
+ const levels = Object.keys(levelMs);
3401
+ const removeByLevel = this.options.connection.prepare(
3402
+ `DELETE FROM ${table}
3403
+ WHERE target_id = ? AND lower(coalesce(level, '')) = ? AND occurred_at_ms < ?`
3387
3404
  );
3388
- const remove = this.options.connection.prepare(
3389
- `DELETE FROM ${table} WHERE target_id = ? AND producer_id = ? AND sequence = ?`
3405
+ const fallbackPlaceholders = levels.map(() => "?").join(", ");
3406
+ const removeFallback = this.options.connection.prepare(
3407
+ `DELETE FROM ${table}
3408
+ WHERE target_id = ? AND occurred_at_ms < ?` + (levels.length === 0 ? "" : ` AND lower(coalesce(level, '')) NOT IN (${fallbackPlaceholders})`)
3390
3409
  );
3391
- let cursor = null;
3410
+ let done = false;
3392
3411
  return () => {
3393
- const rows = cursor === null ? readFirstPage.all(this.options.targetId, cutoffMs) : readNextPage.all(
3394
- this.options.targetId,
3395
- cutoffMs,
3396
- cursor.occurredAtMs,
3397
- cursor.producerId,
3398
- cursor.sequence
3399
- );
3400
- if (rows.length === 0) {
3412
+ if (done) {
3401
3413
  return { deleted: 0, done: true };
3402
3414
  }
3403
- const scanned = rows.map((row) => {
3404
- const parsed = this.rowParser.parseRawEnvelope(row);
3405
- if (!parsed.ok) {
3406
- throw new Error(parsed.error);
3407
- }
3408
- return parsed.value;
3409
- });
3410
- const eligible = scanned.filter((envelope) => this.rawEventHasRequiredRollups(envelope));
3415
+ done = true;
3411
3416
  const transaction = this.options.connection.transaction(() => {
3412
- let deleted2 = 0;
3413
- for (const envelope of eligible) {
3414
- deleted2 += remove.run(
3415
- this.options.targetId,
3416
- envelope.producerId,
3417
- envelope.sequence
3418
- ).changes;
3417
+ let deleted = 0;
3418
+ for (const level of levels) {
3419
+ const retainMs = levelMs[level];
3420
+ if (retainMs === void 0) {
3421
+ continue;
3422
+ }
3423
+ deleted += removeByLevel.run(this.options.targetId, level, nowMs - retainMs).changes;
3419
3424
  }
3420
- return deleted2;
3425
+ deleted += removeFallback.run(
3426
+ this.options.targetId,
3427
+ nowMs - this.options.retention.rawMs,
3428
+ ...levels
3429
+ ).changes;
3430
+ return deleted;
3421
3431
  });
3422
- const deleted = transaction();
3423
- const last = scanned[scanned.length - 1];
3424
- if (last === void 0 || rows.length < RETENTION_PAGE_SIZE) {
3425
- return { deleted, done: true };
3426
- }
3427
- cursor = {
3428
- occurredAtMs: last.occurredAtMs,
3429
- producerId: last.producerId,
3430
- sequence: last.sequence
3431
- };
3432
- return { deleted, done: false };
3432
+ return { deleted: transaction(), done: true };
3433
3433
  };
3434
3434
  }
3435
3435
  rawEventHasRequiredRollups(envelope) {