OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
fix(ingest): KAFKA_REBALANCE_TIMEOUT_MS is passed to the consumer
Carl-Gerhard Lindesvärdd9c382a54a19
diff --git a/apps/api/src/config/env.test.ts b/apps/api/src/config/env.test.tsindex fefaa7dc9..adeb8a750 100644--- a/apps/api/src/config/env.test.ts+++ b/apps/api/src/config/env.test.ts@@ -403,6 +403,14 @@ describe('cross-field invariants, checked before the transform', () => {).toThrow(/must be below KAFKA_SESSION_TIMEOUT_MS/);});+ it('passes KAFKA_REBALANCE_TIMEOUT_MS to the consumer, defaulting to kafkajs', () => {+ expect(loadConfig(base).core.kafka.rebalanceTimeoutMs).toBe(60_000);+ expect(+ loadConfig({ ...base, KAFKA_REBALANCE_TIMEOUT_MS: '30000' }).core.kafka+ .rebalanceTimeoutMs+ ).toBe(30_000);+ });+it('refuses a reaper deadman below the session idle window', () => {expect(() =>loadConfig({diff --git a/apps/api/src/config/env.ts b/apps/api/src/config/env.tsindex 75c265d8b..b54009fec 100644--- a/apps/api/src/config/env.ts+++ b/apps/api/src/config/env.ts@@ -30,6 +30,8 @@ const DEFAULT_KAFKA_MAX_WAIT_MS = 500;const DEFAULT_KAFKA_MAX_MESSAGES_PER_PARTITION = 256;const DEFAULT_KAFKA_SESSION_TIMEOUT_MS = 30_000;const DEFAULT_KAFKA_HEARTBEAT_INTERVAL_MS = 3000;+/** kafkajs's own default, so leaving the variable unset changes nothing. */+const DEFAULT_KAFKA_REBALANCE_TIMEOUT_MS = 60_000;const DEFAULT_KAFKA_REQUEST_TIMEOUT_MS = 5000;const DEFAULT_KAFKA_CONNECTION_TIMEOUT_MS = 2000;/** Kafka's and Redpanda's own default `max.message.bytes`: 1 MiB. */@@ -439,6 +441,9 @@ const rawSchema = z.object({KAFKA_HEARTBEAT_INTERVAL_MS: positiveIntWithDefault(DEFAULT_KAFKA_HEARTBEAT_INTERVAL_MS),+ KAFKA_REBALANCE_TIMEOUT_MS: positiveIntWithDefault(+ DEFAULT_KAFKA_REBALANCE_TIMEOUT_MS+ ),KAFKA_REQUEST_TIMEOUT_MS: positiveIntWithDefault(DEFAULT_KAFKA_REQUEST_TIMEOUT_MS),@@ -716,6 +721,7 @@ function deriveKafkaConfig(raw: RawEnv): CoreConfig['kafka'] {maxMessagesPerPartition: raw.KAFKA_MAX_MESSAGES_PER_PARTITION,sessionTimeoutMs: raw.KAFKA_SESSION_TIMEOUT_MS,heartbeatIntervalMs: raw.KAFKA_HEARTBEAT_INTERVAL_MS,+ rebalanceTimeoutMs: raw.KAFKA_REBALANCE_TIMEOUT_MS,requestTimeoutMs: raw.KAFKA_REQUEST_TIMEOUT_MS,connectionTimeoutMs: raw.KAFKA_CONNECTION_TIMEOUT_MS,producerRetries: raw.KAFKA_PRODUCER_RETRIES,diff --git a/apps/public/content/docs/self-hosting/environment-variables.mdx b/apps/public/content/docs/self-hosting/environment-variables.mdxindex c9174b503..629e1d9c5 100644--- a/apps/public/content/docs/self-hosting/environment-variables.mdx+++ b/apps/public/content/docs/self-hosting/environment-variables.mdx@@ -1151,6 +1151,19 @@ How often, in milliseconds, the consumer sends background heartbeats to the brokKAFKA_HEARTBEAT_INTERVAL_MS=3000```+### KAFKA_REBALANCE_TIMEOUT_MS++**Type**: `number`+**Required**: No+**Default**: `60000`++How long, in milliseconds, the consumer group waits for every member to rejoin during a rebalance. No consumer processes events while it waits, so a member that stopped without leaving the group stalls ingestion for up to this long. Raise it only if a single batch can take longer than this to finish.++**Example**:+```bash+KAFKA_REBALANCE_TIMEOUT_MS=60000+```+## Buffers### SESSION_BUFFER_BATCH_SIZEdiff --git a/packages/core/src/config.ts b/packages/core/src/config.tsindex 7e3431b13..78a8dd4ce 100644--- a/packages/core/src/config.ts+++ b/packages/core/src/config.ts@@ -117,6 +117,8 @@ export interface KafkaConfig {maxMessagesPerPartition: number;sessionTimeoutMs: number;heartbeatIntervalMs: number;+ /** How long the group waits for every member to rejoin during a rebalance. */+ rebalanceTimeoutMs: number;requestTimeoutMs: number;connectionTimeoutMs: number;producerRetries: number;diff --git a/packages/core/src/modules/ingest/src/kafka.ts b/packages/core/src/modules/ingest/src/kafka.tsindex 0cb0c598c..4d90cf175 100644--- a/packages/core/src/modules/ingest/src/kafka.ts+++ b/packages/core/src/modules/ingest/src/kafka.ts@@ -261,6 +261,7 @@ export const createKafkaEventsConsumer = (groupId: options?.groupId || config.kafka.consumerGroup,sessionTimeout: config.kafka.sessionTimeoutMs,heartbeatInterval: config.kafka.heartbeatIntervalMs,+ rebalanceTimeout: config.kafka.rebalanceTimeoutMs,minBytes: config.kafka.minMessages * KAFKA_BYTES_PER_MESSAGE,maxWaitTimeInMs: config.kafka.maxWaitMs,maxBytesPerPartition:diff --git a/packages/core/src/modules/ingest/src/producer-tuning.test.ts b/packages/core/src/modules/ingest/src/producer-tuning.test.tsindex 151393244..e386025e2 100644--- a/packages/core/src/modules/ingest/src/producer-tuning.test.ts+++ b/packages/core/src/modules/ingest/src/producer-tuning.test.ts@@ -29,6 +29,7 @@ const kafkaConfig = (tuning: Partial<KafkaConfig> = {}): KafkaConfig =>maxMessagesPerPartition: 256,sessionTimeoutMs: 30_000,heartbeatIntervalMs: 3000,+ rebalanceTimeoutMs: 60_000,requestTimeoutMs: 5000,connectionTimeoutMs: 2000,producerRetries: 2,diff --git a/packages/core/test/config-fixture.ts b/packages/core/test/config-fixture.tsindex 30fe1ef54..4db16bd8c 100644--- a/packages/core/test/config-fixture.ts+++ b/packages/core/test/config-fixture.ts@@ -73,6 +73,7 @@ export function testCoreConfig(maxMessagesPerPartition: 256,sessionTimeoutMs: 30_000,heartbeatIntervalMs: 3000,+ rebalanceTimeoutMs: 60_000,requestTimeoutMs: 5000,connectionTimeoutMs: 2000,producerRetries: 2,