Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
add 100_000 cap for stream
Thiago Araujo da Silvae5a3a37b1a08
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex 910219ff37..84e28c4089 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -421,7 +421,7 @@ Separate from the OpenTelemetry metrics above. `src/services/telemetry/telemetry- **Never discover buffered events by pattern.** The previous layout wrote one Redis key per event and the cron found them with `getKeysByPattern` per (event type, bucket), so each run cost `events × buckets` full keyspace walks — 240 walks over a ~440k-key keyspace, ~73s of Redis engine CPU every 10 minutes, and it grew every time an event was added to the aggregation list. The stream layout is read by key, so the cost tracks the number of pending events instead of the size of the keyspace. Adding an event type to `POSTHOG_AGGREGATED_EVENTS` must stay free of keyspace scans.- **A `distinctId` must always hash to the same bucket.** Each shard is aggregated independently, so a `distinctId` split across shards produces one aggregated PostHog event per shard instead of one overall.-Draining is at-least-once: a shard is trimmed (`XTRIM MINID`) only after its batch has been handed to PostHog, so a failed run retries on the next tick. Growth is bounded by the `MAXLEN` cap on write, not by a TTL. Nothing reads the pre-stream keys, so a deploy that changes this layout drops whatever is still buffered — acceptable for product analytics, and the reason there is no migration path to maintain.+Draining is at-least-once: a shard is trimmed (`XTRIM MINID`) only after its batch has been handed to the PostHog client, so a run that throws before that point retries the whole batch on the next tick. Growth is bounded by the `MAXLEN` cap on write (100k entries per shard), not by a TTL, and one run drains at most 50k entries per shard, so a backlog is worked off over several ticks instead of being pulled into the cron's memory at once. Nothing reads the pre-stream keys, so a deploy that changes this layout drops whatever is still buffered — acceptable for product analytics, and the reason there is no migration path to maintain.### Database Configurationdiff --git a/backend/src/services/telemetry/telemetry-service.ts b/backend/src/services/telemetry/telemetry-service.tsindex e4715b3b63..fd682bf0ac 100644--- a/backend/src/services/telemetry/telemetry-service.ts+++ b/backend/src/services/telemetry/telemetry-service.ts@@ -51,7 +51,8 @@ const TELEMETRY_BUCKET_NAMES = Array.from();const TELEMETRY_EVENT_STREAM_BATCH_SIZE = 10_000;-const TELEMETRY_EVENT_STREAM_MAX_ENTRIES = 50_000;+const TELEMETRY_EVENT_STREAM_COLLECT_CEILING = 50_000;+const TELEMETRY_EVENT_STREAM_MAX_ENTRIES = 100_000;type AggregatedEventData = Record<string, unknown>;type SingleEventData = {@@ -320,15 +321,20 @@ To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environmeconst resolvedOrgName = event.organizationName ?? requestContext.get(RequestContextKey.OrgName);if (POSTHOG_AGGREGATED_EVENTS.includes(event.event)) {- await keyStore.streamAdd(getTelemetryEventStreamKey(event.event, event.distinctId), "*", {- data: JSON.stringify({- distinctId: event.distinctId,- event: event.event,- properties: event.properties,- organizationId: event.organizationId,- ...(resolvedOrgName ? { organizationName: resolvedOrgName } : {})- })- });+ await keyStore.streamAdd(+ getTelemetryEventStreamKey(event.event, event.distinctId),+ "*",+ {+ data: JSON.stringify({+ distinctId: event.distinctId,+ event: event.event,+ properties: event.properties,+ organizationId: event.organizationId,+ ...(resolvedOrgName ? { organizationName: resolvedOrgName } : {})+ })+ },+ TELEMETRY_EVENT_STREAM_MAX_ENTRIES+ );} else {// Skip groupIdentify entirely when the event is marked anonymous.//@@ -563,14 +569,14 @@ To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environmeconst { entries, lastId } = await keyStore.streamCollect(streamKey,TELEMETRY_EVENT_STREAM_BATCH_SIZE,- TELEMETRY_EVENT_STREAM_MAX_ENTRIES+ TELEMETRY_EVENT_STREAM_COLLECT_CEILING);if (entries.length === 0 || !lastId) return 0;- if (entries.length >= TELEMETRY_EVENT_STREAM_MAX_ENTRIES) {+ if (entries.length >= TELEMETRY_EVENT_STREAM_COLLECT_CEILING) {logger.warn(- `Telemetry aggregation hit the collection ceiling for bucket ${bucketId} of ${eventType} [collected=${entries.length}] [maxEntries=${TELEMETRY_EVENT_STREAM_MAX_ENTRIES}] — the shard is backing up; the oldest entries risk being dropped by the Redis MAXLEN cap`+ `Telemetry aggregation hit the collection ceiling for bucket ${bucketId} of ${eventType} [collected=${entries.length}] [ceiling=${TELEMETRY_EVENT_STREAM_COLLECT_CEILING}] [maxLen=${TELEMETRY_EVENT_STREAM_MAX_ENTRIES}] — the shard is backing up; once it exceeds the MAXLEN cap the oldest entries are dropped`);}