@noego/telemetry 0.0.1 → 0.0.3

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,16 +1,16 @@
1
1
  import { T as TelemetryAdmissionPolicy, M as MetadataSnapshotLimits, a as TelemetryClient } from '../telemetry_client-CYaPYfOl.cjs';
2
- import { T as TelemetrySinkPlugin, c as MaintenanceLifecycleEvent, e as TelemetryCollectorRuntime, f as TelemetryCollectorStatus } from '../maintenance_coordinator.types-B-bZUNvw.cjs';
3
- import { S as SqliteTargetConfiguration, M as MetricDefinition } from '../query.types-Bntwh6KF.cjs';
4
- import { T as TelemetryStorageTransport, e as TelemetryStorageTarget, a as TelemetryStorageCapabilities } from '../storage.types-DjuUMinz.cjs';
2
+ import { T as TelemetrySinkPlugin, c as MaintenanceLifecycleEvent, e as TelemetryCollectorRuntime, f as TelemetryCollectorStatus } from '../maintenance_coordinator.types-C4ULi4A4.cjs';
3
+ import { S as SqliteTargetConfiguration, M as MetricDefinition } from '../query.types-DuYWbFFe.cjs';
4
+ import { T as TelemetryStorageTransport, e as TelemetryStorageTarget, a as TelemetryStorageCapabilities } from '../storage.types-Bji_pWqr.cjs';
5
5
  import { a as TelemetryBatchValidationLimits, c as TelemetryBatchReceiver } from '../transport.types-BAl_TRtU.cjs';
6
6
  import { NodeTelemetryProducerOptions } from './producer/index.cjs';
7
7
  export { NodeTelemetryProducerHost } from './producer/index.cjs';
8
8
  export { SQLiteTelemetryTransport } from '../sqlite/index.cjs';
9
- export { a as NodeTelemetryConfigurationParseOptions, N as NodeTelemetryConfigurationParser, T as TelemetryConfigurationError, b as TelemetryDurationParser } from '../telemetry_configuration_parser-R-niZQRZ.cjs';
9
+ export { a as NodeTelemetryConfigurationParseOptions, N as NodeTelemetryConfigurationParser, T as TelemetryConfigurationError, b as TelemetryDurationParser } from '../telemetry_configuration_parser-CgSN7R6A.cjs';
10
10
  export { D as DEFAULT_METADATA_SNAPSHOT_LIMITS, a as DEFAULT_TELEMETRY_ADMISSION_POLICY } from '../client_defaults-C9LnSX4j.cjs';
11
11
  import '../envelope.types-rOLpWXRC.cjs';
12
12
  import '../result.types-171Huujb.cjs';
13
- import '../metric_definition_contract-BR6a_GzF.cjs';
13
+ import '../metric_definition_contract-DfhhmTZ1.cjs';
14
14
 
15
15
  type NodeLocalTelemetryProducerOptions = Omit<NodeTelemetryProducerOptions, 'transport'>;
