Skip to content

Commit b6289bb

Browse files
fix: add 'id' to scripts, make timing refer to script id
1 parent 586d88f commit b6289bb

29 files changed

+192
-98
lines changed

agent/agentscripts/agentscripts.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript)
323323

324324
_, err = r.scriptCompleted(ctx, &proto.WorkspaceAgentScriptCompletedRequest{
325325
Timing: &proto.Timing{
326+
ScriptId: script.ID[:],
326327
DisplayName: script.DisplayName,
327328
Start: timestamppb.New(start),
328329
End: timestamppb.New(end),
@@ -331,6 +332,10 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript)
331332
BlockedLogin: script.StartBlocksLogin,
332333
},
333334
})
335+
336+
if err != nil {
337+
logger.Error(ctx, fmt.Sprintf("reporting script completed: %s", err.Error()))
338+
}
334339
}()
335340

336341
err = cmd.Start()

agent/proto/agent.pb.go

Lines changed: 94 additions & 75 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ message WorkspaceAgentScript {
5454
bool start_blocks_login = 7;
5555
google.protobuf.Duration timeout = 8;
5656
string display_name = 9;
57+
bytes id = 10;
5758
}
5859

5960
message WorkspaceAgentMetadata {
@@ -279,6 +280,7 @@ message Timing {
279280
int32 exit_code = 4;
280281
bool ran_on_start = 5;
281282
bool blocked_login = 6;
283+
bytes script_id = 7;
282284
}
283285

284286
service Agent {

coderd/agentapi/manifest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func dbAgentScriptsToProto(scripts []database.WorkspaceAgentScript) []*agentprot
178178

179179
func dbAgentScriptToProto(script database.WorkspaceAgentScript) *agentproto.WorkspaceAgentScript {
180180
return &agentproto.WorkspaceAgentScript{
181+
Id: script.ID[:],
181182
DisplayName: script.DisplayName,
182183
LogSourceId: script.LogSourceID[:],
183184
LogPath: script.LogPath,

coderd/agentapi/scripts.go

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

21-
_, err := s.Database.InsertWorkspaceAgentScriptTimings(ctx, database.InsertWorkspaceAgentScriptTimingsParams{
22-
AgentID: s.AgentID,
21+
scriptID, err := uuid.FromBytes(req.Timing.ScriptId)
22+
if err != nil {
23+
return nil, xerrors.Errorf("script id from bytes: %w", err)
24+
}
25+
26+
_, err = s.Database.InsertWorkspaceAgentScriptTimings(ctx, database.InsertWorkspaceAgentScriptTimingsParams{
27+
ScriptID: scriptID,
2328
DisplayName: req.Timing.DisplayName,
2429
StartedAt: req.Timing.Start.AsTime(),
2530
EndedAt: req.Timing.End.AsTime(),

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,7 @@ func (s *MethodTestSuite) TestSystemFunctions() {
26342634
}))
26352635
s.Run("InsertWorkspaceAgentScriptTimings", s.Subtest(func(db database.Store, check *expects) {
26362636
check.Args(database.InsertWorkspaceAgentScriptTimingsParams{
2637-
AgentID: uuid.New(),
2637+
ScriptID: uuid.New(),
26382638
}).Asserts( /* rbac.ResourceSystem, policy.ActionCreate */ )
26392639
}))
26402640
s.Run("InsertWorkspaceAgentScripts", s.Subtest(func(db database.Store, check *expects) {

coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7838,7 +7838,7 @@ 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,
7841+
ScriptID: arg.ScriptID,
78427842
StartedAt: arg.StartedAt,
78437843
EndedAt: arg.EndedAt,
78447844
ExitCode: arg.ExitCode,

coderd/database/dump.sql

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

0 commit comments

Comments
 (0)