Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add agent timings#14713

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

Merged
DanielleMaywood merged 57 commits intomainfromdm-add-agent-timings
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
57 commits
Select commitHold shift + click to select a range
bcfacf7
feat: begin impl of agent script timings
DanielleMaywoodSep 17, 2024
d55b2e6
feat: add job_id and display_name to script timings
DanielleMaywoodSep 17, 2024
05d8a8b
fix: increment migration number
DanielleMaywoodSep 17, 2024
d54f6c3
fix: rename migrations from 251 to 254
DanielleMaywoodSep 18, 2024
d573c67
test: get tests compiling
DanielleMaywoodSep 18, 2024
09a1a42
fix: appease the linter
DanielleMaywoodSep 18, 2024
6d829f3
fix: get tests passing again
DanielleMaywoodSep 18, 2024
4df7831
fix: drop column from correct table
DanielleMaywoodSep 18, 2024
2565f0a
test: add fixture for agent script timings
DanielleMaywoodSep 18, 2024
669b837
fix: typo
DanielleMaywoodSep 18, 2024
df51673
fix: use job id used in provisioner job timings
DanielleMaywoodSep 18, 2024
c6d71d1
fix: increment migration number
DanielleMaywoodSep 18, 2024
a306e48
test: behaviour of script runner
DanielleMaywoodSep 18, 2024
4b0056c
test: rewrite test
DanielleMaywoodSep 18, 2024
14b68a1
test: does exit 1 script break things?
DanielleMaywoodSep 18, 2024
b22cb57
test: rewrite test again
DanielleMaywoodSep 18, 2024
ef5e2fe
fix: revert change
DanielleMaywoodSep 19, 2024
a5b412b
fix: let code breathe
DanielleMaywoodSep 19, 2024
57ebf30
fix: wrap errors
DanielleMaywoodSep 19, 2024
2a49f67
fix: justify nolint
DanielleMaywoodSep 19, 2024
0698584
fix: swap require.Equal argument order
DanielleMaywoodSep 19, 2024
3580069
fix: add mutex operations
DanielleMaywoodSep 19, 2024
9cb1252
feat: add 'ran_on_start' and 'blocked_login' fields
DanielleMaywoodSep 19, 2024
0b0d1ef
fix: update testdata fixture
DanielleMaywoodSep 19, 2024
eb857c1
fix: refer to agent_id instead of job_id in timings
DanielleMaywoodSep 19, 2024
586d88f
fix: JobID -> AgentID in dbauthz_test
DanielleMaywoodSep 19, 2024
b6289bb
fix: add 'id' to scripts, make timing refer to script id
DanielleMaywoodSep 19, 2024
863c3dc
fix: fix broken tests and convert bug
DanielleMaywoodSep 19, 2024
b8d5d1d
fix: update testdata fixtures
DanielleMaywoodSep 19, 2024
61c26ea
fix: update testdata fixtures again
DanielleMaywoodSep 19, 2024
7f8b6f9
feat: capture stage and if script timed out
DanielleMaywoodSep 20, 2024
c20ac32
fix: update migration number
DanielleMaywoodSep 20, 2024
c652133
test: add test for script api
DanielleMaywoodSep 20, 2024
1199b64
fix: fake db query
DanielleMaywoodSep 20, 2024
afa61eb
fix: use UTC time
DanielleMaywoodSep 20, 2024
8d325e2
fix: ensure r.scriptComplete is not nil
DanielleMaywoodSep 20, 2024
aeee582
fix: move err check to right after call
DanielleMaywoodSep 20, 2024
424069c
fix: uppercase sql
DanielleMaywoodSep 20, 2024
9b43a94
fix: use dbtime.Now()
DanielleMaywoodSep 20, 2024
ed31199
fix: debug log on r.scriptCompleted being nil
DanielleMaywoodSep 20, 2024
8814711
fix: ensure correct rbac permissions
DanielleMaywoodSep 20, 2024
0414623
chore: remove DisplayName
DanielleMaywoodSep 20, 2024
a8192a5
Merge branch 'main' into dm-add-agent-timings
DanielleMaywoodSep 20, 2024
08a466a
fix: get tests passing
DanielleMaywoodSep 20, 2024
8e7c757
fix: remove space in sql up
DanielleMaywoodSep 20, 2024
621071e
docs: document ExecuteOption
DanielleMaywoodSep 20, 2024
3b4df92
fix: drop 'RETURNING' from sql
DanielleMaywoodSep 20, 2024
44127b8
chore: remove 'display_name' from timing table
DanielleMaywoodSep 20, 2024
5846216
fix: testdata fixture
DanielleMaywoodSep 20, 2024
c43a143
fix: put r.scriptCompleted call in goroutine
DanielleMaywoodSep 23, 2024
13889bf
fix: track goroutine for test + use separate context for reporting
DanielleMaywoodSep 23, 2024
bf32b89
fix: appease linter, handle trackCommandGoroutine error
DanielleMaywoodSep 23, 2024
7fe6d8c
fix: resolve race condition
DanielleMaywoodSep 23, 2024
d7e86c6
feat: replace timed_out column with status column
DanielleMaywoodSep 23, 2024
6e338f2
test: update testdata fixture
DanielleMaywoodSep 23, 2024
79a620b
fix: apply suggestions from review
DanielleMaywoodSep 24, 2024
180307f
revert: linter changes
DanielleMaywoodSep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
test: behaviour of script runner
  • Loading branch information
