Commit bfa08b5
committed
Backfill WAS_RUNNING events for running apps, tasks, and service instances
Seed a synthetic WAS_RUNNING usage event for every currently-running app
process, a TASK_WAS_RUNNING event for every currently-running task, and a
WAS_RUNNING event for every existing service instance, so billing consumers
can bootstrap a complete baseline even after the original
STARTED/TASK_STARTED/CREATED events have been pruned.
The backfill is a batched, idempotent VCAP::WasRunningBackfill helper invoked
from thin no_transaction migrations (mirrors the bigint-migration pattern):
each batch keysets over the started processes / running tasks / service
instances by id and runs in its own READ COMMITTED transaction, so no
statement risks the migration timeout and MySQL's INSERT..SELECT takes no
shared next-key locks on the scanned source rows while the API serves
traffic. The app backfill scopes the package/droplet aggregates to each
batch's apps (index-backed) to keep package_state fidelity without scanning
the whole tables, and COALESCEs nullable legacy process/app/task columns so a
single NULL row cannot abort a deploy.
Because the API stays live during migrations, a batch can race a concurrent
stop/delete and insert a baseline row that no later ending event would ever
prune; a post-seed sweep removes WAS_RUNNING/TASK_WAS_RUNNING rows whose
resource is no longer running/present.
A skip_was_running_backfill config flag lets operators opt out (checked by the
migrations, not the helper, since the migrations are recorded as applied
either way); 'rake db:was_running_backfill' re-runs the seeding later for
operators who skipped. Rollback deletes are batched too.
Document the WAS_RUNNING/TASK_WAS_RUNNING states and their created_at
(migration-time) semantics on the V3 resources, and list the new states in
the legacy V2 usage-event docs because V2 reads the same event rows.1 parent 8508a76 commit bfa08b5
19 files changed
Lines changed: 1041 additions & 2 deletions
File tree
- db/migrations
- docs
- v2
- app_usage_events
- service_usage_events
- v3/source/includes/resources
- app_usage_events
- service_usage_events
- lib
- cloud_controller/config_schemas
- database
- tasks
- spec
- api/documentation
- migrations
- helpers
- unit/lib/database
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
631 | 631 | | |
632 | 632 | | |
633 | 633 | | |
| 634 | + | |
634 | 635 | | |
635 | 636 | | |
636 | 637 | | |
| 638 | + | |
637 | 639 | | |
638 | 640 | | |
639 | 641 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| 293 | + | |
293 | 294 | | |
294 | 295 | | |
295 | 296 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
0 commit comments