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

improve v2 rate-limiter #380

Merged
merged 3 commits into from
Jan 22, 2021
Merged

improve v2 rate-limiter #380

merged 3 commits into from
Jan 22, 2021

Conversation

MalloZup
Copy link
Contributor

@MalloZup MalloZup commented Jan 14, 2021

Descriptions:

This PR improve the rate-limit interceptor changing interface.

Links:

This PR is follow-up of discussion at thanos-io/thanos#3654

Signed-off-by: dmaiocchi <sodar@riseup.net>
@google-cla
Copy link

google-cla bot commented Jan 14, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@MalloZup
Copy link
Contributor Author

@googlebot I signed it!

🏭

@codecov-io
Copy link

codecov-io commented Jan 15, 2021

Codecov Report

Merging #380 (6bfe427) into v2 (a79558a) will decrease coverage by 19.36%.
The diff coverage is 46.37%.

Impacted file tree graph

@@             Coverage Diff             @@
##               v2     #380       +/-   ##
===========================================
- Coverage   83.58%   64.21%   -19.37%     
===========================================
  Files          30       34        +4     
  Lines         932      897       -35     
===========================================
- Hits          779      576      -203     
- Misses        114      265      +151     
- Partials       39       56       +17     
Impacted Files Coverage Δ
chain.go 0.00% <ø> (-90.91%) ⬇️
grpctesting/interceptor_suite.go 0.00% <0.00%> (ø)
interceptors/ratelimit/ratelimit.go 50.00% <0.00%> (-50.00%) ⬇️
interceptors/tags/fieldextractor.go 13.79% <0.00%> (-71.51%) ⬇️
grpctesting/pingservice.go 52.63% <20.00%> (ø)
interceptors/retry/retry.go 66.66% <70.00%> (-9.58%) ⬇️
interceptors/skip/interceptor.go 71.42% <71.42%> (ø)
interceptors/logging/interceptors.go 100.00% <100.00%> (ø)
interceptors/logging/logging.go 61.53% <100.00%> (-6.21%) ⬇️
interceptors/logging/payload.go 67.18% <100.00%> (-15.43%) ⬇️
... and 36 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 08b17eb...6bfe427. Read the comment docs.

@MalloZup MalloZup changed the title WIP: improve v2 rate-limiter improve v2 rate-limiter Jan 15, 2021
Copy link
Collaborator

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

LGTM, just some thoughts. Hope this makes sense (:

go.mod Outdated Show resolved Hide resolved
interceptors/ratelimit/examples_test.go Outdated Show resolved Hide resolved
interceptors/ratelimit/examples_test.go Outdated Show resolved Hide resolved
interceptors/ratelimit/examples_test.go Outdated Show resolved Hide resolved
interceptors/ratelimit/examples_test.go Outdated Show resolved Hide resolved
interceptors/ratelimit/ratelimit.go Outdated Show resolved Hide resolved
@bwplotka
Copy link
Collaborator

Let me know when it's good for another review 🤗

Fixes #351

@MalloZup
Copy link
Contributor Author

@bwplotka yop I will work this week. thx for feedback. I own you a cake or something 😁

@MalloZup MalloZup force-pushed the rate-limit-v2 branch 6 times, most recently from 5a222db to 56ffdd7 Compare January 21, 2021 11:13
@MalloZup
Copy link
Contributor Author

MalloZup commented Jan 21, 2021

@bwplotka I do have reworked a bit the PR with providers.

A part of the conflict file, I do have some doubts. I would appreciated if you have any feedback.

when Running go test locally I do have:
go test

# github.com/grpc-ecosystem/go-grpc-middleware/providers/tockenbucket/v2 [github.com/grpc-ecosystem/go-grpc-middleware/providers/tockenbucket/v2.test]
./examples_test.go:27:41: cannot use limiter (type TockenBucketInterceptor) as type "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/ratelimit".Limiter in argument to "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/ratelimit".UnaryServerInterceptor:
	TockenBucketInterceptor does not implement "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/ratelimit".Limiter (wrong type for Limit method)
		have Limit(context.Context) error
		want Limit() bool
./examples_test.go:30:41: cannot use limiter (type TockenBucketInterceptor) as type "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/ratelimit".Limiter in argument to "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/ratelimit".UnaryServerInterceptor:
	TockenBucketInterceptor does not implement "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/ratelimit".Limiter (wrong type for Limit method)
		have Limit(context.Context) error
		want Limit() bool
./examples_test.go:30:41: cannot use "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/ratelimit".UnaryServerInterceptor(limiter) (type grpc.UnaryServerInterceptor) as type grpc.StreamServerInterceptor in argument to middleware.WithStreamServerChain
FAIL	github.com/grpc-ecosystem/go-grpc-middleware/providers/tockenbucket/v2 [build failed]

I can't follow-up this error since I do have changed the interface to accept error. 🤔

Right now I don't know if the issue is cause because of some golang modules/import messiness or some other reason.. Will check more in details but if you have any hint/lights would be great ❤️

@bwplotka
Copy link
Collaborator

bwplotka commented Jan 22, 2021

Yes. This is major problem with multi modules.

you need to play with replace to make sure it works for you locally.

But ideal flow is:

  1. Change interface first. Merge PR to v2
  2. Make a PR to add provider on top of new interface. Make sure to update code dep to latest.

Done (:

@MalloZup
Copy link
Contributor Author

@bwplotka thx for confirmation, will play with that

@MalloZup
Copy link
Contributor Author

@bwplotka take look on this. I have splitted the PR in 2 parts.

The 1st part , (this here) will just implement the error part.

The 2nd part PR follow-up will base on this and implement what I was doing previously

TIA 🌻

Copy link
Collaborator

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Solid.

Lgtm! Let's fix comment if you want (:

@MalloZup
Copy link
Contributor Author

@bwplotka ok I missed the comment. should be fine now

Signed-off-by: dmaiocchi <sodar@riseup.net>
@bwplotka bwplotka merged commit 6672a20 into grpc-ecosystem:v2 Jan 22, 2021
@MalloZup
Copy link
Contributor Author

thx @bwplotka will follow-up with 2nd ❤️

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.

None yet

3 participants