Skip to content

Commit f5335be

Browse files
committed
RHINENG-24787: fix test_generate_data; update docs
1 parent 6369972 commit f5335be

3 files changed

Lines changed: 35 additions & 29 deletions

File tree

dev/test_generate_data.sql

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ create table if not exists _const (
99
truncate table _const ;
1010
insert into _const values -- counts in prod 2022/02
1111
('accounts', 50), -- 50k -- number of rh_accounts
12-
('systems', 7500), -- 750k -- number of systems(_platform)
12+
('systems', 10), -- 750k -- number of system_inventory rows (each with system_patch)
1313
('advisories', 320), -- 50k -- number of advisory_metadata
1414
('repos', 350), -- 55k -- number of repos
1515
('package_names', 300), -- 58k -- number of package_name
@@ -76,10 +76,10 @@ $$
7676
;
7777

7878

79-
-- generate systems
79+
-- generate systems (system_inventory + system_patch per host)
8080
-- duration: 55s / 1M systems (on RDS)
8181
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
82-
alter sequence system_platform_id_seq restart with 1;
82+
alter sequence system_inventory_id_seq restart with 1;
8383
do $$
8484
declare
8585
cnt int := 0;
@@ -90,11 +90,12 @@ do $$
9090
rnd float;
9191
json_data text[];
9292
json_hash text[];
93-
json_rnd int;
9493
rnd_date1 timestamp with time zone;
9594
rnd_date2 timestamp with time zone;
95+
acc_id int;
96+
new_id bigint;
97+
ji int;
9698
begin
97-
--select count(*) into cnt from system_platform;
9899
select val into wanted from _const where key = 'systems';
99100
select val into progress from _const where key = 'progress_pct';
100101
select count(*) into rh_accounts from rh_account;
@@ -105,21 +106,27 @@ do $$
105106
rnd := random();
106107
rnd_date1 := now() - make_interval(days => (rnd*30)::int);
107108
rnd_date2 := rnd_date1 + make_interval(days => (rnd*10)::int);
108-
insert into system_platform
109+
acc_id := trunc(rnd*rh_accounts)+1;
110+
ji := trunc(rnd*3)+1;
111+
insert into system_inventory
109112
(inventory_id, display_name, rh_account_id, vmaas_json, json_checksum,
110-
last_updated, unchanged_since, last_upload, last_evaluation,
113+
last_upload, arch, tags, created, os_name, os_major, rhsm_version)
114+
values
115+
(gen_uuid, gen_uuid::text, acc_id, json_data[ji], json_hash[ji],
116+
rnd_date2, 'x86_64', '[]'::jsonb, rnd_date1, 'RHEL', 8, '8.0')
117+
returning id into new_id;
118+
insert into system_patch
119+
(rh_account_id, system_id, last_evaluation,
111120
packages_installed, packages_installable, packages_applicable)
112121
values
113-
(gen_uuid, gen_uuid, trunc(rnd*rh_accounts)+1, json_data[trunc(rnd*3)], json_hash[trunc(rnd*3)],
114-
rnd_date2, rnd_date1, rnd_date2, rnd_date2,
115-
trunc(rnd*1000), trunc(rnd*50), trunc(rnd*50))
116-
on conflict do nothing;
117-
if mod(cnt, (wanted*progress/100)::int) = 0 then
118-
raise notice 'created % system_platforms', cnt;
122+
(acc_id, new_id, rnd_date2,
123+
trunc(rnd*1000), trunc(rnd*50), trunc(rnd*50));
124+
if mod(cnt, greatest(1, ceil((wanted::numeric * progress) / 100.0)::int)) = 0 then
125+
raise notice 'created % systems (inventory + patch)', cnt;
119126
end if;
120127
cnt := cnt + 1;
121128
end loop;
122-
raise notice 'created % system_platforms', wanted;
129+
raise notice 'created % systems (inventory + patch)', wanted;
123130
end;
124131
$$
125132
;
@@ -182,11 +189,11 @@ do $$
182189
select val into adv_per_system from _const where key = 'adv_per_system';
183190
select val * adv_per_system into wanted from _const where key = 'systems';
184191
select val into progress from _const where key = 'progress_pct';
185-
select count(*) into systems from system_platform;
192+
select count(*) into systems from system_inventory;
186193
select count(*) into advs from advisory_metadata;
187194
select count(*) into stat from status;
188195
<<systems>>
189-
for row in select rh_account_id, id from system_platform
196+
for row in select rh_account_id, id from system_inventory
190197
loop
191198
-- assign random 0-2*adv_per_system advisories to system
192199
rnd := random() * 2 * adv_per_system;
@@ -204,7 +211,7 @@ do $$
204211
cnt := cnt + rnd::int;
205212
if cnt > nextpct then
206213
raise notice 'created % system_advisories', cnt;
207-
nextpct := nextpct + (wanted*progress/100)::int;
214+
nextpct := nextpct + greatest(1, ceil((wanted::numeric * progress) / 100.0)::int);
208215
end if;
209216
exit systems when cnt > wanted;
210217
end loop; -- <<systems>>
@@ -252,10 +259,10 @@ do $$
252259
select val into repo_per_system from _const where key = 'repo_per_system';
253260
select val * repo_per_system into wanted from _const where key = 'systems';
254261
select val into progress from _const where key = 'progress_pct';
255-
select count(*) into systems from system_platform;
262+
select count(*) into systems from system_inventory;
256263
select count(*) into repos from repo;
257264
<<systems>>
258-
for row in select rh_account_id, id from system_platform
265+
for row in select rh_account_id, id from system_inventory
259266
loop
260267
-- assign random 0-2*repo_per_system repos per system
261268
rnd := random() * 2 * repo_per_system;
@@ -266,7 +273,7 @@ do $$
266273
values
267274
(row.rh_account_id, row.id, trunc(repos*rnd2)+1)
268275
on conflict do nothing;
269-
if mod(cnt, (wanted*progress/100)::int) = 0 then
276+
if mod(cnt, greatest(1, ceil((wanted::numeric * progress) / 100.0)::int)) = 0 then
270277
raise notice 'created % system_repos', cnt;
271278
end if;
272279
cnt := cnt + 1;
@@ -293,7 +300,7 @@ do $$
293300
values (id, 'package' || id )
294301
on conflict do nothing;
295302
cnt := cnt + 1;
296-
if mod(cnt, (wanted*progress/100)::int) = 0 then
303+
if mod(cnt, greatest(1, ceil((wanted::numeric * progress) / 100.0)::int)) = 0 then
297304
raise notice 'created % package names', cnt;
298305
end if;
299306
end loop;
@@ -325,7 +332,7 @@ do $$
325332
values (id, name_id, id || '.' || id || '-1.el8.x86_64', '0', '0', advisory_id)
326333
on conflict do nothing;
327334
cnt := cnt + 1;
328-
if mod(cnt, (wanted*progress/100)::int) = 0 then
335+
if mod(cnt, greatest(1, ceil((wanted::numeric * progress) / 100.0)::int)) = 0 then
329336
raise notice 'created % packages', cnt;
330337
end if;
331338
end loop;
@@ -365,21 +372,21 @@ do $$
365372
insert into system_package2 (rh_account_id, system_id, name_id, package_id, installable_id, applicable_id)
366373
(select row.id, sp.id, p.name_id, p.id, p.id, p.id
367374
from (select id, name_id from package limit rnd1::int offset rnd2::int) p,
368-
(select id from system_platform where rh_account_id = row.id) sp
375+
(select id from system_inventory where rh_account_id = row.id) sp
369376
)
370377
on conflict do nothing;
371378
cnt := cnt + 1;
372379
if cnt > nextpct then
373380
raise notice 'created system_packages for % accounts', cnt;
374-
nextpct := nextpct + (wanted*progress/100)::int;
381+
nextpct := nextpct + greatest(1, ceil((wanted::numeric * progress) / 100.0)::int);
375382
end if;
376383
exit when cnt > wanted;
377384
end loop;
378385
end;
379386
$$
380387
;
381388

382-
-- show size of whole system_platform table
389+
-- show partition sizes for large system tables
383390
SELECT
384391
parent.relname AS parent,
385392
child.relname AS child,
@@ -388,4 +395,4 @@ SELECT
388395
FROM pg_inherits
389396
JOIN pg_class parent ON pg_inherits.inhparent = parent.oid
390397
JOIN pg_class child ON pg_inherits.inhrelid = child.oid
391-
WHERE parent.relname in ('system_platform', 'system_package2');
398+
WHERE parent.relname in ('system_inventory', 'system_patch', 'system_package2');

docs/md/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on [this service](https://github.com/RedHatInsights/insights-rbac), however it c
1616
`ENABLE_RBAC=no`. See [component environment variables](../../conf/manager.env)
1717

1818
- **listener** - connects to the Kafka service, and listens for messages about newly uploaded archives. When a new
19-
archive is uploaded, it upserts **`system_inventory`** (including `vmaas_json` with installed packages, repos, and modules) and the matching **`system_patch`** row; it does not write to a monolithic **`system_platform`** table (that name may exist only as a **SQL VIEW** for compatibility). Upload locks and checksum logic apply to **`system_inventory`**. It registers repositories for the system by pairing `repo` with the internal system id (**`system_inventory.id`**) through **`system_repo`**. After that it sends a
19+
archive is uploaded, it upserts **`system_inventory`** (including `vmaas_json` with installed packages, repos, and modules) and the matching **`system_patch`** row. Upload locks and checksum logic apply to **`system_inventory`**. It registers repositories for the system by pairing `repo` with the internal system id (**`system_inventory.id`**) through **`system_repo`**. After that it sends a
2020
Kafka message (`patchman.evaluator.upload` topic) to evaluate the system with the `evaluator-upload` component. This
2121
component also handles system deleting events (`platform.inventory.events` Kafka topic).
2222
See [component environment variables](../../conf/listener.env)

docs/md/database.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
Main database tables description:
55
- **system_inventory** — Partitioned table for the registered host / inventory profile: internal `id`, Insights `inventory_id`, `rh_account_id`, `vmaas_json` (packages, repos, modules for VMaaS), `yum_updates` and related checksums, staleness and culling timestamps, `display_name`, OS fields, tags/workspaces, and workload flags. **`system_repo`** (and similar link tables) use this internal `id` as the system key. The **listener** upserts rows here and relies on **system_inventory** for upload locks and unchanged detection; the **evaluator** reads it via a join to **system_patch**.
66
- **system_patch** — Partitioned evaluation output for each system, keyed by `rh_account_id` and `system_id` where `system_id` equals **system_inventory.id** on the same account. Holds advisory and package count caches, `last_evaluation`, `third_party`, `template_id`, and related aggregates. Rows are created or updated by the **listener** together with **system_inventory**; the **evaluator** persists evaluation results here (not into a single legacy table).
7-
- **system_platform** (compatibility) — The schema may define **`system_platform` as a SQL VIEW** over `system_inventory` joined to `system_patch` on `system_inventory.id = system_patch.system_id` (and matching `rh_account_id`). A future migration could remove the view. Go code loads the combined shape as **SystemPlatformV2** (`Inventory` + `Patch`) rather than a monolithic `SystemPlatform` ORM model.
87
- **advisory_metadata** - stores info about advisories (`description`, `summary`, `solution` etc.). It's synced and stored on trigger by `vmaas_sync` component. It allows to display detail information about the advisory.
98
- **system_advisories** - stores info about advisories evaluated for particular systems (system - advisory M-N mapping table). `system_id` references **system_inventory.id**. Contains info when system advisory was firstly reported and patched (if so). Records are created and updated by `evaluator` component. It allows to display list of advisories related to a system.
109
- **advisory_account_data** - stores info about all advisories detected within at least one system that belongs to a given account. So it provides overall statistics about system advisories displayed by the application.
@@ -13,6 +12,6 @@ Main database tables description:
1312
- **system_package2** - list of packages installed on a system
1413

1514
## Schema
16-
The ERD image below may lag `database_admin/schema/create_schema.sql` (for example if it still shows **`system_platform`** as a base table while the physical tables are **system_inventory** and **system_patch**).
15+
The ERD image below may lag `database_admin/schema/create_schema.sql`; for systems it may not reflect the split between **system_inventory** (host profile / upload payload) and **system_patch** (evaluation caches and aggregates).
1716

1817
![](graphics/db_diagram.png)

0 commit comments

Comments
 (0)