-
Notifications
You must be signed in to change notification settings - Fork 48
RHINENG-29747: add workspace_id not null constraint #2329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| ALTER TABLE system_inventory ALTER COLUMN workspace_id DROP NOT NULL; | ||
|
|
||
| CREATE OR REPLACE FUNCTION refresh_account_advisory_caches_multi(advisory_ids_in INTEGER[] DEFAULT NULL, | ||
| rh_account_id_in INTEGER DEFAULT NULL) | ||
| RETURNS VOID AS | ||
| $refresh_account_advisory$ | ||
| BEGIN | ||
| PERFORM aa.rh_account_id, aa.workspace_id, aa.advisory_id | ||
| FROM account_advisory aa | ||
| WHERE (aa.advisory_id = ANY (advisory_ids_in) OR advisory_ids_in IS NULL) | ||
| AND (aa.rh_account_id = rh_account_id_in OR rh_account_id_in IS NULL) | ||
| FOR UPDATE OF aa; | ||
|
|
||
| WITH current_counts AS ( | ||
| SELECT sa.advisory_id, sa.rh_account_id, si.workspace_id, | ||
| count(sa.*) FILTER (WHERE sa.status_id = 0) AS systems_installable, | ||
| count(sa.*) AS systems_applicable | ||
| FROM system_advisories sa | ||
| JOIN system_inventory si | ||
| ON sa.rh_account_id = si.rh_account_id AND sa.system_id = si.id | ||
| JOIN system_patch sp | ||
| ON si.id = sp.system_id AND sp.rh_account_id = si.rh_account_id | ||
| WHERE sp.last_evaluation IS NOT NULL | ||
| AND si.stale = FALSE | ||
| AND si.workspace_id IS NOT NULL | ||
| AND (sa.advisory_id = ANY (advisory_ids_in) OR advisory_ids_in IS NULL) | ||
| AND (si.rh_account_id = rh_account_id_in OR rh_account_id_in IS NULL) | ||
| GROUP BY sa.advisory_id, sa.rh_account_id, si.workspace_id | ||
| ), | ||
| upserted AS ( | ||
| INSERT INTO account_advisory (advisory_id, rh_account_id, workspace_id, systems_installable, systems_applicable) | ||
| SELECT advisory_id, rh_account_id, workspace_id, systems_installable, systems_applicable | ||
| FROM current_counts | ||
| ON CONFLICT (rh_account_id, workspace_id, advisory_id) DO UPDATE SET | ||
| systems_installable = EXCLUDED.systems_installable, | ||
| systems_applicable = EXCLUDED.systems_applicable | ||
| ) | ||
| DELETE FROM account_advisory | ||
| WHERE (advisory_id, rh_account_id, workspace_id) NOT IN (SELECT advisory_id, rh_account_id, workspace_id FROM current_counts) | ||
| AND (advisory_id = ANY (advisory_ids_in) OR advisory_ids_in IS NULL) | ||
| AND (rh_account_id = rh_account_id_in OR rh_account_id_in IS NULL); | ||
| END; | ||
| $refresh_account_advisory$ LANGUAGE plpgsql; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| ALTER TABLE system_inventory ALTER COLUMN workspace_id SET NOT NULL; | ||
|
|
||
| CREATE OR REPLACE FUNCTION refresh_account_advisory_caches_multi(advisory_ids_in INTEGER[] DEFAULT NULL, | ||
| rh_account_id_in INTEGER DEFAULT NULL) | ||
| RETURNS VOID AS | ||
| $refresh_account_advisory$ | ||
| BEGIN | ||
| PERFORM aa.rh_account_id, aa.workspace_id, aa.advisory_id | ||
| FROM account_advisory aa | ||
| WHERE (aa.advisory_id = ANY (advisory_ids_in) OR advisory_ids_in IS NULL) | ||
| AND (aa.rh_account_id = rh_account_id_in OR rh_account_id_in IS NULL) | ||
| FOR UPDATE OF aa; | ||
|
|
||
| WITH current_counts AS ( | ||
| SELECT sa.advisory_id, sa.rh_account_id, si.workspace_id, | ||
| count(sa.*) FILTER (WHERE sa.status_id = 0) AS systems_installable, | ||
| count(sa.*) AS systems_applicable | ||
| FROM system_advisories sa | ||
| JOIN system_inventory si | ||
| ON sa.rh_account_id = si.rh_account_id AND sa.system_id = si.id | ||
| JOIN system_patch sp | ||
| ON si.id = sp.system_id AND sp.rh_account_id = si.rh_account_id | ||
| WHERE sp.last_evaluation IS NOT NULL | ||
| AND si.stale = FALSE | ||
| AND (sa.advisory_id = ANY (advisory_ids_in) OR advisory_ids_in IS NULL) | ||
| AND (si.rh_account_id = rh_account_id_in OR rh_account_id_in IS NULL) | ||
| GROUP BY sa.advisory_id, sa.rh_account_id, si.workspace_id | ||
| ), | ||
| upserted AS ( | ||
| INSERT INTO account_advisory (advisory_id, rh_account_id, workspace_id, systems_installable, systems_applicable) | ||
| SELECT advisory_id, rh_account_id, workspace_id, systems_installable, systems_applicable | ||
| FROM current_counts | ||
| ON CONFLICT (rh_account_id, workspace_id, advisory_id) DO UPDATE SET | ||
| systems_installable = EXCLUDED.systems_installable, | ||
| systems_applicable = EXCLUDED.systems_applicable | ||
| ) | ||
| DELETE FROM account_advisory | ||
| WHERE (advisory_id, rh_account_id, workspace_id) NOT IN (SELECT advisory_id, rh_account_id, workspace_id FROM current_counts) | ||
| AND (advisory_id = ANY (advisory_ids_in) OR advisory_ids_in IS NULL) | ||
| AND (rh_account_id = rh_account_id_in OR rh_account_id_in IS NULL); | ||
| END; | ||
| $refresh_account_advisory$ LANGUAGE plpgsql; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -364,25 +364,26 @@ func updateSystemPlatform(tx *gorm.DB, accountID int, host *Host, | |
| isBootc := len(host.SystemProfile.BootcStatus.Booted.Image) > 0 | ||
|
|
||
| updatesReqJSONString := string(updatesReqJSON) | ||
| var workspaceID *uuid.UUID | ||
| var workspaceName *string | ||
| if l := len(host.Groups); l > 0 { | ||
| workspace := host.Groups[0] | ||
| uuid, err := uuid.Parse(workspace.ID) | ||
| if err != nil { | ||
| utils.LogError("workspaceID", workspace.ID, "invalid workspace UUID") | ||
| return nil, errors.New("received invalid workspace UUID") | ||
| } | ||
| workspaceID = &uuid | ||
| if workspace.Name != "" { | ||
| workspaceName = &workspace.Name | ||
| } | ||
| if l != 1 { | ||
| utils.LogWarn( | ||
| "host_id", host.ID, "org_id", host.OrgID, "workspaces", host.Groups, | ||
| "received a host with multiple workspaces", | ||
| ) | ||
| } | ||
| l := len(host.Groups) | ||
| if l == 0 { | ||
| utils.LogError("inventoryID", inventoryID, "workspace UUID missing for system") | ||
| return nil, errors.New("workspace UUID missing for system") | ||
| } | ||
|
Comment on lines
+369
to
+372
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Uploads for hosts with no workspace group now return an error instead of storing the inventory. The existing code accepted such hosts and persisted a NULL workspace ID, so any still-valid host event without Triggers: When an inventory upload contains an empty Suggested fix: Ensure the event pipeline supplies a valid workspace before this function, or define and use a non-NULL fallback workspace value instead of rejecting the upload. |
||
| workspace := host.Groups[0] | ||
| workspaceID, err := uuid.Parse(workspace.ID) | ||
| if err != nil { | ||
| utils.LogError("workspaceID", workspace.ID, "invalid workspace UUID") | ||
| return nil, errors.New("received invalid workspace UUID") | ||
| } | ||
| if workspace.Name != "" { | ||
| workspaceName = &workspace.Name | ||
| } | ||
| if l != 1 { | ||
| utils.LogWarn( | ||
| "host_id", host.ID, "org_id", host.OrgID, "workspaces", host.Groups, | ||
| "received a host with multiple workspaces", | ||
| ) | ||
| } | ||
| systemPlatform := &models.SystemPlatformV2{ | ||
| Inventory: models.SystemInventory{ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.