-
Notifications
You must be signed in to change notification settings - Fork 30
feat(api/log)!: support paging on GetBuildLogs
#798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
88c0df7
5e1c4b0
9368375
2328018
404163c
29e8aff
ed5f252
f8f03d0
3c43516
04ba4ab
9aea6af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,15 +7,15 @@ package api | |
| import ( | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| "github.com/go-vela/server/router/middleware/org" | ||
| "github.com/go-vela/server/router/middleware/user" | ||
| "strconv" | ||
|
|
||
| "github.com/go-vela/server/database" | ||
| "github.com/go-vela/server/router/middleware/build" | ||
| "github.com/go-vela/server/router/middleware/org" | ||
| "github.com/go-vela/server/router/middleware/repo" | ||
| "github.com/go-vela/server/router/middleware/service" | ||
| "github.com/go-vela/server/router/middleware/step" | ||
| "github.com/go-vela/server/router/middleware/user" | ||
| "github.com/go-vela/server/util" | ||
|
|
||
| "github.com/go-vela/types/library" | ||
|
|
@@ -47,6 +47,17 @@ import ( | |
| // description: Build number | ||
| // required: true | ||
| // type: integer | ||
| // - in: query | ||
| // name: page | ||
| // description: The page of results to retrieve | ||
| // type: integer | ||
| // default: 1 | ||
| // - in: query | ||
| // name: per_page | ||
| // description: How many results per page to return | ||
| // type: integer | ||
| // maximum: 500 | ||
| // default: 100 | ||
| // security: | ||
| // - ApiKeyAuth: [] | ||
| // responses: | ||
|
|
@@ -82,10 +93,30 @@ func GetBuildLogs(c *gin.Context) { | |
| "user": u.GetName(), | ||
| }).Infof("reading logs for build %s", entry) | ||
|
|
||
| // capture page query parameter if present | ||
| page, err := strconv.Atoi(c.DefaultQuery("page", "1")) | ||
| if err != nil { | ||
| //nolint:lll // ignore long line length due to error message | ||
| retErr := fmt.Errorf("unable to convert page query parameter for build %s: %w", entry, err) | ||
| util.HandleError(c, http.StatusBadRequest, retErr) | ||
|
|
||
| return | ||
| } | ||
|
|
||
| // capture per_page query parameter if present | ||
| perPage, err := strconv.Atoi(c.DefaultQuery("per_page", "10")) | ||
cognifloyd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| retErr := fmt.Errorf("unable to convert per_page query parameter for build %s: %w", entry, err) | ||
| util.HandleError(c, http.StatusBadRequest, retErr) | ||
|
|
||
| return | ||
| } | ||
|
|
||
| // ensure per_page isn't above or below allowed values | ||
| perPage = util.MaxInt(1, util.MinInt(500, perPage)) | ||
|
||
|
|
||
| // send API call to capture the list of logs for the build | ||
| // | ||
| // TODO: add page and per_page query parameters | ||
| l, t, err := database.FromContext(c).ListLogsForBuild(b, 1, 100) | ||
| l, t, err := database.FromContext(c).ListLogsForBuild(b, page, perPage) | ||
| if err != nil { | ||
| retErr := fmt.Errorf("unable to get logs for build %s: %w", entry, err) | ||
|
|
||
|
|
@@ -96,8 +127,8 @@ func GetBuildLogs(c *gin.Context) { | |
|
|
||
| // create pagination object | ||
| pagination := Pagination{ | ||
| Page: 1, | ||
| PerPage: 100, | ||
| Page: page, | ||
| PerPage: perPage, | ||
| Total: t, | ||
| } | ||
| // set pagination headers | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doc comment is a bit clearer on my intention. @jbrockopp do you want the maximum to be 100? I would like to increase that for this endpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we shouldn't allow anything more than 100 results per page 👍
Especially for something like logs which can be quite taxing to retrieve depending on the size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even 100 seems like a lot, tbh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dropped the maximum back to 100.
And I left the default at 100 so that it is backwards compatible. Does that look better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cognifloyd apologies if my initial review left you under the impression that this breaking change is bad.
More so, I wanted to confirm it because if so, we try to update the PR title with a
!i.e.
feat(api/log): support paging on GetBuildLogs->feat(api/log)!: support paging on GetBuildLogsFWIW - I'm not opposed to making the default
10instead of current behavior of100.Like @wass3rw3rk mentioned,
100does seem like a lot since it can be taxing on the system.i.e. someone has a build with a bunch of steps that each have >
1 MBin logsFor now, I'll plan to approve this PR so if we don't want to change it, then we can consider it in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I can add
!(I'm slowly learning this commit format) and switch to 10 by default. I'll do that in 30 min or soThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I lowered the
per_pagedefault to 10 and marked this PR as a breaking change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks.. i like it. we can either hardcode in CLI as @jbrockopp said and/or consider dropping hints if they are viewing a subset of available data.