feat(api): bound event list responses by size and time - #351
Draft
tsan88 wants to merge 1 commit into
Draft
Conversation
/api/events and /api/events/preview returned every event stored for the requested type/project — FindOptions already had Limit and Offset, but the handlers never filled them in. On a busy instance one preview request weighed 25.8 MB, and the frontend then filtered that in the browser. Both endpoints now accept limit, offset/page, from, to and window (15m, 24h, "7d"; "all" opts out of the configured default), and report what was applied in the response meta so a client can tell a truncated response from an exhausted one. Defaults are deliberately conservative and non-breaking: 1000 events per response, no time window. An operator can set ui.default_window (or UI_DEFAULT_WINDOW) to also narrow lists by time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/api/eventsand/api/events/previewreturned every event stored for the requested type/project.LimitandOffsetalready existed inevent.FindOptions, but the handlers never filled them in.Measured on a production instance (≈40k events/day): a single
/api/events/previewresponse for one project weighed 25.8 MB, which the frontend then filtered in the browser. That is the dominant cost of opening the UI.Changes
limit,offset/page,from,toandwindow("15m","24h","7d";"all"or"0"opt out of the configured default).from/totake unix seconds or ISO 8601.metareports what was applied (limit,offset,returned,from,to), so a client can tell a truncated response from an exhausted one.uiconfig section:default_limit(1000),max_limit(5000),default_window(empty), also settable viaUI_DEFAULT_LIMIT/UI_MAX_LIMIT/UI_DEFAULT_WINDOW.RegisterAPItakes aListLimitsargument.Defaults are deliberately conservative: a size cap only, no time window, so nothing disappears from an existing UI unless an operator asks for it. An unreadable
default_windowlogs a warning and is ignored rather than failing startup.On our instance the same request is now 189 KB with
default_limit: 500anddefault_window: 1h.Testing
go vet ./...,go test ./...andgo buildpass. AddedTestAPI_Events_Limits(default limit,max_limitceiling, default window,window=all, explicitfrom/to) andTestParseWindow. Existing tests pass an emptyListLimits, which keeps the old "return everything" behaviour.Note for maintainers: the frontend side of this (a period selector that sends
window=) is buggregator/frontend#290, and it degrades gracefully against a server without this PR.