Skip to content

Commit eb857c1

Browse files
fix: refer to agent_id instead of job_id in timings
1 parent 0b0d1ef commit eb857c1

9 files changed

+16
-26
lines changed

coderd/agentapi/scripts.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,8 @@ type ScriptsAPI struct {
1818
func (s *ScriptsAPI) ScriptCompleted(ctx context.Context, req *agentproto.WorkspaceAgentScriptCompletedRequest) (*agentproto.WorkspaceAgentScriptCompletedResponse, error) {
1919
res := &agentproto.WorkspaceAgentScriptCompletedResponse{}
2020

21-
agent, err := s.Database.GetWorkspaceAgentByID(ctx, s.AgentID)
22-
if err != nil {
23-
return nil, xerrors.Errorf("get workspace agent by id in database: %w", err)
24-
}
25-
26-
resource, err := s.Database.GetWorkspaceResourceByID(ctx, agent.ResourceID)
27-
if err != nil {
28-
return nil, xerrors.Errorf("get workspace resource by id in database: %w", err)
29-
}
30-
31-
_, err = s.Database.InsertWorkspaceAgentScriptTimings(ctx, database.InsertWorkspaceAgentScriptTimingsParams{
32-
JobID: resource.JobID,
21+
_, err := s.Database.InsertWorkspaceAgentScriptTimings(ctx, database.InsertWorkspaceAgentScriptTimingsParams{
22+
AgentID: s.AgentID,
3323
DisplayName: req.Timing.DisplayName,
3424
StartedAt: req.Timing.Start.AsTime(),
3525
EndedAt: req.Timing.End.AsTime(),

coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7838,11 +7838,11 @@ func (q *FakeQuerier) InsertWorkspaceAgentScriptTimings(_ context.Context, arg d
78387838

78397839
//nolint:gosimple // Stop linter suggesting 'arg' should be of type database.WorkspaceAgentScriptTiming
78407840
scriptTiming := database.WorkspaceAgentScriptTiming{
7841+
AgentID: arg.AgentID,
78417842
StartedAt: arg.StartedAt,
78427843
EndedAt: arg.EndedAt,
78437844
ExitCode: arg.ExitCode,
78447845
DisplayName: arg.DisplayName,
7845-
JobID: arg.JobID,
78467846
RanOnStart: arg.RanOnStart,
78477847
BlockedLogin: arg.BlockedLogin,
78487848
}

coderd/database/dump.sql

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/foreign_key_constraint.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000255_workspace_agent_script_timings.up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CREATE TABLE workspace_agent_script_timings
22
(
3-
job_id uuid not null references provisioner_jobs (id) on delete cascade,
3+
agent_id uuid not null references workspace_agents (id) on delete cascade,
44
display_name text not null,
55
started_at timestamp with time zone not null,
66
ended_at timestamp with time zone not null,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
INSERT INTO workspace_agent_script_timings (job_id, display_name, started_at, ended_at, exit_code, ran_on_start, blocked_login)
1+
INSERT INTO workspace_agent_script_timings (agent_id, display_name, started_at, ended_at, exit_code, ran_on_start, blocked_login)
22
VALUES
3-
('424a58cb-61d6-4627-9907-613c396c4a38', 'Startup Script', NOW() - INTERVAL '1 hour 55 minutes', NOW() - INTERVAL '1 hour 50 minutes', 0, true, false);
3+
('45e89705-e09d-4850-bcec-f9a937f5d78d', 'Startup Script', NOW() - INTERVAL '1 hour 55 minutes', NOW() - INTERVAL '1 hour 50 minutes', 0, true, false);

coderd/database/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceagents.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ WHERE
291291
-- name: InsertWorkspaceAgentScriptTimings :one
292292
INSERT INTO
293293
workspace_agent_script_timings (
294-
job_id,
294+
agent_id,
295295
display_name,
296296
started_at,
297297
ended_at,

0 commit comments

Comments
 (0)