@DanielleMaywood
DanielleMaywood committedSep 20, 2024
commita306e480ec794eda2286e7321e1482724d8a3060
46 changes: 46 additions & 0 deletionsagent/agentscripts/agentscripts_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,6 +116,52 @@ func TestTimeout(t *testing.T) {
require.ErrorIs(t, runner.Execute(context.Background(), nil), agentscripts.ErrTimeout)
}

func TestScriptReportsTiming(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think we need to expand this a bit to cover the timeout and non-zero exit status use-cases.

mafredri reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah, definitely a good idea.

I had tried a non-zero exit code but it appeared to cause the test to fail so I'll investigate that again to make sure it wasn't me doing something wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Potentially a follow-up PR?

t.Parallel()

tests := []struct {
displayName string
script string
exitCode int32
}{
{
displayName: "exit-0",
script: "exit 0",
exitCode: 0,
},
{
displayName: "exit-1",
script: "exit 1",
exitCode: 1,
},
}

for _, tt := range tests {
ctx := testutil.Context(t, testutil.WaitShort)
fLogger := newFakeScriptLogger()
runner := setup(t, func(uuid2 uuid.UUID) agentscripts.ScriptLogger {
return fLogger
})
defer runner.Close()
aAPI := agenttest.NewFakeAgentAPI(t, slogtest.Make(t, nil), nil, nil)
err := runner.Init([]codersdk.WorkspaceAgentScript{{
DisplayName: tt.displayName,
LogSourceID: uuid.New(),
Script: tt.script,
}}, aAPI.ScriptCompleted)
require.NoError(t, err)
require.NoError(t, runner.Execute(context.Background(), func(script codersdk.WorkspaceAgentScript) bool {
return true
}))
_ = testutil.RequireRecvCtx(ctx, t, fLogger.logs)

require.Equal(t, len(aAPI.GetTiming()), 1)
timing := aAPI.GetTiming()[0]
require.Equal(t, timing.DisplayName, tt.displayName)
require.Equal(t, timing.ExitCode, tt.exitCode)
}
}

// TestCronClose exists because cron.Run() can happen after cron.Close().
// If this happens, there used to be a deadlock.
func TestCronClose(t *testing.T) {
Expand Down
11 changes: 10 additions & 1 deletionagent/agenttest/client.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -170,6 +170,7 @@ type FakeAgentAPI struct {
logsCh chan<- *agentproto.BatchCreateLogsRequest
lifecycleStates []codersdk.WorkspaceAgentLifecycle
metadata map[string]agentsdk.Metadata
timing []*agentproto.Timing

getAnnouncementBannersFunc func() ([]codersdk.BannerConfig, error)
}
Expand All@@ -182,6 +183,10 @@ func (*FakeAgentAPI) GetServiceBanner(context.Context, *agentproto.GetServiceBan
return &agentproto.ServiceBanner{}, nil
}

func (f *FakeAgentAPI) GetTiming() []*agentproto.Timing {
return f.timing
}

func (f *FakeAgentAPI) SetAnnouncementBannersFunc(fn func() ([]codersdk.BannerConfig, error)) {
f.Lock()
defer f.Unlock()
Expand DownExpand Up@@ -301,7 +306,11 @@ func (f *FakeAgentAPI) BatchCreateLogs(ctx context.Context, req *agentproto.Batc
return &agentproto.BatchCreateLogsResponse{}, nil
}

func (*FakeAgentAPI) ScriptCompleted(_ context.Context, _ *agentproto.WorkspaceAgentScriptCompletedRequest) (*agentproto.WorkspaceAgentScriptCompletedResponse, error) {
func (f *FakeAgentAPI) ScriptCompleted(_ context.Context, req *agentproto.WorkspaceAgentScriptCompletedRequest) (*agentproto.WorkspaceAgentScriptCompletedResponse, error) {
f.Lock()
f.timing = append(f.timing, req.Timing)
f.Unlock()

return &agentproto.WorkspaceAgentScriptCompletedResponse{}, nil
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp