Skip to content

Commit ec6def8

Browse files
committed
Rename state -> lifecycle state
1 parent 74bf3fd commit ec6def8

23 files changed

+265
-284
lines changed

agent/agent.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type Client interface {
7171
WorkspaceAgentMetadata(ctx context.Context) (codersdk.WorkspaceAgentMetadata, error)
7272
ListenWorkspaceAgent(ctx context.Context) (net.Conn, error)
7373
AgentReportStats(ctx context.Context, log slog.Logger, stats func() *codersdk.AgentStats) (io.Closer, error)
74-
PostWorkspaceAgentState(ctx context.Context, state codersdk.PostWorkspaceAgentStateRequest) error
74+
PostWorkspaceAgentLifecycle(ctx context.Context, state codersdk.PostWorkspaceAgentLifecycleRequest) error
7575
PostWorkspaceAgentAppHealth(ctx context.Context, req codersdk.PostWorkspaceAppHealthsRequest) error
7676
PostWorkspaceAgentVersion(ctx context.Context, version string) error
7777
}
@@ -128,8 +128,8 @@ type agent struct {
128128
sessionToken atomic.Pointer[string]
129129
sshServer *ssh.Server
130130

131-
stateMu sync.Mutex // Protects following.
132-
state codersdk.WorkspaceAgentState
131+
lifecycleMu sync.Mutex // Protects following.
132+
lifecycleState codersdk.WorkspaceAgentLifecycle
133133

134134
network *tailnet.Conn
135135
}
@@ -160,15 +160,15 @@ func (a *agent) runLoop(ctx context.Context) {
160160
}
161161
}
162162