16
16
  type NodeTelemetryCollectorOptions = Readonly<{
@@ -1,16 +1,16 @@
1
1
  import { T as TelemetryAdmissionPolicy, M as MetadataSnapshotLimits, a as TelemetryClient } from '../telemetry_client-BXw8WH_F.js';
2
- import { T as TelemetrySinkPlugin, c as MaintenanceLifecycleEvent, e as TelemetryCollectorRuntime, f as TelemetryCollectorStatus } from '../maintenance_coordinator.types-CBA5y74b.js';
3
- import { S as SqliteTargetConfiguration, M as MetricDefinition } from '../query.types-DySoqYop.js';
4
- import { T as TelemetryStorageTransport, e as TelemetryStorageTarget, a as TelemetryStorageCapabilities } from '../storage.types-BTCGVxOM.js';
2
+ import { T as TelemetrySinkPlugin, c as MaintenanceLifecycleEvent, e as TelemetryCollectorRuntime, f as TelemetryCollectorStatus } from '../maintenance_coordinator.types-ikUrRXmO.js';
3
+ import { S as SqliteTargetConfiguration, M as MetricDefinition } from '../query.types-DU5v7vM0.js';
4
+ import { T as TelemetryStorageTransport, e as TelemetryStorageTarget, a as TelemetryStorageCapabilities } from '../storage.types-k7oElEB3.js';
5
5
  import { a as TelemetryBatchValidationLimits, c as TelemetryBatchReceiver } from '../transport.types-DDnZoKWi.js';
6
6
  import { NodeTelemetryProducerOptions } from './producer/index.js';
7
7
  export { NodeTelemetryProducerHost } from './producer/index.js';
8
8
  export { SQLiteTelemetryTransport } from '../sqlite/index.js';
9
- export { a as NodeTelemetryConfigurationParseOptions, N as NodeTelemetryConfigurationParser, T as TelemetryConfigurationError, b as TelemetryDurationParser } from '../telemetry_configuration_parser-C7Et_gwG.js';
9
+ export { a as NodeTelemetryConfigurationParseOptions, N as NodeTelemetryConfigurationParser, T as TelemetryConfigurationError, b as TelemetryDurationParser } from '../telemetry_configuration_parser-BZ8Nvnle.js';
10
10
  export { D as DEFAULT_METADATA_SNAPSHOT_LIMITS, a as DEFAULT_TELEMETRY_ADMISSION_POLICY } from '../client_defaults-B5tC-TgG.js';
11
11
  import '../envelope.types-rOLpWXRC.js';
12
12
  import '../result.types-171Huujb.js';
13
- import '../metric_definition_contract-l4i4SaAp.js';
13
+ import '../metric_definition_contract-BYtnODhu.js';
14
14
 
15
15
  type NodeLocalTelemetryProducerOptions = Omit<NodeTelemetryProducerOptions, 'transport'>;
16
16
  type NodeTelemetryCollectorOptions = Readonly<{
@@ -3946,73 +3946,49 @@ var TelemetryRepository = class {
3946
3946
  lastSequence: sample.sequence
3947
3947
  };
3948
3948
  }
3949
+ /**
3950
+ * Raw retention is purely time-based, matching the native collector: every
3951
+ * expired row goes in one set-based statement per level band. No page size,
3952
+ * no row cap, and no rollup-completion gate — metric samples are extracted at
3953
+ * ingest and retained on their own clock, so dropping a raw row costs no
3954
+ * metric fidelity, and no row can outlive its window waiting on a rollup.
3955
+ */
3949
3956
  createRawEventRetentionStep(nowMs) {
3950
- const cutoffMs = nowMs - this.options.retention.rawMs;
3951
3957
  const table = this.options.tableMap.quoted("rawEvents");
3952
- const readFirstPage = this.options.connection.prepare(
3953
- `SELECT producer_id, sequence, event_id, occurred_at_ms, monotonic_ns,
3954
- source, process_kind, level, label, conversation_id,
3955
- conversation_id_kind, correlation_id, metadata_json, schema_version
3956
- FROM ${table}
3957
- WHERE target_id = ? AND occurred_at_ms < ?
3958
- ORDER BY occurred_at_ms ASC, producer_id ASC, sequence ASC
3959
- LIMIT ${RETENTION_PAGE_SIZE}`
3960
- );
3961
- const readNextPage = this.options.connection.prepare(
3962
- `SELECT producer_id, sequence, event_id, occurred_at_ms, monotonic_ns,
3963
- source, process_kind, level, label, conversation_id,
3964
- conversation_id_kind, correlation_id, metadata_json, schema_version
3965
- FROM ${table}
3966
- WHERE target_id = ? AND occurred_at_ms < ?
3967
- AND (occurred_at_ms, producer_id, sequence) > (?, ?, ?)
3968
- ORDER BY occurred_at_ms ASC, producer_id ASC, sequence ASC
3969
- LIMIT ${RETENTION_PAGE_SIZE}`
3958
+ const levelMs = this.options.retention.levelMs ?? {};
3959
+ const levels = Object.keys(levelMs);
3960
+ const removeByLevel = this.options.connection.prepare(
3961
+ `DELETE FROM ${table}
3962
+ WHERE target_id = ? AND lower(coalesce(level, '')) = ? AND occurred_at_ms < ?`
3970
3963
  );
3971
- const remove = this.options.connection.prepare(
3972
- `DELETE FROM ${table} WHERE target_id = ? AND producer_id = ? AND sequence = ?`
3964
+ const fallbackPlaceholders = levels.map(() => "?").join(", ");
3965
+ const removeFallback = this.options.connection.prepare(
3966
+ `DELETE FROM ${table}
3967
+ WHERE target_id = ? AND occurred_at_ms < ?` + (levels.length === 0 ? "" : ` AND lower(coalesce(level, '')) NOT IN (${fallbackPlaceholders})`)
3973
3968
  );
3974
- let cursor = null;
3969
+ let done = false;
3975
3970
  return () => {
3976
- const rows = cursor === null ? readFirstPage.all(this.options.targetId, cutoffMs) : readNextPage.all(
3977
- this.options.targetId,
3978
- cutoffMs,
3979
- cursor.occurredAtMs,
3980
- cursor.producerId,
3981
- cursor.sequence
3982
- );
3983
- if (rows.length === 0) {
3971
+ if (done) {
3984
3972
  return { deleted: 0, done: true };
3985
3973
  }
3986
- const scanned = rows.map((row) => {
3987
- const parsed = this.rowParser.parseRawEnvelope(row);
3988
- if (!parsed.ok) {
3989
- throw new Error(parsed.error);
3990
- }
3991
- return parsed.value;
3992
- });
3993
- const eligible = scanned.filter((envelope) => this.rawEventHasRequiredRollups(envelope));
3974
+ done = true;
3994
3975
  const transaction = this.options.connection.transaction(() => {
3995
- let deleted2 = 0;
3996
- for (const envelope of eligible) {
3997
- deleted2 += remove.run(
3998
- this.options.targetId,
3999
- envelope.producerId,
4000
- envelope.sequence
4001
- ).changes;
3976
+ let deleted = 0;
3977
+ for (const level of levels) {
3978
+ const retainMs = levelMs[level];
3979
+ if (retainMs === void 0) {
3980
+ continue;
3981
+ }
3982
+ deleted += removeByLevel.run(this.options.targetId, level, nowMs - retainMs).changes;
4002
3983
  }
4003
- return deleted2;
3984
+ deleted += removeFallback.run(
3985
+ this.options.targetId,
3986
+ nowMs - this.options.retention.rawMs,
3987
+ ...levels
3988
+ ).changes;
3989
+ return deleted;
4004
3990
  });
4005
- const deleted = transaction();
4006
- const last = scanned[scanned.length - 1];
4007
- if (last === void 0 || rows.length < RETENTION_PAGE_SIZE) {
4008
- return { deleted, done: true };
4009
- }
4010
- cursor = {
4011
- occurredAtMs: last.occurredAtMs,
4012
- producerId: last.producerId,
4013
- sequence: last.sequence
4014
- };
4015
- return { deleted, done: false };
3991
+ return { deleted: transaction(), done: true };
4016
3992
  };
4017
3993
  }
4018
3994
  rawEventHasRequiredRollups(envelope) {
@@ -4753,6 +4729,7 @@ var TelemetryTableMap = class _TelemetryTableMap {
4753
4729
  rawEventsOccurredIndex: this.indexName(mapping.rawEvents, "occurred"),
4754
4730
  rawEventsConversationIndex: this.indexName(mapping.rawEvents, "conversation"),
4755
4731
  rawEventsLabelIndex: this.indexName(mapping.rawEvents, "label"),
4732
+ rawEventsLevelIndex: this.indexName(mapping.rawEvents, "level"),
4756
4733
  metricSamplesTimeIndex: this.indexName(mapping.metricSamples, "time"),
4757
4734
  metricSamplesEventIndex: this.indexName(mapping.metricSamples, "event"),
4758
4735
  metricRollupsTimeIndex: this.indexName(mapping.metricRollups, "time")
@@ -6741,6 +6718,7 @@ var SqliteTargetSchema = z3.object({
6741
6718
  raw: DurationSchema,
6742
6719
  lateArrival: DurationSchema.optional(),
6743
6720
  samples: DurationSchema.optional(),
6721
+ levels: z3.record(z3.string().min(1), DurationSchema).optional(),
6744
6722
  rollups: z3.array(
6745
6723
  z3.object({
6746
6724
  resolution: DurationSchema,
@@ -6883,6 +6861,7 @@ var NodeTelemetryConfigurationParser = class {
6883
6861
  true
6884
6862
  );
6885
6863
  const samplesMs = target.retention.samples === void 0 ? rawMs + lateArrivalMs : this.durations.parse(target.retention.samples, `${field}.retention.samples`);
6864
+ const levelMs = this.resolveLevelRetention(target.retention.levels, field);
6886
6865
  const rollups = target.retention.rollups.map(
6887
6866
  (tier, tierIndex) => Object.freeze({
6888
6867
  resolutionMs: this.durations.parse(
@@ -6917,6 +6896,7 @@ var NodeTelemetryConfigurationParser = class {
6917
6896
  rawMs,
6918
6897
  lateArrivalMs,
6919
6898
  samplesMs,
6899
+ levelMs,
6920
6900
  rollups: Object.freeze(rollups)
6921
6901
  }),
6922
6902
  maintenance: Object.freeze({
@@ -6947,6 +6927,26 @@ var NodeTelemetryConfigurationParser = class {
6947
6927
  }
6948
6928
  return resolved;
6949
6929
  }
6930
+ resolveLevelRetention(levels, field) {
6931
+ if (levels === void 0) {
6932
+ return Object.freeze({});
6933
+ }
6934
+ const resolved = {};
6935
+ for (const [level, duration] of Object.entries(levels)) {
6936
+ const normalized = level.trim().toLowerCase();
6937
+ if (normalized.length === 0) {
6938
+ throw new Error(`${field}.retention.levels contains an empty level name`);
6939
+ }
6940
+ if (resolved[normalized] !== void 0) {
6941
+ throw new Error(`${field}.retention.levels declares "${normalized}" more than once`);
6942
+ }
6943
+ resolved[normalized] = this.durations.parse(
6944
+ duration,
6945
+ `${field}.retention.levels.${normalized}`
6946
+ );
6947
+ }
6948
+ return Object.freeze(resolved);
6949
+ }
6950
6950
  validateRetention(target, field) {
6951
6951
  const retention = target.retention;
6952
6952
  const requiredSamplesMs = retention.rawMs + retention.lateArrivalMs;