Skip to content

Commit 92b2e26

Browse files
authored
feat: send log limit exceeded in response, not error (#12078)
When we exceed the db-imposed limit of logs, we need to communicate that back to the agent. In v1 we did it with a 4xx-level HTTP status, but with dRPC, the errors are delivered as strings, which feels fragile to me for something we want to gracefully handle. So, this PR adds the log limit exceeded as a field on the response message, and fixes the API handler to set it as appropriate instead of an error.
1 parent 1f5a6d5 commit 92b2e26

File tree

4 files changed

+81
-66
lines changed

4 files changed

+81
-66
lines changed

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);

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
})

0 commit comments

Comments
 (0)