Skip to content

Commit 6bdf800

Browse files
authored
feat(clickhouse): replicate run plan type to task_runs_v2 (#3978)
Replicates `TaskRun.planType` into the `task_runs_v2` ClickHouse table so run analytics can group by plan type. Adds a `plan_type` column (goose migration `033`, `LowCardinality(String)`), the replication insert mapping, and the matching schema/column/type entries - same shape as the recent `region` addition. Write-once at trigger, so it just rides along on existing replicated rows. Internal analytics only; not exposed in the Query API.
1 parent 015106d commit 6bdf800

6 files changed

Lines changed: 28 additions & 0 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: improvement
4+
---
5+
6+
Store the run's plan type on the runs analytics table so reporting can group runs by plan.

apps/webapp/app/services/runsReplicationService.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,7 @@ export class RunsReplicationService {
11241124
run.bulkActionGroupIds ?? [], // bulk_action_group_ids
11251125
baseWorkerQueue(run.masterQueue ?? ""), // worker_queue (raw - operators slice by this)
11261126
run.region ?? "", // region (geo for customers)
1127+
run.planType ?? "", // plan_type
11271128
run.maxDurationInSeconds ?? null, // max_duration_in_seconds
11281129
annotations?.triggerSource ?? "", // trigger_source
11291130
annotations?.rootTriggerSource ?? "", // root_trigger_source

apps/webapp/test/runsReplicationService.part1.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ describe("RunsReplicationService (part 1/7)", () => {
8484
queue: "test",
8585
workerQueue: "us-east-1-next",
8686
region: "us-east-1",
87+
planType: "free",
8788
runtimeEnvironmentId: runtimeEnvironment.id,
8889
projectId: project.id,
8990
organizationId: organization.id,
@@ -126,6 +127,7 @@ describe("RunsReplicationService (part 1/7)", () => {
126127
// worker_queue stays the raw backing (operators); region is the geo (customers)
127128
worker_queue: "us-east-1-next",
128129
region: "us-east-1",
130+
plan_type: "free",
129131
})
130132
);
131133

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- +goose Up
2+
ALTER TABLE trigger_dev.task_runs_v2
3+
ADD COLUMN IF NOT EXISTS plan_type LowCardinality(String) DEFAULT '';
4+
5+
-- +goose Down
6+
ALTER TABLE trigger_dev.task_runs_v2
7+
DROP COLUMN IF EXISTS plan_type;

internal-packages/clickhouse/src/taskRuns.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ describe("Task Runs V2", () => {
8484
["bulk_action_group_id_1234", "bulk_action_group_id_1235"], // bulk_action_group_ids
8585
"", // worker_queue
8686
"", // region
87+
"", // plan_type
8788
null, // max_duration_in_seconds
8889
"", // trigger_source
8990
"", // root_trigger_source
@@ -217,6 +218,7 @@ describe("Task Runs V2", () => {
217218
[], // bulk_action_group_ids
218219
"", // worker_queue
219220
"", // region
221+
"", // plan_type
220222
null, // max_duration_in_seconds
221223
"", // trigger_source
222224
"", // root_trigger_source
@@ -273,6 +275,7 @@ describe("Task Runs V2", () => {
273275
[], // bulk_action_group_ids
274276
"", // worker_queue
275277
"", // region
278+
"", // plan_type
276279
null, // max_duration_in_seconds
277280
"", // trigger_source
278281
"", // root_trigger_source
@@ -376,6 +379,7 @@ describe("Task Runs V2", () => {
376379
[], // bulk_action_group_ids
377380
"", // worker_queue
378381
"", // region
382+
"", // plan_type
379383
null, // max_duration_in_seconds
380384
"", // trigger_source
381385
"", // root_trigger_source
@@ -487,6 +491,7 @@ describe("Task Runs V2", () => {
487491
[], // bulk_action_group_ids
488492
"", // worker_queue
489493
"", // region
494+
"", // plan_type
490495
null, // max_duration_in_seconds
491496
"", // trigger_source
492497
"", // root_trigger_source
@@ -543,6 +548,7 @@ describe("Task Runs V2", () => {
543548
[],
544549
"", // worker_queue
545550
"", // region
551+
"", // plan_type
546552
null,
547553
"",
548554
"",
@@ -605,6 +611,7 @@ describe("Task Runs V2", () => {
605611
[],
606612
"", // worker_queue
607613
"", // region
614+
"", // plan_type
608615
null,
609616
"",
610617
"",
@@ -661,6 +668,7 @@ describe("Task Runs V2", () => {
661668
[],
662669
"", // worker_queue
663670
"", // region
671+
"", // plan_type
664672
null,
665673
"",
666674
"",

internal-packages/clickhouse/src/taskRuns.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const TaskRunV2 = z.object({
4949
bulk_action_group_ids: z.array(z.string()).default([]),
5050
worker_queue: z.string().default(""),
5151
region: z.string().default(""),
52+
plan_type: z.string().default(""),
5253
max_duration_in_seconds: z.number().int().nullish(),
5354
trigger_source: z.string().default(""),
5455
root_trigger_source: z.string().default(""),
@@ -110,6 +111,7 @@ export const TASK_RUN_COLUMNS = [
110111
"bulk_action_group_ids",
111112
"worker_queue",
112113
"region",
114+
"plan_type",
113115
"max_duration_in_seconds",
114116
"trigger_source",
115117
"root_trigger_source",
@@ -178,6 +180,7 @@ export type TaskRunFieldTypes = {
178180
bulk_action_group_ids: string[];
179181
worker_queue: string;
180182
region: string;
183+
plan_type: string;
181184
max_duration_in_seconds: number | null;
182185
trigger_source: string;
183186
root_trigger_source: string;
@@ -317,6 +320,7 @@ export type TaskRunInsertArray = [
317320
bulk_action_group_ids: string[],
318321
worker_queue: string,
319322
region: string,
323+
plan_type: string,
320324
max_duration_in_seconds: number | null,
321325
trigger_source: string,
322326
root_trigger_source: string,

0 commit comments

Comments
 (0)