Skip to content

Commit 44127b8

Browse files
chore: remove 'display_name' from timing table
1 parent 3b4df92 commit 44127b8

13 files changed

+172
-190
lines changed

agent/agentscripts/agentscripts.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,12 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript,
350350

351351
_, err = r.scriptCompleted(ctx, &proto.WorkspaceAgentScriptCompletedRequest{
352352
Timing: &proto.Timing{
353-
ScriptId: script.ID[:],
354-
DisplayName: script.DisplayName,
355-
Start: timestamppb.New(start),
356-
End: timestamppb.New(end),
357-
ExitCode: int32(exitCode),
358-
Stage: stage,
359-
TimedOut: errors.Is(err, ErrTimeout),
353+
ScriptId: script.ID[:],
354+
Start: timestamppb.New(start),
355+
End: timestamppb.New(end),
356+
ExitCode: int32(exitCode),
357+
Stage: stage,
358+
TimedOut: errors.Is(err, ErrTimeout),
360359
},
361360
})
362361
if err != nil {

agent/agentscripts/agentscripts_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ func TestScriptReportsTiming(t *testing.T) {
138138
require.Equal(t, 1, len(timings))
139139

140140
timing := timings[0]
141-
require.Equal(t, "say-hello", timing.DisplayName)
142141
require.Equal(t, int32(0), timing.ExitCode)
143142
require.GreaterOrEqual(t, timing.End.AsTime(), timing.Start.AsTime())
144143
}

agent/proto/agent.pb.go

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

agent/proto/agent.proto

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,17 @@ message WorkspaceAgentScriptCompletedResponse {
275275

276276
message Timing {
277277
bytes script_id = 1;
278-
string display_name = 2;
279-
google.protobuf.Timestamp start = 3;
280-
google.protobuf.Timestamp end = 4;
281-
int32 exit_code = 5;
278+
google.protobuf.Timestamp start = 2;
279+
google.protobuf.Timestamp end = 3;
280+
int32 exit_code = 4;
282281

283282
enum Stage {
284283
START = 0;
285284
STOP = 1;
286285
CRON = 2;
287286
}
288-
Stage stage = 6;
289-
bool timed_out = 7;
287+
Stage stage = 5;
288+
bool timed_out = 6;
290289
}
291290

292291
service Agent {

coderd/agentapi/scripts.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
agentproto "github.com/coder/coder/v2/agent/proto"
1010
"github.com/coder/coder/v2/coderd/database"
11+
"github.com/coder/coder/v2/coderd/database/dbauthz"
1112
)
1213

1314
type ScriptsAPI struct {
@@ -32,14 +33,15 @@ func (s *ScriptsAPI) ScriptCompleted(ctx context.Context, req *agentproto.Worksp
3233
stage = database.WorkspaceAgentScriptTimingStageCron
3334
}
3435

36+
//nolint:gocritic // We need permissions to write to the DB here and we are in the context of the agent.
37+
ctx = dbauthz.AsProvisionerd(ctx)
3538
err = s.Database.InsertWorkspaceAgentScriptTimings(ctx, database.InsertWorkspaceAgentScriptTimingsParams{
36-
ScriptID: scriptID,
37-
Stage: stage,
38-
DisplayName: req.Timing.DisplayName,
39-
StartedAt: req.Timing.Start.AsTime(),
40-
EndedAt: req.Timing.End.AsTime(),
41-
ExitCode: req.Timing.ExitCode,
42-
TimedOut: req.Timing.TimedOut,
39+
ScriptID: scriptID,
40+
Stage: stage,
41+
StartedAt: req.Timing.Start.AsTime(),
42+
EndedAt: req.Timing.End.AsTime(),
43+
ExitCode: req.Timing.ExitCode,
44+
TimedOut: req.Timing.TimedOut,
4345
})
4446
if err != nil {
4547
return nil, xerrors.Errorf("insert workspace agent script timings into database: %w", err)

coderd/agentapi/scripts_test.go

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,56 +26,51 @@ func TestScriptCompleted(t *testing.T) {
2626
{
2727
scriptID: uuid.New(),
2828
timing: &agentproto.Timing{
29-
Stage: agentproto.Timing_START,
30-
DisplayName: "Start Script",
31-
Start: timestamppb.New(dbtime.Now()),
32-
End: timestamppb.New(dbtime.Now().Add(time.Second)),
33-
TimedOut: false,
34-
ExitCode: 0,
29+
Stage: agentproto.Timing_START,
30+
Start: timestamppb.New(dbtime.Now()),
31+
End: timestamppb.New(dbtime.Now().Add(time.Second)),
32+
TimedOut: false,
33+
ExitCode: 0,
3534
},
3635
},
3736
{
3837
scriptID: uuid.New(),
3938
timing: &agentproto.Timing{
40-
Stage: agentproto.Timing_STOP,
41-
DisplayName: "Stop Script",
42-
Start: timestamppb.New(dbtime.Now()),
43-
End: timestamppb.New(dbtime.Now().Add(time.Second)),
44-
TimedOut: false,
45-
ExitCode: 0,
39+
Stage: agentproto.Timing_STOP,
40+
Start: timestamppb.New(dbtime.Now()),
41+
End: timestamppb.New(dbtime.Now().Add(time.Second)),
42+
TimedOut: false,
43+
ExitCode: 0,
4644
},
4745
},
4846
{
4947
scriptID: uuid.New(),
5048
timing: &agentproto.Timing{
51-
Stage: agentproto.Timing_CRON,
52-
DisplayName: "Cron Script",
53-
Start: timestamppb.New(dbtime.Now()),
54-
End: timestamppb.New(dbtime.Now().Add(time.Second)),
55-
TimedOut: false,
56-
ExitCode: 0,
49+
Stage: agentproto.Timing_CRON,
50+
Start: timestamppb.New(dbtime.Now()),
51+
End: timestamppb.New(dbtime.Now().Add(time.Second)),
52+
TimedOut: false,
53+
ExitCode: 0,
5754
},
5855
},
5956
{
6057
scriptID: uuid.New(),
6158
timing: &agentproto.Timing{
62-
Stage: agentproto.Timing_START,
63-
DisplayName: "Timed Out Script",
64-
Start: timestamppb.New(dbtime.Now()),
65-
End: timestamppb.New(dbtime.Now().Add(time.Second)),
66-
TimedOut: true,
67-
ExitCode: 255,
59+
Stage: agentproto.Timing_START,
60+
Start: timestamppb.New(dbtime.Now()),
61+
End: timestamppb.New(dbtime.Now().Add(time.Second)),
62+
TimedOut: true,
63+
ExitCode: 255,
6864
},
6965
},
7066
{
7167
scriptID: uuid.New(),
7268
timing: &agentproto.Timing{
73-
Stage: agentproto.Timing_START,
74-
DisplayName: "Failed Script",
75-
Start: timestamppb.New(dbtime.Now()),
76-
End: timestamppb.New(dbtime.Now().Add(time.Second)),
77-
TimedOut: true,
78-
ExitCode: 1,
69+
Stage: agentproto.Timing_START,
70+
Start: timestamppb.New(dbtime.Now()),
71+
End: timestamppb.New(dbtime.Now().Add(time.Second)),
72+
TimedOut: true,
73+
ExitCode: 1,
7974
},
8075
},
8176
}
@@ -86,13 +81,12 @@ func TestScriptCompleted(t *testing.T) {
8681

8782
mDB := dbmock.NewMockStore(gomock.NewController(t))
8883
mDB.EXPECT().InsertWorkspaceAgentScriptTimings(gomock.Any(), database.InsertWorkspaceAgentScriptTimingsParams{
89-
ScriptID: tt.scriptID,
90-
Stage: protoScriptTimingStageToDatabase(tt.timing.Stage),
91-
DisplayName: tt.timing.DisplayName,
92-
StartedAt: tt.timing.Start.AsTime(),
93-
EndedAt: tt.timing.End.AsTime(),
94-
TimedOut: tt.timing.TimedOut,
95-
ExitCode: tt.timing.ExitCode,
84+
ScriptID: tt.scriptID,
85+
Stage: protoScriptTimingStageToDatabase(tt.timing.Stage),
86+
StartedAt: tt.timing.Start.AsTime(),
87+
EndedAt: tt.timing.End.AsTime(),
88+
TimedOut: tt.timing.TimedOut,
89+
ExitCode: tt.timing.ExitCode,
9690
})
9791

9892
api := &agentapi.ScriptsAPI{Database: mDB}

coderd/database/dbmem/dbmem.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7837,14 +7837,14 @@ func (q *FakeQuerier) InsertWorkspaceAgentScriptTimings(_ context.Context, arg d
78377837
defer q.mutex.Unlock()
78387838

78397839
q.workspaceAgentScriptTimings = append(q.workspaceAgentScriptTimings,
7840+
//nolint:gosimple // Stop the linter complaining about changing the type of `arg`.
78407841
database.WorkspaceAgentScriptTiming{
7841-
ScriptID: arg.ScriptID,
7842-
StartedAt: arg.StartedAt,
7843-
EndedAt: arg.EndedAt,
7844-
ExitCode: arg.ExitCode,
7845-
DisplayName: arg.DisplayName,
7846-
Stage: arg.Stage,
7847-
TimedOut: arg.TimedOut,
7842+
ScriptID: arg.ScriptID,
7843+
StartedAt: arg.StartedAt,
7844+
EndedAt: arg.EndedAt,
7845+
ExitCode: arg.ExitCode,
7846+
Stage: arg.Stage,
7847+
TimedOut: arg.TimedOut,
78487848
},
78497849
)
78507850

coderd/database/dump.sql

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ CREATE TYPE workspace_agent_script_timing_stage AS ENUM (
99
CREATE TABLE workspace_agent_script_timings
1010
(
1111
script_id uuid NOT NULL REFERENCES workspace_agent_scripts (id) ON DELETE CASCADE,
12-
display_name text NOT NULL,
1312
started_at timestamp with time zone NOT NULL,
1413
ended_at timestamp with time zone NOT NULL,
1514
exit_code int NOT NULL,
1615
stage workspace_agent_script_timing_stage NOT NULL,
1716
timed_out bool NOT NULL
1817
);
18+
19+
ALTER TABLE workspace_agent_script_timings ADD UNIQUE (script_id, started_at);

coderd/database/models.go

Lines changed: 6 additions & 7 deletions
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: 7 additions & 10 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,11 @@ WHERE
292292
INSERT INTO
293293
workspace_agent_script_timings (
294294
script_id,
295-
display_name,
296295
started_at,
297296
ended_at,
298297
exit_code,
299298
stage,
300299
timed_out
301300
)
302301
VALUES
303-
($1, $2, $3, $4, $5, $6, $7);
302+
($1, $2, $3, $4, $5, $6);

coderd/database/unique_constraint.go

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

0 commit comments

Comments
 (0)