mirror of
https://github.com/coder/coder.git
synced 2025-07-18 14:17:22 +00:00
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.
This commit is contained in:
@ -37,7 +37,7 @@ func (a *LogsAPI) BatchCreateLogs(ctx context.Context, req *agentproto.BatchCrea
|
||||
return nil, err
|
||||
}
|
||||
if workspaceAgent.LogsOverflowed {
|
||||
return nil, xerrors.New("workspace agent logs overflowed")
|
||||
return &agentproto.BatchCreateLogsResponse{LogLimitExceeded: true}, nil
|
||||
}
|
||||
|
||||
if len(req.Logs) == 0 {
|
||||
@ -128,7 +128,7 @@ func (a *LogsAPI) BatchCreateLogs(ctx context.Context, req *agentproto.BatchCrea
|
||||
return nil, xerrors.Errorf("publish workspace update: %w", err)
|
||||
}
|
||||
}
|
||||
return nil, xerrors.New("workspace agent log limit exceeded")
|
||||
return &agentproto.BatchCreateLogsResponse{LogLimitExceeded: true}, nil
|
||||
}
|
||||
|
||||
// Publish by the lowest log ID inserted so the log stream will fetch
|
||||
|
@ -215,9 +215,9 @@ func TestBatchCreateLogs(t *testing.T) {
|
||||
LogSourceId: logSource.ID[:],
|
||||
Logs: []*agentproto.Log{},
|
||||
})
|
||||
require.Error(t, err)
|
||||
require.ErrorContains(t, err, "workspace agent logs overflowed")
|
||||
require.Nil(t, resp)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, resp)
|
||||
require.True(t, resp.LogLimitExceeded)
|
||||
require.False(t, publishWorkspaceUpdateCalled)
|
||||
require.False(t, publishWorkspaceAgentLogsUpdateCalled)
|
||||
})
|
||||
@ -419,8 +419,9 @@ func TestBatchCreateLogs(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
require.Error(t, err)
|
||||
require.Nil(t, resp)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, resp)
|
||||
require.True(t, resp.LogLimitExceeded)
|
||||
require.True(t, publishWorkspaceUpdateCalled)
|
||||
require.False(t, publishWorkspaceAgentLogsUpdateCalled)
|
||||
})
|
||||
|
Reference in New Issue
Block a user