Skip to content

Commit df221df

Browse files
committed
server: Reset all the data
1 parent be4807a commit df221df

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- apply changes
2+
--
3+
-- One-shot data reset for the v1 -> v2 metric-model transition.
4+
--
5+
-- Background: a metric's identity is its hash (orm queries supply it from the
6+
-- SQL, independent of the metric name). On ingest an existing app_metric row is
7+
-- matched by hash and reused as-is; its name/tags are never refreshed. So when a
8+
-- v2 client begins reporting an already-seen hash, the server keeps the stale v1
9+
-- name (e.g. orm.DMessage.findMessages) instead of the v2 family name
10+
-- (ebean.query + label tag). The app_metric catalog has no retention, so those
11+
-- stale rows never age out on their own.
12+
--
13+
-- This migration empties all metric data and the catalog so the next ingest
14+
-- recreates rows with their current (v2) name/tags. It deliberately does NOT
15+
-- drop the schema: the Ebean db_migration history table lives in this schema,
16+
-- and dropping it would break the migration run and leave the tables un-rebuilt.
17+
-- Truncating keeps the schema, partitions and migration history intact while
18+
-- clearing every row.
19+
--
20+
-- PRECONDITION: only deploy once the forwarding apps emit v2 for ALL queries
21+
-- (insight top --by name shows only ebean.txn / ebean.query, no orm.* rows).
22+
-- Otherwise v1 forwarders immediately refill the old-semantic rows.
23+
--
24+
-- Runs exactly once per database via migration.run (dev/test/na/apac), so no
25+
-- kubectl/DB access is required and there is nothing to remove afterwards.
26+
-- Truncating a partitioned parent truncates all of its partitions; cascade
27+
-- handles foreign-key order; restart identity resets the id sequences.
28+
-- The job control table is intentionally left alone (managed by DJob.initRollup).
29+
30+
truncate table
31+
ebean_insight.timed_entry,
32+
ebean_insight.timed_m1,
33+
ebean_insight.timed_m10,
34+
ebean_insight.timed_m60,
35+
ebean_insight.timed_d1,
36+
ebean_insight.gauge_entry,
37+
ebean_insight.gauge_m1,
38+
ebean_insight.gauge_m10,
39+
ebean_insight.gauge_m60,
40+
ebean_insight.gauge_d1,
41+
ebean_insight.rollup_job,
42+
ebean_insight.query_plan_change,
43+
ebean_insight.query_plan,
44+
ebean_insight.capture_request,
45+
ebean_insight.app_metric,
46+
ebean_insight.app_pod,
47+
ebean_insight.app_db,
48+
ebean_insight.app,
49+
ebean_insight.env
50+
restart identity cascade;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- extends db partitions
2+
select partition('day', 'gauge_entry', 4);
3+
select partition('day', 'timed_entry', 4);
4+
select partition('day', 'timed_m1', 4);
5+
select partition('day', 'gauge_m1', 4);
6+
select partition('day', 'timed_m10', 4);
7+
select partition('day', 'gauge_m10', 4);
8+
select partition('day', 'timed_m60', 4);
9+
select partition('day', 'gauge_m60', 4);
10+
select partition('day', 'timed_d1', 4);
11+
select partition('day', 'gauge_d1', 4);

server/src/main/resources/dbmigration/idx_postgres.migrations

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
-1362069816, 1.2__plan_shape.sql
55
702796780, 1.3__plan_change.sql
66
85386349, 1.4__metric_tags.sql
7+
1704466480, 1.5__reset_data.sql
8+
1157210771, 1.6__base_partitions.sql
79

0 commit comments

Comments
 (0)