Railyard side of PY1.3 (RYP-D2, RYP-E1, SC-E3). Acceptance:
1. apps/insights: umami-software/umami v3.4.0 (MIT, commit ec0ff503),
vendored --depth 1, LICENSE kept, NOTICE added. Fork additions only:
src/railyard/{ingest,summary,tenancy,api-only}.ts, /v1/ingest/batch (the
edge collector contract v1, bearer INSIGHTS_INGEST_TOKEN, no IP ever,
retried batches de-duplicated by migration 90_railyard_ingest_receipts),
/api/v1/tenants/{org}/summary (bearer INSIGHTS_API_TOKEN), src/proxy.ts
(INSIGHTS_API_ONLY=1 serves only the Railyard API and the heartbeat).
Tenant isolation is tested at the API level (an app id owned by another org
is refused) and at the SQL level (upstream migrations 01-26 plus 90 on a
throwaway cluster: org B never reads org A's rows, even naming its app).
Upstream vitest suite: not run on the Mac (pnpm 12.3.4 pinned upstream,
disk floor); it runs in the image build on box 2 or CI.
2. No upstream product name in anything a customer loads: the page tag, the
console pages and the fork's additions (tests); the upstream dashboard is
never served in API-only mode.
3. The console writes the collector's site entry on "Add app", on
auto-created apps from deploys, and rewrites every entry on add-on, plan or
pause changes (lib/sites.ts, SITES KV binding). The bridge gains
`sites` (the project's app, site key, page tag and collector URLs, entry
written) and the analytics proof is the first event from Insights. The
console's Insights page shows visitors, events, first event and the
visit -> signup -> first action funnel.
5. insights-edge/src/caps.ts: at 100% of the cap events are still counted and
not stored until the next UTC month; the console shows the same message
from a byte-identical copy (lib/caps.ts, tested).
4 (384 MB at 50 events a second for 10 min) is measured on staging before deploy.
Env: INSIGHTS_API_URL, INSIGHTS_API_TOKEN, SITES KV binding (console);
INSIGHTS_INGEST_TOKEN, INSIGHTS_API_TOKEN, INSIGHTS_API_ONLY (Insights).
Tests: console 54/54 (tsc clean), insights fork 7/7 (incl. SQL isolation),
insights-edge caps + collector + sim 14/14, tests/contract 3/3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
254 lines
7.4 KiB
SQL
254 lines
7.4 KiB
SQL
-- create new hourly table
|
|
CREATE TABLE umami.website_event_stats_hourly_new
|
|
(
|
|
website_id UUID,
|
|
session_id UUID,
|
|
visit_id UUID,
|
|
hostname SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
browser LowCardinality(String),
|
|
os LowCardinality(String),
|
|
device LowCardinality(String),
|
|
screen LowCardinality(String),
|
|
language LowCardinality(String),
|
|
country LowCardinality(String),
|
|
region LowCardinality(String),
|
|
city String,
|
|
entry_url AggregateFunction(argMin, String, DateTime('UTC')),
|
|
exit_url AggregateFunction(argMax, String, DateTime('UTC')),
|
|
url_path SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
url_query SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
utm_source SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
utm_medium SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
utm_campaign SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
utm_content SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
utm_term SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
referrer_domain SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
page_title SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
gclid SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
fbclid SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
msclkid SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
ttclid SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
li_fat_id SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
twclid SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
event_type UInt32,
|
|
event_name SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
views SimpleAggregateFunction(sum, UInt64),
|
|
min_time SimpleAggregateFunction(min, DateTime('UTC')),
|
|
max_time SimpleAggregateFunction(max, DateTime('UTC')),
|
|
tag SimpleAggregateFunction(groupArrayArray, Array(String)),
|
|
distinct_id String,
|
|
created_at Datetime('UTC')
|
|
)
|
|
ENGINE = AggregatingMergeTree
|
|
PARTITION BY toYYYYMM(created_at)
|
|
ORDER BY (
|
|
website_id,
|
|
event_type,
|
|
toStartOfHour(created_at),
|
|
cityHash64(visit_id),
|
|
visit_id
|
|
)
|
|
SAMPLE BY cityHash64(visit_id);
|
|
|
|
-- create view
|
|
CREATE MATERIALIZED VIEW umami.website_event_stats_hourly_mv_new
|
|
TO umami.website_event_stats_hourly_new
|
|
AS
|
|
SELECT
|
|
website_id,
|
|
session_id,
|
|
visit_id,
|
|
hostnames as hostname,
|
|
browser,
|
|
os,
|
|
device,
|
|
screen,
|
|
language,
|
|
country,
|
|
region,
|
|
city,
|
|
entry_url,
|
|
exit_url,
|
|
url_paths as url_path,
|
|
url_query,
|
|
utm_source,
|
|
utm_medium,
|
|
utm_campaign,
|
|
utm_content,
|
|
utm_term,
|
|
referrer_domain,
|
|
page_title,
|
|
gclid,
|
|
fbclid,
|
|
msclkid,
|
|
ttclid,
|
|
li_fat_id,
|
|
twclid,
|
|
event_type,
|
|
event_name,
|
|
views,
|
|
min_time,
|
|
max_time,
|
|
tag,
|
|
distinct_id,
|
|
timestamp as created_at
|
|
FROM (SELECT
|
|
website_id,
|
|
session_id,
|
|
visit_id,
|
|
arrayFilter(x -> x != '', groupArray(hostname)) hostnames,
|
|
browser,
|
|
os,
|
|
device,
|
|
screen,
|
|
language,
|
|
country,
|
|
region,
|
|
city,
|
|
argMinState(url_path, created_at) entry_url,
|
|
argMaxState(url_path, created_at) exit_url,
|
|
arrayFilter(x -> x != '', groupArray(url_path)) as url_paths,
|
|
arrayFilter(x -> x != '', groupArray(url_query)) url_query,
|
|
arrayFilter(x -> x != '', groupArray(utm_source)) utm_source,
|
|
arrayFilter(x -> x != '', groupArray(utm_medium)) utm_medium,
|
|
arrayFilter(x -> x != '', groupArray(utm_campaign)) utm_campaign,
|
|
arrayFilter(x -> x != '', groupArray(utm_content)) utm_content,
|
|
arrayFilter(x -> x != '', groupArray(utm_term)) utm_term,
|
|
arrayFilter(x -> x != '' and x != hostname, groupArray(referrer_domain)) referrer_domain,
|
|
arrayFilter(x -> x != '', groupArray(page_title)) page_title,
|
|
arrayFilter(x -> x != '', groupArray(gclid)) gclid,
|
|
arrayFilter(x -> x != '', groupArray(fbclid)) fbclid,
|
|
arrayFilter(x -> x != '', groupArray(msclkid)) msclkid,
|
|
arrayFilter(x -> x != '', groupArray(ttclid)) ttclid,
|
|
arrayFilter(x -> x != '', groupArray(li_fat_id)) li_fat_id,
|
|
arrayFilter(x -> x != '', groupArray(twclid)) twclid,
|
|
event_type,
|
|
if(event_type = 2, groupArray(event_name), []) event_name,
|
|
sumIf(1, event_type = 1) views,
|
|
min(created_at) min_time,
|
|
max(created_at) max_time,
|
|
arrayFilter(x -> x != '', groupArray(tag)) tag,
|
|
distinct_id,
|
|
toStartOfHour(created_at) timestamp
|
|
FROM umami.website_event
|
|
GROUP BY website_id,
|
|
session_id,
|
|
visit_id,
|
|
hostname,
|
|
browser,
|
|
os,
|
|
device,
|
|
screen,
|
|
language,
|
|
country,
|
|
region,
|
|
city,
|
|
event_type,
|
|
distinct_id,
|
|
timestamp);
|
|
|
|
-- rename tables
|
|
RENAME TABLE umami.website_event_stats_hourly TO umami.website_event_stats_hourly_old;
|
|
RENAME TABLE umami.website_event_stats_hourly_new TO umami.website_event_stats_hourly;
|
|
|
|
-- drop views
|
|
DROP TABLE umami.website_event_stats_hourly_mv;
|
|
DROP TABLE umami.website_event_stats_hourly_mv_new;
|
|
|
|
-- recreate view
|
|
CREATE MATERIALIZED VIEW umami.website_event_stats_hourly_mv
|
|
TO umami.website_event_stats_hourly
|
|
AS
|
|
SELECT
|
|
website_id,
|
|
session_id,
|
|
visit_id,
|
|
hostnames as hostname,
|
|
browser,
|
|
os,
|
|
device,
|
|
screen,
|
|
language,
|
|
country,
|
|
region,
|
|
city,
|
|
entry_url,
|
|
exit_url,
|
|
url_paths as url_path,
|
|
url_query,
|
|
utm_source,
|
|
utm_medium,
|
|
utm_campaign,
|
|
utm_content,
|
|
utm_term,
|
|
referrer_domain,
|
|
page_title,
|
|
gclid,
|
|
fbclid,
|
|
msclkid,
|
|
ttclid,
|
|
li_fat_id,
|
|
twclid,
|
|
event_type,
|
|
event_name,
|
|
views,
|
|
min_time,
|
|
max_time,
|
|
tag,
|
|
distinct_id,
|
|
timestamp as created_at
|
|
FROM (SELECT
|
|
website_id,
|
|
session_id,
|
|
visit_id,
|
|
arrayFilter(x -> x != '', groupArray(hostname)) hostnames,
|
|
browser,
|
|
os,
|
|
device,
|
|
screen,
|
|
language,
|
|
country,
|
|
region,
|
|
city,
|
|
argMinState(url_path, created_at) entry_url,
|
|
argMaxState(url_path, created_at) exit_url,
|
|
arrayFilter(x -> x != '', groupArray(url_path)) as url_paths,
|
|
arrayFilter(x -> x != '', groupArray(url_query)) url_query,
|
|
arrayFilter(x -> x != '', groupArray(utm_source)) utm_source,
|
|
arrayFilter(x -> x != '', groupArray(utm_medium)) utm_medium,
|
|
arrayFilter(x -> x != '', groupArray(utm_campaign)) utm_campaign,
|
|
arrayFilter(x -> x != '', groupArray(utm_content)) utm_content,
|
|
arrayFilter(x -> x != '', groupArray(utm_term)) utm_term,
|
|
arrayFilter(x -> x != '' and x != hostname, groupArray(referrer_domain)) referrer_domain,
|
|
arrayFilter(x -> x != '', groupArray(page_title)) page_title,
|
|
arrayFilter(x -> x != '', groupArray(gclid)) gclid,
|
|
arrayFilter(x -> x != '', groupArray(fbclid)) fbclid,
|
|
arrayFilter(x -> x != '', groupArray(msclkid)) msclkid,
|
|
arrayFilter(x -> x != '', groupArray(ttclid)) ttclid,
|
|
arrayFilter(x -> x != '', groupArray(li_fat_id)) li_fat_id,
|
|
arrayFilter(x -> x != '', groupArray(twclid)) twclid,
|
|
event_type,
|
|
if(event_type = 2, groupArray(event_name), []) event_name,
|
|
sumIf(1, event_type = 1) views,
|
|
min(created_at) min_time,
|
|
max(created_at) max_time,
|
|
arrayFilter(x -> x != '', groupArray(tag)) tag,
|
|
distinct_id,
|
|
toStartOfHour(created_at) timestamp
|
|
FROM umami.website_event
|
|
GROUP BY website_id,
|
|
session_id,
|
|
visit_id,
|
|
hostname,
|
|
browser,
|
|
os,
|
|
device,
|
|
screen,
|
|
language,
|
|
country,
|
|
region,
|
|
city,
|
|
event_type,
|
|
distinct_id,
|
|
timestamp);
|