Skip to content

Commit 29598a7

Browse files
authored
feat(webapp): add option to disable PostgreSQL task-event writes (#4242)
## Summary Adds `EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED` (default off), which makes the task-event store skip all PostgreSQL `TaskEvent` writes. It's for deployments that store task events in ClickHouse (`EVENT_REPOSITORY_DEFAULT_STORE=clickhouse_v2`) and no longer want the PostgreSQL copy. ## How it works The guard sits at the single postgres write boundary, `TaskEventStore.create` / `createMany`, so it covers every write path (OTLP ingestion and run-lifecycle events) with one check. Reads are untouched (`findMany` / trace queries / streaming), so existing PostgreSQL events remain readable. Leave it off unless the default store is `clickhouse_v2`, otherwise task events for any run still routed to PostgreSQL would be dropped.
1 parent 6e943f2 commit 29598a7

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: feature
4+
---
5+
6+
Added `EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED` to skip all PostgreSQL task-event writes for deployments that store task events in ClickHouse. Leave it off unless `EVENT_REPOSITORY_DEFAULT_STORE` is `clickhouse_v2`, otherwise task events are lost.

apps/webapp/app/env.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,7 @@ const EnvironmentSchema = z
18601860
.enum(["postgres", "clickhouse", "clickhouse_v2"])
18611861
.default("postgres"),
18621862
EVENT_REPOSITORY_DEBUG_LOGS_DISABLED: BoolEnv.default(false),
1863+
EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED: BoolEnv.default(false),
18631864
EVENTS_CLICKHOUSE_MAX_TRACE_SUMMARY_VIEW_COUNT: z.coerce.number().int().default(25_000),
18641865
EVENTS_CLICKHOUSE_MAX_TRACE_DETAILED_SUMMARY_VIEW_COUNT: z.coerce.number().int().default(5_000),
18651866
EVENTS_CLICKHOUSE_MAX_LIVE_RELOADING_SETTING: z.coerce.number().int().default(2000),

apps/webapp/app/v3/eventRepository/eventRepository.server.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,23 @@ export class EventRepository implements IEventRepository {
157157
}
158158

159159
private async insertImmediate(event: CreateEventInput) {
160+
if (env.EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED) {
161+
return;
162+
}
160163
await this.#flushBatch(nanoid(), [this.#createableEventToPrismaEvent(event)]);
161164
}
162165

163166
insertMany(events: CreateEventInput[]) {
167+
if (env.EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED) {
168+
return;
169+
}
164170
this._flushScheduler.addToBatch(events.map(this.#createableEventToPrismaEvent));
165171
}
166172

167173
async insertManyImmediate(events: CreateEventInput[]) {
174+
if (env.EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED) {
175+
return;
176+
}
168177
await this.#flushBatchWithReturn(nanoid(), events.map(this.#createableEventToPrismaEvent));
169178
}
170179

@@ -1018,7 +1027,7 @@ export class EventRepository implements IEventRepository {
10181027
if (options.immediate) {
10191028
await this.insertImmediate(event);
10201029
} else {
1021-
this._flushScheduler.addToBatch([this.#createableEventToPrismaEvent(event)]);
1030+
this.insertMany([event]);
10221031
}
10231032
}
10241033

@@ -1152,7 +1161,7 @@ export class EventRepository implements IEventRepository {
11521161
if (options.immediate) {
11531162
await this.insertImmediate(event);
11541163
} else {
1155-
this._flushScheduler.addToBatch([this.#createableEventToPrismaEvent(event)]);
1164+
this.insertMany([event]);
11561165
}
11571166

11581167
return result;

docs/self-hosting/env/webapp.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ mode: "wide"
135135
| `SERVER_OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` | No | 8192 | OTel span attribute value length limit. |
136136
| **Task events** | | | |
137137
| `EVENT_REPOSITORY_DEFAULT_STORE` | No | postgres | Where to store task events. Set to `clickhouse_v2` to store in ClickHouse (recommended for production). |
138+
| `EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED` | No | 0 | Skip all PostgreSQL task-event writes (set to `1`). Only enable when `EVENT_REPOSITORY_DEFAULT_STORE` is `clickhouse_v2`, otherwise task events are lost. |
138139
| **Realtime** | | | |
139140
| `REALTIME_STREAM_VERSION` | No | v1 | Stream version exposed to tasks via the `TRIGGER_REALTIME_STREAM_VERSION` variable. Distinct from `REALTIME_STREAMS_DEFAULT_VERSION`. One of `v1`, `v2`. |
140141
| `REALTIME_STREAM_MAX_LENGTH` | No | 1000 | Realtime stream max length. |

0 commit comments

Comments
 (0)