Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/cli/src/server/local-schema-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,19 @@ export const LOCAL_SCHEMA_HISTORY: ReadonlyArray<LocalSchemaHistoryEntry> = Obje
manifestDigest: "09eeccdbd568e6d550b739bb05e074dedb399720902b35577d4eb963c48b0a53",
projectRevision: "ed74788ef292834069e0ea6ee3b22d68fc604fb66cb54d2d551db67ce8d20b3a",
}),
Object.freeze({
// v25 partitions trace_facets_hourly by day (Tinybird rejects a TTL shorter
// than the partition period); the rollup is recreated and rebuilt.
//
// projectRevision is carried forward deliberately: it is a hardcoded
// constant that no longer tracks the generator's header, and the identity
// this gate compares is the fingerprint/digest pair.
version: 25,
fingerprint: "bfaed79bcf2423f5",
digest: "bfaed79bcf2423f532b582ab321d4b5f55410853cb381cad1df7041e0663f941",
manifestDigest: "005ad815cff50e1c642dfc696cf423d7d9a3c7ee58b8cdcd4ad647bf35ab1297",
projectRevision: "ed74788ef292834069e0ea6ee3b22d68fc604fb66cb54d2d551db67ce8d20b3a",
}),
] as const)

/** Immutable SQLite control DDL identities, checked by clickhouse:schema:check. */
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/server/local-schema-version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Increment this value for every structural change to the generated local
// schema. The compatibility manifest and migration registry must be updated in
// the same change before a new value can ship.
export const LOCAL_SCHEMA_VERSION = 24 as const
export const LOCAL_SCHEMA_VERSION = 25 as const

/** SQLite eventing state has its own independent version sequence. */
export const LOCAL_CONTROL_SCHEMA_VERSION = 1 as const
42 changes: 35 additions & 7 deletions apps/cli/src/server/local-store-migrations/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import {
} from "./step-executor"
import type { StateDispositionEntry } from "../local-store-migration-module"

/** Rebuilds the facet rollup from every retained root span; the truncate makes a resumed step converge. */
const TRACE_FACETS_HOURLY_BACKFILL = [
"TRUNCATE TABLE IF EXISTS trace_facets_hourly",
"INSERT INTO trace_facets_hourly (OrgId, Hour, ServiceName, SpanName, HttpMethod, HttpStatusCode, DeploymentEnv, ServiceNamespace, HasError, TraceCount, DurationMin, DurationMax, DurationQuantiles) SELECT OrgId, toStartOfHour(Timestamp) AS Hour, ServiceName, SpanName, HttpMethod, HttpStatusCode, DeploymentEnv, ServiceNamespace, HasError, count() AS TraceCount, min(Duration) AS DurationMin, max(Duration) AS DurationMax, quantilesTDigestState(0.5, 0.95)(Duration) AS DurationQuantiles FROM trace_list_mv GROUP BY OrgId, Hour, ServiceName, SpanName, HttpMethod, HttpStatusCode, DeploymentEnv, ServiceNamespace, HasError",
] as const

/** Existing rollup rows keep what the old view bodies wrote and age out with their TTL. */
const ERROR_RETENTION = {
preservationInterval: "error retention horizon",
Expand Down Expand Up @@ -1054,19 +1060,13 @@ export const LOCAL_STORE_STEPS: ReadonlyArray<StepSpec> = [
},
{
// Both objects are new; the backfill rolls up the root spans already retained.
// A resumed step re-runs afterBootstrap on the staged target, hence the truncate.
id: "local-0023-to-0024-trace-facets-hourly",
from: 23,
to: 24,
description:
"Create trace_facets_hourly and its materialized view, backfilled from trace_list_mv, so the traces sidebar facets read an hourly rollup",
clonedBefore: "any DDL runs",
afterBootstrap: [
backfill(
"TRUNCATE TABLE IF EXISTS trace_facets_hourly",
"INSERT INTO trace_facets_hourly (OrgId, Hour, ServiceName, SpanName, HttpMethod, HttpStatusCode, DeploymentEnv, ServiceNamespace, HasError, TraceCount, DurationMin, DurationMax, DurationQuantiles) SELECT OrgId, toStartOfHour(Timestamp) AS Hour, ServiceName, SpanName, HttpMethod, HttpStatusCode, DeploymentEnv, ServiceNamespace, HasError, count() AS TraceCount, min(Duration) AS DurationMin, max(Duration) AS DurationMax, quantilesTDigestState(0.5, 0.95)(Duration) AS DurationQuantiles FROM trace_list_mv GROUP BY OrgId, Hour, ServiceName, SpanName, HttpMethod, HttpStatusCode, DeploymentEnv, ServiceNamespace, HasError",
),
],
afterBootstrap: [backfill(...TRACE_FACETS_HOURLY_BACKFILL)],
plan: [
[
"create-trace-facets-hourly",
Expand All @@ -1086,5 +1086,33 @@ export const LOCAL_STORE_STEPS: ReadonlyArray<StepSpec> = [
},
],
},
{
// Partitioning cannot be altered in place, so the rollup is recreated and rebuilt.
id: "local-0024-to-0025-trace-facets-hourly-daily-partition",
from: 24,
to: 25,
description: "Recreate trace_facets_hourly partitioned by day and rebuild it from trace_list_mv",
clonedBefore: "any DDL runs",
beforeBootstrap: [dropViews("trace_facets_hourly_mv"), dropTables("trace_facets_hourly")],
afterBootstrap: [backfill(...TRACE_FACETS_HOURLY_BACKFILL)],
plan: [
[
"recreate-trace-facets-hourly",
"Drop trace_facets_hourly and its view, recreate both partitioned by day, and backfill from trace_list_mv",
],
],
verifies: "Verify the v25 physical schema and the retained raw telemetry counts",
dispositions: [
{
name: "trace_facets_hourly",
classification: "derived",
disposition: "rebuild-within-retention-horizon",
guarantee: "Rebuilt from every root span trace_list_mv retains; both keep 30 days.",
preservationInterval: "source retention horizon",
sourceRetentionDays: 30,
targetRetentionDays: 30,
},
],
},
// local-schema:bump appends the next step above this line.
]
3 changes: 3 additions & 0 deletions apps/cli/src/server/schema-identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import schemaV21Sql from "./schema/local-schema-v21.sql" with { type: "text" }
import schemaV22Sql from "./schema/local-schema-v22.sql" with { type: "text" }
import schemaV23Sql from "./schema/local-schema-v23.sql" with { type: "text" }
import schemaV24Sql from "./schema/local-schema-v24.sql" with { type: "text" }
import schemaV25Sql from "./schema/local-schema-v25.sql" with { type: "text" }
import { schemaDigest as digestSchema, schemaFingerprint as fingerprintSchema } from "./store-version"
import { buildLocalSchemaManifest, type LocalSchemaManifest } from "./schema-manifest"
import { LOCAL_SCHEMA_VERSION } from "./local-schema-version"
Expand Down Expand Up @@ -91,6 +92,7 @@ const SNAPSHOT_SQL: ReadonlyArray<string> = [
schemaV22Sql,
schemaV23Sql,
schemaV24Sql,
schemaV25Sql,
]

export interface LocalSchemaSnapshot {
Expand Down Expand Up @@ -172,6 +174,7 @@ export const LOCAL_SCHEMA_V21 = localSchemaIdentity(21)
export const LOCAL_SCHEMA_V22 = localSchemaIdentity(22)
export const LOCAL_SCHEMA_V23 = localSchemaIdentity(23)
export const LOCAL_SCHEMA_V24 = localSchemaIdentity(24)
export const LOCAL_SCHEMA_V25 = localSchemaIdentity(25)

export const CURRENT_LOCAL_SCHEMA: LocalSchemaIdentity = Object.freeze({
version: LOCAL_SCHEMA_VERSION,
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/server/schema/local-inserts.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"projectRevision": "fdd5816bd9f83325d3bcc1eac0c3d5a872035552bbb1ed9600d7c8464692fe89",
"projectRevision": "92181b09631cc85a9bfc1ea57dc85000f3c6770b0799e5b357692f4634ce8042",
"orgPlaceholder": "__ORG__",
"datasources": {
"traces": {
Expand Down
Loading
Loading