163-
func (a *agent) setState(ctx context.Context, state codersdk.WorkspaceAgentState) {
164-
a.stateMu.Lock()
165-
defer a.stateMu.Unlock()
163+
func (a *agent) setLifecycle(ctx context.Context, state codersdk.WorkspaceAgentLifecycle) {
164+
a.lifecycleMu.Lock()
165+
defer a.lifecycleMu.Unlock()
166166

167-
a.state = state
167+
a.lifecycleState = state
168168

169169
var err error
170170
for r := retry.New(time.Second, 30*time.Second); r.Wait(ctx); {
171-
err = a.client.PostWorkspaceAgentState(ctx, codersdk.PostWorkspaceAgentStateRequest{
171+
err = a.client.PostWorkspaceAgentLifecycle(ctx, codersdk.PostWorkspaceAgentLifecycleRequest{
172172
State: state,
173173
})
174174
if err == nil {
@@ -224,14 +224,14 @@ func (a *agent) run(ctx context.Context) error {
224224
timeout = t.C
225225
}
226226

227-
a.setState(ctx, codersdk.WorkspaceAgentStateStarting)
227+
a.setLifecycle(ctx, codersdk.WorkspaceAgentLifecycleStarting)
228228

229229
var err error
230230
select {
231231
case err = <-scriptDone:
232232
case <-timeout:
233233
a.logger.Warn(ctx, "startup script timed out")
234-
a.setState(ctx, codersdk.WorkspaceAgentStateStartTimeout)
234+
a.setLifecycle(ctx, codersdk.WorkspaceAgentLifecycleStartTimeout)
235235
err = <-scriptDone // The script can still complete after a timeout.
236236
}
237237
if errors.Is(err, context.Canceled) {
@@ -240,7 +240,7 @@ func (a *agent) run(ctx context.Context) error {
240240
execTime := time.Since(scriptStart)
241241
if err != nil {
242242
a.logger.Warn(ctx, "startup script failed", slog.F("execution_time", execTime), slog.Error(err))
243-
a.setState(ctx, codersdk.WorkspaceAgentStateStartError)
243+
a.setLifecycle(ctx, codersdk.WorkspaceAgentLifecycleStartError)
244244
return
245245
}
246246
a.logger.Info(ctx, "startup script completed", slog.F("execution_time", execTime))
@@ -255,7 +255,7 @@ func (a *agent) run(ctx context.Context) error {
255255
}
256256
}
257257

258-
a.setState(ctx, codersdk.WorkspaceAgentStateReady)
258+
a.setLifecycle(ctx, codersdk.WorkspaceAgentLifecycleReady)
259259
}()
260260
}
261261

agent/agent_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ func (c *client) AgentReportStats(ctx context.Context, _ slog.Logger, stats func
11301130
}), nil
11311131
}
11321132

1133-
func (*client) PostWorkspaceAgentState(_ context.Context, _ codersdk.PostWorkspaceAgentStateRequest) error {
1133+
func (*client) PostWorkspaceAgentLifecycle(_ context.Context, _ codersdk.PostWorkspaceAgentLifecycleRequest) error {
11341134
return nil
11351135
}
11361136

coderd/apidoc/docs.go

Lines changed: 28 additions & 46 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: 22 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ func New(options *Options) *API {
534534
r.Get("/gitsshkey", api.agentGitSSHKey)
535535
r.Get("/coordinate", api.workspaceAgentCoordinate)
536536
r.Post("/report-stats", api.workspaceAgentReportStats)
537-
r.Post("/report-state", api.workspaceAgentReportState)
537+
r.Post("/report-lifecycle", api.workspaceAgentReportLifecycle)
538538
})
539539
r.Route("/{workspaceagent}", func(r chi.Router) {
540540
r.Use(

coderd/coderdtest/authorize.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
7272
"POST:/api/v2/workspaceagents/me/version": {NoAuthorize: true},
7373
"POST:/api/v2/workspaceagents/me/app-health": {NoAuthorize: true},
7474
"POST:/api/v2/workspaceagents/me/report-stats": {NoAuthorize: true},
75-
"POST:/api/v2/workspaceagents/me/report-state": {NoAuthorize: true},
75+
"POST:/api/v2/workspaceagents/me/report-lifecycle": {NoAuthorize: true},
7676

7777
// These endpoints have more assertions. This is good, add more endpoints to assert if you can!
7878
"GET:/api/v2/organizations/{organization}": {AssertObject: rbac.ResourceOrganization.InOrg(a.Admin.OrganizationID)},
@@ -265,9 +265,11 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
265265
// Routes like proxy routes support all HTTP methods. A helper func to expand
266266
// 1 url to all http methods.
267267
assertAllHTTPMethods := func(url string, check RouteCheck) {
268-
methods := []string{http.MethodGet, http.MethodHead, http.MethodPost,
268+
methods := []string{
269+
http.MethodGet, http.MethodHead, http.MethodPost,
269270
http.MethodPut, http.MethodPatch, http.MethodDelete,
270-
http.MethodConnect, http.MethodOptions, http.MethodTrace}
271+
http.MethodConnect, http.MethodOptions, http.MethodTrace,
272+
}
271273

272274
for _, method := range methods {
273275
route := method + ":" + url

coderd/database/databasefake/databasefake.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3871,12 +3871,12 @@ func (q *fakeQuerier) GetQuotaConsumedForUser(_ context.Context, userID uuid.UUI
38713871
return sum, nil
38723872
}
38733873

3874-
func (q *fakeQuerier) UpdateWorkspaceAgentStateByID(_ context.Context, arg database.UpdateWorkspaceAgentStateByIDParams) error {
3874+
func (q *fakeQuerier) UpdateWorkspaceAgentLifecycleStateByID(_ context.Context, arg database.UpdateWorkspaceAgentLifecycleStateByIDParams) error {
38753875
q.mutex.Lock()
38763876
defer q.mutex.Unlock()
38773877
for i, agent := range q.workspaceAgents {
38783878
if agent.ID == arg.ID {
3879-
agent.State = arg.State
3879+
agent.LifecycleState = arg.LifecycleState
38803880
q.workspaceAgents[i] = agent
38813881
return nil
38823882
}

0 commit comments

Comments
 (0)