defmodule Vigil.Repo.Migrations.CreatePerformance do
use Ecto.Migration
# Slice 6 (ROADMAP.md): spans from both SDKs in one table (partitioned by
# UUIDv7 id, a partition a day), transactions rolled up per (project,
# name, op, method) with GlitchTip's 50-bucket duration histogram, and
# hourly per-transaction stats (partitioned weekly). Errors link to
# traces through issue_events.trace_id.
def up do
execute """
CREATE TABLE spans (
id uuid NOT NULL,
project_id uuid NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
organization_id uuid NOT NULL,
trace_id varchar(32) NOT NULL,
span_id varchar(16) NOT NULL,
parent_span_id varchar(16),
segment_id varchar(16),
is_segment boolean NOT NULL DEFAULT false,
transaction_group_id uuid,
transaction varchar(1024),
op varchar(255),
description text,
status varchar(64),
start_at timestamp(6) NOT NULL,
duration_ms double precision NOT NULL,
environment varchar(255),
release varchar(250),
event_id varchar(32),
attributes jsonb NOT NULL DEFAULT '{}',
PRIMARY KEY (id)
) PARTITION BY RANGE (id)
"""
execute "CREATE INDEX spans_project_trace_index ON spans (project_id, trace_id)"
execute "CREATE INDEX spans_organization_trace_index ON spans (organization_id, trace_id)"
execute """
CREATE INDEX spans_group_segments_index ON spans (transaction_group_id, id DESC)
WHERE is_segment
"""
create table(:transaction_groups, primary_key: false) do
add :id, :binary_id, primary_key: true
add :project_id, references(:projects, type: :binary_id, on_delete: :delete_all),
null: false
add :organization_id, :binary_id, null: false
add :name, :string, size: 1024, null: false
add :op, :string, null: false, default: ""
add :method, :string, null: false, default: ""
add :first_seen, :utc_datetime_usec, null: false
add :last_seen, :utc_datetime_usec, null: false
add :count, :bigint, null: false, default: 0
add :error_count, :bigint, null: false, default: 0
add :duration_sum, :float, null: false, default: 0.0
add :histogram, {:array, :integer}, null: false
end
create unique_index(:transaction_groups, [:project_id, :name, :op, :method])
create index(:transaction_groups, [:project_id, :last_seen])
execute """
CREATE TABLE transaction_counts (
transaction_group_id uuid NOT NULL REFERENCES transaction_groups (id) ON DELETE CASCADE,
hour timestamp NOT NULL,
count bigint NOT NULL DEFAULT 0,
error_count bigint NOT NULL DEFAULT 0,
duration_sum double precision NOT NULL DEFAULT 0,
PRIMARY KEY (transaction_group_id, hour)
) PARTITION BY RANGE (hour)
"""
execute "ALTER TABLE issue_events ADD COLUMN trace_id varchar(32)"
execute """
CREATE INDEX issue_events_project_trace_index ON issue_events (project_id, trace_id)
WHERE trace_id IS NOT NULL
"""
end
def down do
execute "DROP INDEX issue_events_project_trace_index"
execute "ALTER TABLE issue_events DROP COLUMN trace_id"
execute "DROP TABLE transaction_counts"
drop table(:transaction_groups)
execute "DROP TABLE spans"
end
end
neiam
/vigil
public · Issues · Pulls · Labels · Forks · Compare · Actions running · Badges · Packages
⭐
Log in to mark this repository.
3.2 KiB · text
History
bbb2a48