Skip to content
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

feat: Add configurable pageSize on paginated requests #245

Merged

Conversation

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented Jun 28, 2022

Add configurable limit on paginated request

This add the query parameter 'page_size' on both GET /transactions, GET /accounts and GET /balances endpoints.
The parameter is capped to a value of 1000.
The default value still the same as before (15).

The PR also fix some tests around pagination which was working but was not doing the right thing (see api/controllers/pagination_test.go line 209).

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring / Technical debt

What parts of the code are impacted ?

  • pkg/api/controllers
  • pkg/storage

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@gfyrag gfyrag added this to the v1.6.0 milestone Jun 28, 2022
@gfyrag gfyrag self-assigned this Jun 28, 2022
@gfyrag gfyrag requested a review from a team as a code owner June 28, 2022 14:10
@gfyrag gfyrag force-pushed the feature/num-567-let-users-get-more-than-15-transactions branch 3 times, most recently from 404181c to 039f00a Compare June 28, 2022 14:32
@codecov
Copy link

codecov bot commented Jun 28, 2022

Codecov Report

Merging #245 (53a1014) into main (a6c1a6d) will increase coverage by 0.32%.
The diff coverage is 84.78%.

@@            Coverage Diff             @@
##             main     #245      +/-   ##
==========================================
+ Coverage   71.19%   71.51%   +0.32%     
==========================================
  Files          78       79       +1     
  Lines        4180     4227      +47     
==========================================
+ Hits         2976     3023      +47     
+ Misses        942      937       -5     
- Partials      262      267       +5     
Impacted Files Coverage Δ
pkg/storage/storage.go 55.22% <ø> (ø)
pkg/storage/sqlstorage/accounts.go 83.73% <66.66%> (-1.98%) ⬇️
pkg/api/controllers/balance_controller.go 75.92% <70.00%> (-2.80%) ⬇️
pkg/storage/sqlstorage/balances.go 77.67% <70.00%> (-1.96%) ⬇️
pkg/api/controllers/transaction_controller.go 92.63% <75.00%> (-1.52%) ⬇️
pkg/storage/sqlstorage/transactions.go 85.79% <91.66%> (-0.08%) ⬇️
pkg/api/controllers/account_controller.go 88.11% <100.00%> (+0.88%) ⬆️
pkg/api/controllers/query.go 100.00% <100.00%> (ø)
pkg/storage/accounts.go 100.00% <100.00%> (+11.76%) ⬆️
pkg/storage/balances.go 100.00% <100.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a6c1a6d...53a1014. Read the comment docs.

pkg/api/controllers/query.go Fixed Show resolved Hide resolved
pkg/api/controllers/query.go Fixed Show resolved Hide resolved
@altitude altitude changed the title feat: Add configurable limit on paginated request. feat: Add configurable pageSize on paginated requests Jul 1, 2022
pkg/api/controllers/swagger.yaml Outdated Show resolved Hide resolved
pkg/api/controllers/swagger.yaml Outdated Show resolved Hide resolved
@gfyrag gfyrag force-pushed the feature/num-567-let-users-get-more-than-15-transactions branch 2 times, most recently from 41572ae to d6c66c7 Compare July 5, 2022 10:11
@antoinegelloz
Copy link
Contributor

We might want to wait for #243 to be merged, and apply the same feature on the new GetBalances route ?

jdupas22
jdupas22 previously approved these changes Jul 5, 2022
if pageSize > MaxPageSize {
pageSize = MaxPageSize
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can print a log here ?

Copy link
Contributor Author

@gfyrag gfyrag Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? If we print a log each time the code take a default value, it will give a lot of useless logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, i don't remind if it complete, i have to check, but all requests should be logged using opentelemetry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? If we log each time a default value is used, it will give a lot of logs ^^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't mean especially logging the default value, but logging that the parameter given was higher than expeced. I think this can be useful to determine how our api (and our parameters) are used by our customers in way we didn't predict ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, i agree.
Instead of a log, i think an opentelemetry attributes is well suited.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdupas22 I checked the instrumentation library used to handle http request (https://pkg.go.dev/go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin) and it register the full path inside an attribute named "http.target".

pkg/storage/sqlstorage/accounts.go Show resolved Hide resolved
@gfyrag
Copy link
Contributor Author

gfyrag commented Jul 5, 2022

#243

We might want to wait for #243 to be merged, and apply the same feature on the new GetBalances route ?

Completely agree.

@gfyrag gfyrag force-pushed the feature/num-567-let-users-get-more-than-15-transactions branch from d3ba1fc to 83bc397 Compare July 8, 2022 10:33
This add the query parameter 'page_size' on both GET /transactions, GET /accounts, and GET /balances endpoints.
The parameter is capped to a value of 1000.
The default value still the same as before (15).

The PR also fix some tests around pagination which was working but was not doing the right thing (see api/controllers/pagination_test.go line 209).
@gfyrag gfyrag force-pushed the feature/num-567-let-users-get-more-than-15-transactions branch from 83bc397 to 2bce66b Compare July 8, 2022 13:31
@altitude altitude merged commit 3ca2993 into main Jul 12, 2022
@altitude altitude deleted the feature/num-567-let-users-get-more-than-15-transactions branch July 12, 2022 14:39
gfyrag added a commit that referenced this pull request Jul 18, 2022
* feat(api): Add configurable page_size on paginated request.

Co-authored-by: Antoine Gelloz <antoine.gelloz@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants