|
| 1 | +-- Load-test generator for system_inventory (+ required rh_account, system_patch). |
| 2 | +-- Faster subset of dev/test_generate_data.sql (no advisories, repos, packages, etc.). |
| 3 | +\timing on |
| 4 | +\set ON_ERROR_STOP on |
| 5 | + |
| 6 | +CREATE TABLE IF NOT EXISTS _const ( |
| 7 | + key TEXT PRIMARY KEY, |
| 8 | + val INT |
| 9 | +); |
| 10 | + |
| 11 | +TRUNCATE _const; |
| 12 | +INSERT INTO _const VALUES |
| 13 | + ('accounts', 50), -- rh_account rows |
| 14 | + ('systems', 7500), -- system_inventory + system_patch rows |
| 15 | + ('progress_pct', 10); -- progress NOTICE every N% |
| 16 | + |
| 17 | +-- Minimal vmaas_json samples (same as test_generate_data.sql) |
| 18 | +CREATE TABLE IF NOT EXISTS _json ( |
| 19 | + id INT PRIMARY KEY, |
| 20 | + data TEXT, |
| 21 | + hash TEXT |
| 22 | +); |
| 23 | +INSERT INTO _json VALUES |
| 24 | + (1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}'), |
| 25 | + (2, '{ "package_list": [ "libsmbclient-4.6.2-12.el7_4.x86_64", "dconf-0.26.0-2.el7.x86_64"]}'), |
| 26 | + (3, '{ "repository_list": [ "rhel-7-server-rpms" ], "releasever": "7Server", "basearch": "x86_64", "package_list": [ "libsmbclient-4.6.2-12.el7_4.x86_64"]}') |
| 27 | +ON CONFLICT DO NOTHING; |
| 28 | +UPDATE _json SET hash = encode(sha256(data::bytea), 'hex'); |
| 29 | + |
| 30 | +-- Wipes accounts and all dependent host data (inventory, patch, advisories links, packages, …) |
| 31 | +TRUNCATE rh_account CASCADE; |
| 32 | + |
| 33 | +ALTER SEQUENCE rh_account_id_seq RESTART WITH 1; |
| 34 | +DO $$ |
| 35 | +DECLARE |
| 36 | + cnt INT := 0; |
| 37 | + wanted INT; |
| 38 | + id INT; |
| 39 | +BEGIN |
| 40 | + SELECT val INTO wanted FROM _const WHERE key = 'accounts'; |
| 41 | + WHILE cnt < wanted LOOP |
| 42 | + id := nextval('rh_account_id_seq'); |
| 43 | + INSERT INTO rh_account (id, org_id) VALUES (id, 'RHACCOUNT-' || id); |
| 44 | + cnt := cnt + 1; |
| 45 | + END LOOP; |
| 46 | + RAISE NOTICE 'created % rh_accounts', wanted; |
| 47 | +END; |
| 48 | +$$; |
| 49 | + |
| 50 | +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; |
| 51 | +ALTER SEQUENCE system_inventory_id_seq RESTART WITH 1; |
| 52 | + |
| 53 | +DO $$ |
| 54 | +DECLARE |
| 55 | + cnt INT := 0; |
| 56 | + wanted INT; |
| 57 | + progress INT; |
| 58 | + gen_uuid UUID; |
| 59 | + rh_accounts INT; |
| 60 | + rnd FLOAT; |
| 61 | + json_data TEXT[]; |
| 62 | + json_hash TEXT[]; |
| 63 | + rnd_date1 TIMESTAMPTZ; |
| 64 | + rnd_date2 TIMESTAMPTZ; |
| 65 | + acc_id INT; |
| 66 | + new_id BIGINT; |
| 67 | + ji INT; |
| 68 | + workspace_ids UUID[]; |
| 69 | +BEGIN |
| 70 | + SELECT val INTO wanted FROM _const WHERE key = 'systems'; |
| 71 | + SELECT val INTO progress FROM _const WHERE key = 'progress_pct'; |
| 72 | + SELECT count(*) INTO rh_accounts FROM rh_account; |
| 73 | + json_data := array(SELECT data FROM _json ORDER BY id); |
| 74 | + json_hash := array(SELECT hash FROM _json ORDER BY id); |
| 75 | + workspace_ids := array(SELECT uuid_generate_v4() FROM generate_series(1, 3)); |
| 76 | + |
| 77 | + WHILE cnt < wanted LOOP |
| 78 | + gen_uuid := uuid_generate_v4(); |
| 79 | + rnd := random(); |
| 80 | + rnd_date1 := now() - make_interval(days => (rnd * 30)::INT); |
| 81 | + rnd_date2 := rnd_date1 + make_interval(days => (rnd * 10)::INT); |
| 82 | + acc_id := trunc(rnd * rh_accounts) + 1; |
| 83 | + ji := trunc(rnd * 3) + 1; |
| 84 | + |
| 85 | + INSERT INTO system_inventory |
| 86 | + (inventory_id, display_name, rh_account_id, vmaas_json, json_checksum, |
| 87 | + last_updated, last_upload, arch, tags, created, os_name, os_major, rhsm_version, |
| 88 | + workspaces, workspace_id, workspace_name) |
| 89 | + VALUES |
| 90 | + (gen_uuid, gen_uuid::text, acc_id, json_data[ji], json_hash[ji], |
| 91 | + rnd_date2, rnd_date2, 'x86_64', '[]'::jsonb, rnd_date1, 'RHEL', 8, '8.0', |
| 92 | + jsonb_build_array(jsonb_build_object( |
| 93 | + 'id', workspace_ids[cnt % 3 + 1]::text, |
| 94 | + 'name', workspace_ids[cnt % 3 + 1]::text)), |
| 95 | + workspace_ids[cnt % 3 + 1], workspace_ids[cnt % 3 + 1]::text) |
| 96 | + RETURNING id INTO new_id; |
| 97 | + |
| 98 | + INSERT INTO system_patch |
| 99 | + (rh_account_id, system_id, last_evaluation, |
| 100 | + packages_installed, packages_installable, packages_applicable) |
| 101 | + VALUES |
| 102 | + (acc_id, new_id, rnd_date2, trunc(rnd * 1000), trunc(rnd * 50), trunc(rnd * 50)); |
| 103 | + |
| 104 | + IF mod(cnt, greatest(1, ceil((wanted::numeric * progress) / 100.0)::int)) = 0 THEN |
| 105 | + RAISE NOTICE 'created % systems (inventory + patch)', cnt; |
| 106 | + END IF; |
| 107 | + cnt := cnt + 1; |
| 108 | + END LOOP; |
| 109 | + RAISE NOTICE 'created % systems (inventory + patch)', wanted; |
| 110 | +END; |
| 111 | +$$; |
| 112 | + |
| 113 | +SELECT 'rh_account' AS tbl, count(*) FROM rh_account |
| 114 | +UNION ALL |
| 115 | +SELECT 'system_inventory', count(*) FROM system_inventory |
| 116 | +UNION ALL |
| 117 | +SELECT 'system_patch', count(*) FROM system_patch; |
| 118 | + |
| 119 | +SELECT parent.relname AS parent, |
| 120 | + child.relname AS child, |
| 121 | + pg_size_pretty(pg_relation_size(child.oid)) AS size |
| 122 | +FROM pg_inherits |
| 123 | + JOIN pg_class parent ON pg_inherits.inhparent = parent.oid |
| 124 | + JOIN pg_class child ON pg_inherits.inhrelid = child.oid |
| 125 | +WHERE parent.relname IN ('system_inventory', 'system_patch') |
| 126 | +ORDER BY 1, 2; |
0 commit comments