Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6163df5

Browse files
committed
Merge branch 'main' into dean/template-activity-bump-dur
2 parents 85880ac + 390217b commit 6163df5

File tree

60 files changed

+1016
-602
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1016
-602
lines changed

agent/apphealth.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ type WorkspaceAppHealthReporter func(ctx context.Context)
2626

2727
// NewWorkspaceAppHealthReporter creates a WorkspaceAppHealthReporter that reports app health to coderd.
2828
func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.WorkspaceApp, postWorkspaceAgentAppHealth PostWorkspaceAgentAppHealth) WorkspaceAppHealthReporter {
29+
logger = logger.Named("apphealth")
30+
2931
runHealthcheckLoop := func(ctx context.Context) error {
32+
ctx, cancel := context.WithCancel(ctx)
33+
defer cancel()
34+
3035
// no need to run this loop if no apps for this workspace.
3136
if len(apps) == 0 {
3237
return nil
@@ -87,6 +92,7 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
8792
return nil
8893
}()
8994
if err != nil {
95+
nowUnhealthy := false
9096
mu.Lock()
9197
if failures[app.ID] < int(app.Healthcheck.Threshold) {
9298
// increment the failure count and keep status the same.
@@ -96,14 +102,21 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
96102
// set to unhealthy if we hit the failure threshold.
97103
// we stop incrementing at the threshold to prevent the failure value from increasing forever.
98104
health[app.ID] = codersdk.WorkspaceAppHealthUnhealthy
105+
nowUnhealthy = true
99106
}
100107
mu.Unlock()
108+
logger.Debug(ctx, "error checking app health",
109+
slog.F("id", app.ID.String()),
110+
slog.F("slug", app.Slug),
111+
slog.F("now_unhealthy", nowUnhealthy), slog.Error(err),
112+
)
101113
} else {
102114
mu.Lock()
103115
// we only need one successful health check to be considered healthy.
104116
health[app.ID] = codersdk.WorkspaceAppHealthHealthy
105117
failures[app.ID] = 0
106118
mu.Unlock()
119+
logger.Debug(ctx, "workspace app healthy", slog.F("id", app.ID.String()), slog.F("slug", app.Slug))
107120
}
108121

109122
t.Reset(time.Duration(app.Healthcheck.Interval) * time.Second)
@@ -137,7 +150,9 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
137150
Healths: lastHealth,
138151
})
139152
if err != nil {
140-
logger.Error(ctx, "failed to report workspace app stat", slog.Error(err))
153+
logger.Error(ctx, "failed to report workspace app health", slog.Error(err))
154+
} else {
155+
logger.Debug(ctx, "sent workspace app health", slog.F("health", lastHealth))
141156
}
142157
}
143158
}

agent/proto/agent.pb.go

Lines changed: 70 additions & 58 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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ message BatchCreateLogsRequest {
247247
repeated Log logs = 2;
248248
}
249249

250-
message BatchCreateLogsResponse {}
250+
message BatchCreateLogsResponse {
251+
bool log_limit_exceeded = 1;
252+
}
251253

252254
service Agent {
253255
rpc GetManifest(GetManifestRequest) returns (Manifest);

cli/server.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,13 @@ func redirectToAccessURL(handler http.Handler, accessURL *url.URL, tunnel bool,
19911991
http.Redirect(w, r, accessURL.String(), http.StatusTemporaryRedirect)
19921992
}
19931993

1994+
// Exception: /healthz
1995+
// Kubernetes doesn't like it if you redirect your healthcheck or liveness check endpoint.
1996+
if r.URL.Path == "/healthz" {
1997+
handler.ServeHTTP(w, r)
1998+
return
1999+
}
2000+
19942001
// Exception: DERP
19952002
// We use this endpoint when creating a DERP-mesh in the enterprise version to directly
19962003
// dial other Coderd derpers. Redirecting to the access URL breaks direct dial since the

cli/server_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,17 @@ func TestServer(t *testing.T) {
685685
require.Equal(t, c.expectRedirect, resp.Header.Get("Location"))
686686
}
687687

688+
// We should never readirect /healthz
689+
respHealthz, err := client.Request(ctx, http.MethodGet, "/healthz", nil)
690+
require.NoError(t, err)
691+
defer respHealthz.Body.Close()
692+
require.Equal(t, http.StatusOK, respHealthz.StatusCode, "/healthz should never redirect")
693+
688694
// We should never redirect DERP
689695
respDERP, err := client.Request(ctx, http.MethodGet, "/derp", nil)
690696
require.NoError(t, err)
691697
defer respDERP.Body.Close()
692-
require.Equal(t, http.StatusUpgradeRequired, respDERP.StatusCode)
698+
require.Equal(t, http.StatusUpgradeRequired, respDERP.StatusCode, "/derp should never redirect")
693699
}
694700

695701
// Verify TLS

cli/testdata/coder_templates_init_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ USAGE:
66
Get started with a templated template.
77

88
OPTIONS:
9-
--id aws-devcontainer|aws-linux|aws-windows|azure-linux|do-linux|docker|gcp-devcontainer|gcp-linux|gcp-vm-container|gcp-windows|kubernetes|nomad-docker
9+
--id aws-devcontainer|aws-linux|aws-windows|azure-linux|do-linux|docker|gcp-devcontainer|gcp-linux|gcp-vm-container|gcp-windows|kubernetes|nomad-docker|scratch
1010
Specify a given example template by ID.
1111

1212
———

coderd/agentapi/apps.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ func (a *AppsAPI) BatchUpdateAppHealths(ctx context.Context, req *agentproto.Bat
2424
return nil, err
2525
}
2626

27+
a.Log.Debug(ctx, "got batch app health update",
28+
slog.F("agent_id", workspaceAgent.ID.String()),
29+
slog.F("updates", req.Updates),
30+
)
31+
2732
if len(req.Updates) == 0 {
2833
return &agentproto.BatchUpdateAppHealthResponse{}, nil
2934
}

coderd/agentapi/logs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (a *LogsAPI) BatchCreateLogs(ctx context.Context, req *agentproto.BatchCrea
3737
return nil, err
3838
}
3939
if workspaceAgent.LogsOverflowed {
40-
return nil, xerrors.New("workspace agent logs overflowed")
40+
return &agentproto.BatchCreateLogsResponse{LogLimitExceeded: true}, nil
4141
}
4242

4343
if len(req.Logs) == 0 {
@@ -128,7 +128,7 @@ func (a *LogsAPI) BatchCreateLogs(ctx context.Context, req *agentproto.BatchCrea
128128
return nil, xerrors.Errorf("publish workspace update: %w", err)
129129
}
130130
}
131-
return nil, xerrors.New("workspace agent log limit exceeded")
131+
return &agentproto.BatchCreateLogsResponse{LogLimitExceeded: true}, nil
132132
}
133133

134134
// Publish by the lowest log ID inserted so the log stream will fetch

coderd/agentapi/logs_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ func TestBatchCreateLogs(t *testing.T) {
215215
LogSourceId: logSource.ID[:],
216216
Logs: []*agentproto.Log{},
217217
})
218-
require.Error(t, err)
219-
require.ErrorContains(t, err, "workspace agent logs overflowed")
220-
require.Nil(t, resp)
218+
require.NoError(t, err)
219+
require.NotNil(t, resp)
220+
require.True(t, resp.LogLimitExceeded)
221221
require.False(t, publishWorkspaceUpdateCalled)
222222
require.False(t, publishWorkspaceAgentLogsUpdateCalled)
223223
})
@@ -419,8 +419,9 @@ func TestBatchCreateLogs(t *testing.T) {
419419
},
420420
},
421421
})
422-
require.Error(t, err)
423-
require.Nil(t, resp)
422+
require.NoError(t, err)
423+
require.NotNil(t, resp)
424+
require.True(t, resp.LogLimitExceeded)
424425
require.True(t, publishWorkspaceUpdateCalled)
425426
require.False(t, publishWorkspaceAgentLogsUpdateCalled)
426427
})

coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5692,6 +5692,7 @@ func (q *FakeQuerier) InsertWorkspaceAgentMetadata(_ context.Context, arg databa
56925692
Key: arg.Key,
56935693
Timeout: arg.Timeout,
56945694
Interval: arg.Interval,
5695+
DisplayOrder: arg.DisplayOrder,
56955696
}
56965697

56975698
q.workspaceAgentMetadata = append(q.workspaceAgentMetadata, metadatum)

0 commit comments

Comments
 (0)