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

client: Expose rate limit extensions in response #12

Merged
merged 8 commits into from
Feb 25, 2019

Conversation

philipgough
Copy link
Contributor

No description provided.

@philipgough philipgough force-pushed the expose-limit-extensions branch from 824e376 to ffa7c9f Compare February 21, 2019 09:17
@unleashed
Copy link
Contributor

While this looks good for responses, there is another response we are very interested in, which is the one you get when you specify the hierarchy=1 extension, would you like to try it out?

@philipgough
Copy link
Contributor Author

@unleashed Yep sure. I will take a look at that.

Copy link
Contributor

@unleashed unleashed left a comment

Choose a reason for hiding this comment

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

👍 (see comment about the hierarchy ext)

@unleashed
Copy link
Contributor

@philipgough 3scale/apisonator#75 - we haven't documented it yet, so it's a good moment to do so (we can talk doubts in the chat).

@philipgough
Copy link
Contributor Author

@Unleased I found that and then deleted my comment but you were too quick :)

@philipgough philipgough force-pushed the expose-limit-extensions branch 4 times, most recently from 0e844ca to 219d10e Compare February 25, 2019 09:51
@philipgough
Copy link
Contributor Author

@unleashed - this pr grew a bit from the original plan. Regardless, support and tests have now been added for limit and hierarchy extension and ready for review.

@philipgough philipgough force-pushed the expose-limit-extensions branch from 219d10e to 22e535e Compare February 25, 2019 09:55
Copy link
Contributor

@unleashed unleashed left a comment

Choose a reason for hiding this comment

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

Looks good 👍 - can you check the comment about storing pointers to ints?

client/client.go Outdated

if limReset := resp.Header[limitResetHeaderKey][0]; limReset != "" {
resetLimit, _ := strconv.Atoi(limReset)
authRepRes.limitReset = &resetLimit
Copy link
Contributor

Choose a reason for hiding this comment

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

this does not look good if this is meant to be an integer - why not do this:

authRepRes.limitReset = strconv.Atoi(limReset)

(same thing applies just above)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well it returns two values, one of which is an error which we can safely ignore here. Can probably move this to one line. 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we safely ignore it? I mean, if we do, what would be the contents of the int variable? 0? I think I'd prefer to have it nil'ed if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well I personally don't like to ignore errors. Bt in this case I thought it was safe to assume that backend will return a value that can be cast to an int meaning we dont have to check the error. However happy to go the more verbose path if you think its safer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, backend won't do that ever, because it's officially bug-free, but you know, sometimes some ops guys tries to modify live production code or the odd contribution ends up affecting backend in the future...

So this is my proposal: don't turn them into pointers, use a struct to contain both ints as normal variables, and use a pointer to the struct to signal it is available. Now, if the parsing fails, you could use a non-sensical value, perhaps a negative value. Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

client/types.go Outdated
Success bool
StatusCode int
limitRemaining *int
limitReset *int
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these pointers? You seldom see pointers to (machine) word-sized integers because it is more efficient to just store them in the same space a pointer would consume, plus you save the indirection caused by a second access to memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the zero value for integers is 0 and I did not want it to be confusing. If someone calls the function and the extension is not being used, prefer to return nil than zero, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think then I'd prefer to have a LimitRemaining struct with both ints so that you'd only need to check one pointer for nil, and if it exists, then you can read the ints without further indirection nor checks.

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 so you mean to wrap the limits in some struct, maybe limitExtensions or something and assume its safe to do a single check for nil?

Copy link
Contributor

@unleashed unleashed Feb 25, 2019

Choose a reason for hiding this comment

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

yep, if the header was parsed (even if the Atoi failed, which you can deal with separately) you then fill the two integers in this struct and set a pointer to it in the response (otherwise it just stays with nil).

@philipgough philipgough force-pushed the expose-limit-extensions branch from 22e535e to 44137aa Compare February 25, 2019 16:16
Copy link
Contributor

@unleashed unleashed left a comment

Choose a reason for hiding this comment

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

Looks good - Squash the two test commits into a single one and merge! 👍

test: Updates extension test for changes to limit extension api
…his simplifies the interface for the caller and avoids duplicate nil checks
@philipgough philipgough force-pushed the expose-limit-extensions branch from 44137aa to 7398eb2 Compare February 25, 2019 16:44
@codecov-io
Copy link

Codecov Report

Merging #12 into master will increase coverage by 1.15%.
The diff coverage is 80.48%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #12      +/-   ##
==========================================
+ Coverage   81.81%   82.97%   +1.15%     
==========================================
  Files           5        5              
  Lines         242      276      +34     
==========================================
+ Hits          198      229      +31     
+ Misses         33       32       -1     
- Partials       11       15       +4
Impacted Files Coverage Δ
client/auth_rep.go 86.36% <100%> (ø) ⬆️
client/types.go 50% <100%> (ø) ⬆️
client/authz.go 89.74% <100%> (ø) ⬆️
client/report.go 65% <100%> (+12.5%) ⬆️
client/client.go 87.41% <77.77%> (-3.42%) ⬇️

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 ae45048...7398eb2. Read the comment docs.

@philipgough philipgough merged commit e54ff7d into master Feb 25, 2019
@philipgough philipgough deleted the expose-limit-extensions branch February 25, 2019 16:51
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.

3 participants