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:
Spike Curtis
2024-02-09 16:17:20 +04:00
committed by GitHub
parent 1f5a6d59ba
commit 92b2e26a48
4 changed files with 81 additions and 66 deletions

View File

@ -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

View File

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