Skip to content

Commit fa52350

Browse files
committed
Merge branch 'main' into clarify-stop-warning
2 parents b2ce1dd + 390217b commit fa52350

File tree

61 files changed

+1236
-600
lines changed

Some content is hidden

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

61 files changed

+1236
-600
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/ssh.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ func (r *RootCmd) ssh() *clibase.Cmd {
8787
}
8888
}()
8989

90+
// In stdio mode, we can't allow any writes to stdin or stdout
91+
// because they are used by the SSH protocol.
92+
stdioReader, stdioWriter := inv.Stdin, inv.Stdout
93+
if stdio {
94+
inv.Stdin = stdioErrLogReader{inv.Logger}
95+
inv.Stdout = inv.Stderr
96+
}
97+
9098
// This WaitGroup solves for a race condition where we were logging
9199
// while closing the log file in a defer. It probably solves
92100
// others too.
@@ -234,7 +242,7 @@ func (r *RootCmd) ssh() *clibase.Cmd {
234242
if err != nil {
235243
return xerrors.Errorf("connect SSH: %w", err)
236244
}
237-
copier := newRawSSHCopier(logger, rawSSH, inv.Stdin, inv.Stdout)
245+
copier := newRawSSHCopier(logger, rawSSH, stdioReader, stdioWriter)
238246
if err = stack.push("rawSSHCopier", copier); err != nil {
239247
return err
240248
}
@@ -987,3 +995,12 @@ func sshDisableAutostartOption(src *clibase.Bool) clibase.Option {
987995
Default: "false",
988996
}
989997
}
998+
999+
type stdioErrLogReader struct {
1000+
l slog.Logger
1001+
}
1002+
1003+
func (r stdioErrLogReader) Read(_ []byte) (int, error) {
1004+
r.l.Error(context.Background(), "reading from stdin in stdio mode is not allowed")
1005+
return 0, io.EOF
1006+
}

0 commit comments

Comments
 (0)