Handle creation/deletion of workspace tokens and create token docs
Issue: Handle creation/deletion of workspace tokens an... (#547320 - closed) • Chad Woolley • 18.2
What does this MR do and why?
Implements Handle creation/deletion of workspace tokens an... (#547320 - closed) • Chad Woolley • 18.2
See Acceptance Criteria and Implementation Plan in that associated issue.
References
- Previous MR introducing
WorkspaceToken
model and table: Add WorkspaceTokens model and table (!193071 - merged) • Chad Woolley • 18.1 - Issue: Handle creation/deletion of workspace tokens an... (#547320 - closed) • Chad Woolley • 18.2
- Epic: Simplify Workspaces setup by removing GitLab Wo... (&16785) • Chad Woolley, Vishal Tak
Database explain plans
WorkspaceToken creation
Rails log for queries during creation:
[8] pry(main)> workspace.update!(desired_state: "Running")
TRANSACTION (0.4ms) BEGIN
RemoteDevelopment::WorkspacesAgentConfigVersion Count (1.5ms) SELECT COUNT(*) FROM "workspaces_agent_config_versions" WHERE "workspaces_agent_config_versions"."item_id" = 1 AND "workspaces_agent_config_versions"."item_type" = 'RemoteDevelopment::WorkspacesAgentConfig' /*application:console,correlation_id:a81c92e3ee183be80a9c41b0c84b6105,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:cwoolley--20211214-NGQ7R,console_username:cwoolley,line:/ee/app/models/remote_development/workspace.rb:259:in `validate_workspaces_agent_config_version_is_within_range'*/
RemoteDevelopment::Workspace Update (0.4ms) UPDATE "workspaces" SET "updated_at" = '2025-06-15 01:51:40.971347', "desired_state_updated_at" = '2025-06-15 01:51:40.970773', "desired_state" = 'Running' WHERE "workspaces"."id" = 357 /*application:console,correlation_id:a81c92e3ee183be80a9c41b0c84b6105,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:cwoolley--20211214-NGQ7R,console_username:cwoolley,line:(pry):7:in `__pry__'*/
RemoteDevelopment::WorkspaceToken Load (0.5ms) SELECT "workspace_tokens".* FROM "workspace_tokens" WHERE "workspace_tokens"."token_encrypted" IN ('|ne6X9QROfsfxF1Hs9YhHN0tK/ZvN42nI3xEZ1GpHCdJvH5jYcTBqLdvJSCq+BOphqmOd011vrHprzoYyaLvhWa7XRq0d/Bdga253b7a27b62', '7s7f3HOy0BV4xl/0ZnADCmmcMXZ7kHKRhHPLBQLpPqB98etlbNNNa7ZlRYFYdzRTbt91phGl1y170d98+h3tiXXgan1b3r28') LIMIT 1 /*application:console,correlation_id:a81c92e3ee183be80a9c41b0c84b6105,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:cwoolley--20211214-NGQ7R,console_username:cwoolley,line:/lib/authn/token_field/encrypted.rb:104:in `find_by_encrypted_token'*/
RemoteDevelopment::WorkspaceToken Exists? (0.6ms) SELECT 1 AS one FROM "workspace_tokens" WHERE "workspace_tokens"."workspace_id" = 357 LIMIT 1 /*application:console,correlation_id:a81c92e3ee183be80a9c41b0c84b6105,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:cwoolley--20211214-NGQ7R,console_username:cwoolley,line:/ee/app/models/remote_development/workspace.rb:355:in `do_create_workspace_token'*/
RemoteDevelopment::WorkspaceToken Create (5.7ms) INSERT INTO "workspace_tokens" ("workspace_id", "created_at", "updated_at", "project_id", "token_encrypted") VALUES (357, '2025-06-15 01:51:41.050493', '2025-06-15 01:51:41.050493', 2, '|ne6X9QROfsfxF1Hs9YhHN0tK/ZvN42nI3xEZ1GpHCdJvH5jYcTBqLdvJSCq+BOphqmOd011vrHprzoYyaLvhWa7XRq0d/Bdga253b7a27b62') RETURNING "id" /*application:console,correlation_id:a81c92e3ee183be80a9c41b0c84b6105,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:cwoolley--20211214-NGQ7R,console_username:cwoolley,line:/ee/app/models/remote_development/workspace.rb:355:in `do_create_workspace_token'*/
TRANSACTION (0.6ms) ROLLBACK
Query explain plan:
TODO: ...
WorkspaceToken deletion
Rails log for queries during deletion:
[7] pry(main)> workspace.update!(desired_state: "Stopped")
TRANSACTION (0.3ms) BEGIN
RemoteDevelopment::WorkspacesAgentConfigVersion Count (5.7ms) SELECT COUNT(*) FROM "workspaces_agent_config_versions" WHERE "workspaces_agent_config_versions"."item_id" = 1 AND "workspaces_agent_config_versions"."item_type" = 'RemoteDevelopment::WorkspacesAgentConfig' /*application:console,correlation_id:a81c92e3ee183be80a9c41b0c84b6105,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:cwoolley--20211214-NGQ7R,console_username:cwoolley,line:/ee/app/models/remote_development/workspace.rb:259:in `validate_workspaces_agent_config_version_is_within_range'*/
RemoteDevelopment::WorkspaceToken Destroy (8.3ms) DELETE FROM "workspace_tokens" WHERE "workspace_tokens"."id" = 1 /*application:console,correlation_id:a81c92e3ee183be80a9c41b0c84b6105,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:cwoolley--20211214-NGQ7R,console_username:cwoolley,line:/ee/app/models/remote_development/workspace.rb:364:in `delete_workspace_token'*/
RemoteDevelopment::Workspace Update (1.9ms) UPDATE "workspaces" SET "updated_at" = '2025-06-15 01:50:13.673812', "desired_state_updated_at" = '2025-06-15 01:50:13.575412', "desired_state" = 'Stopped' WHERE "workspaces"."id" = 357 /*application:console,correlation_id:a81c92e3ee183be80a9c41b0c84b6105,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:cwoolley--20211214-NGQ7R,console_username:cwoolley,line:(pry):6:in `__pry__'*/
TRANSACTION (0.2ms) COMMIT
Query explain plan:
TODO: ...
Screenshots or screen recordings
N/A, no UI changes.
How to set up and validate locally
- Ensure that behavior meets Acceptance Criteria in the associated issue.
Manual steps to exercise creation/deletion:
- Create a workspace in dev env
rails console
workspace = RemoteDevelopment::Workspace.last
workspace.update!(desired_state: "Stopped")
workspace.update!(desired_state: "Running")
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Chad Woolley