- Notifications
You must be signed in to change notification settings - Fork914
fix(coderd): mark sub agent deletion via boolean instead of delete#18411
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
a473f80
todb5700a
Comparedb5700a
to7d73585
Compare// Add a test antagonist. For every agent we add a deleted sub agent | ||
// to discover cases where deletion should be handled. | ||
subAgt,err:=db.InsertWorkspaceAgent(genCtx, database.InsertWorkspaceAgentParams{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Review: This may be a bit unusual, but it already helped me catch an issue with theworkspace_prebuilds
VIEW.
Ideally this potential cause would somehow be propagated to the user in case of test failure, but not sure how that could be done. I'll add a log entry to help with discovery.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I like this a lot! I do agree that it could get confusing to troubleshoot, but the log message in combination withdbtestutil.DumpOnFailure
should help. You could also potentially set some relevant fields of the sub-agent so that its purpose is clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
How about this? 😆bc370a8
(#18411)
docs/admin/security/audit-logs.md Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
🚫[linkspector]reported byreviewdog 🐶
Cannot reachhttps://splunk.com Status: null Navigation timeout of 30000 ms exceeded
categorized using any log management tool such as[Splunk](https://splunk.com). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I spot-checked the migrations and the updated views/triggers look OK to me.
Would like a second pair of eyes on this for approval in case there's something I missed.
// Add a test antagonist. For every agent we add a deleted sub agent | ||
// to discover cases where deletion should be handled. | ||
subAgt,err:=db.InsertWorkspaceAgent(genCtx, database.InsertWorkspaceAgentParams{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I like this a lot! I do agree that it could get confusing to troubleshoot, but the log message in combination withdbtestutil.DumpOnFailure
should help. You could also potentially set some relevant fields of the sub-agent so that its purpose is clear.
UPDATE | ||
workspace_agents | ||
SET | ||
deleted= TRUE | ||
WHERE | ||
id= $1 | ||
AND parent_idIS NOT NULL | ||
AND deleted= FALSE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
👍 literally impossible to delete a 'top-level' agent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
obligatory reminder to check migration number!
Uh oh!
There was an error while loading.Please reload this page.
Since deletion of data is uncommon in our database, the introduction of sub agents and their deletion introduced issues with foreign key assumptions incoder/internal#685. We could have only addressed the specific case by allowing cascade deletion of stats as well as handling in the stats collector, but it's unclear how many more such edge-cases we would've run into.
For this reason, we decided to mark the rows as deleted via boolean instead, and filter them out in all queries that seem relevant so that coderd doesn't see the deleted agents.
Testing is covered by updating the relevant
agentapi
tests as well as adding an antagonist deleted agent todbgen
which automatically gets applied to all tests.Fixescoder/internal#685
Note that there are some queries that read
workspace_agents
that were not updated with deletion handling, but each one was analyzed and deemed unnecessary because of how they are used, doing so may introduce more harm than good. On that note, many of these queries can return results for non-latest builds which essentially means, "deleted" agents.