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

add local cache stats #114

Merged
merged 3 commits into from
Jan 17, 2020
Merged

Conversation

freedomljc
Copy link
Contributor

@freedomljc freedomljc commented Dec 30, 2019

To further check how local_cache performs, add stats for local_cache. And the local_cache stats will be available in {debug_port}/stats.

@freedomljc
Copy link
Contributor Author

freedomljc commented Dec 30, 2019

Manually tested it, the local_cache stats is available:

ratelimit.localcache.hitCount: 8
ratelimit.localcache.averageAccessTime: 1577747704
ratelimit.localcache.entryCount: 2
ratelimit.localcache.evacuateCount: 0
ratelimit.localcache.expiredCount: 0
ratelimit.localcache.lookupCount: 56
ratelimit.localcache.missCount: 48
ratelimit.localcache.overwriteCount: 0

@@ -89,7 +89,7 @@ func testBasicBaseConfig(grpcPort, perSecond string, local_cache_size string) fu
os.Setenv("RUNTIME_SUBDIRECTORY", "ratelimit")
os.Setenv("REDIS_PERSECOND_SOCKET_TYPE", "tcp")
os.Setenv("REDIS_SOCKET_TYPE", "tcp")
os.Setenv("LOCAL_CACHE_SIZE", local_cache_size)
os.Setenv("LOCAL_CACHE_SIZE_IN_BYTES", local_cache_size)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In #111 (comment), we updated the env variable name from LOCAL_CACHE_SIZE to LOCAL_CACHE_SIZE_IN_BYTES, but missed updating the env variable name in test case. (It is a duplicate change for #112)

Copy link
Member

Choose a reason for hiding this comment

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

Why don't the integration tests run in CI? I don't remember the history here. Can you fix this? cc @junr03

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The integration tests run in the CI. In current framework of integration test, client sends the requests, and then verifies the response. When adding the integration test for local_cache, we expect the responses are same as before, no matter whether local_cache is enabled or not. if there is a typo for env variable, it means the local_cache is disabled. That's why it is not easy to catch the typo. But there is one trick we can do to verify whether local_cache is used in the integration test: add time.sleep into it,, check {debug_port}/stats to see local_cache related stats.

Copy link
Member

Choose a reason for hiding this comment

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

it all runs in the same travis target: https://travis-ci.org/lyft/ratelimit/builds/631398436#L480. It could be separated into a unit test and an integration test target.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@junr03 , but if I understood correctly, separating it into another target won't help to catch this typo. By mistyping LOCAL_CACHE_SIZE_IN_BYTES as LOCAL_CACHE_SIZE , it means the local_cache is disabled. Since we expect the responses are same no matter whether local_cache is enabled or not, the tests on new-added target still pass.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, I wasn't talking about the typo problem. I was talking about making it easier to see that there are CI targets for both unit tests and integration tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm hesitating to make that change. Generally, the developer should be able to setup the unit test and integration test env, and figure out which part goes wrong if the test fails.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this. A few comments.

@@ -89,7 +89,7 @@ func testBasicBaseConfig(grpcPort, perSecond string, local_cache_size string) fu
os.Setenv("RUNTIME_SUBDIRECTORY", "ratelimit")
os.Setenv("REDIS_PERSECOND_SOCKET_TYPE", "tcp")
os.Setenv("REDIS_SOCKET_TYPE", "tcp")
os.Setenv("LOCAL_CACHE_SIZE", local_cache_size)
os.Setenv("LOCAL_CACHE_SIZE_IN_BYTES", local_cache_size)
Copy link
Member

Choose a reason for hiding this comment

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

Why don't the integration tests run in CI? I don't remember the history here. Can you fix this? cc @junr03

src/redis/local_cache_stats.go Show resolved Hide resolved
@freedomljc
Copy link
Contributor Author

@mattklein123 , when you get the chance, can you take a look again? thanks.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks, generally LGTM with some test comments.

}

// Check the correctness of hitCount, missCount, lookupCount, expiredCount and entryCount
submatch := regexp.MustCompile(`localcache.hitCount:(\d+)\|g\n`).FindStringSubmatch(sink.record)
Copy link
Member

Choose a reason for hiding this comment

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

There is a huge amount of duplication between each test on how you deal with the regex, etc. Can you unify that into a utility? Also, at a higher layer, testing the stats in this way seems suboptimal. Can't you just store the stats as integers vs. strings and then look at them directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just moved it to the utility method, and also simplified it.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks this LGTM. Can you add 1 negative integration test which confirms there is no local cache when the environment variable is not / the default? This can be done by just taking one of the existing tests and verifying all of the local cache stats are 0?

@freedomljc
Copy link
Contributor Author

freedomljc commented Jan 3, 2020

Thanks this LGTM. Can you add 1 negative integration test which confirms there is no local cache when the environment variable is not / the default? This can be done by just taking one of the existing tests and verifying all of the local cache stats are 0?

Currently the integration tests are more about client sends the ratelimit requests to sever, and verify the ratelimit response. But there isn't a good way to access the stats from the client side. To verify the stats, we'll have to parse the response from the {debug_port}/stats. In addition, if local_cache is disabled, the new-added local_cache stats won't be available per https://github.com/lyft/ratelimit/blob/54e6c7cdb9ff312ade1f66b8986c4f719b33fa6d/src/server/server_impl.go#L127-L129. pls let me know if you prefer to do in this way(parse the response, check whether the new-added local_cache stats are available or not) ?

@mattklein123
Copy link
Member

pls let me know if you prefer to do in this way(parse the response, check whether the new-added local_cache stats are available or not) ?

The way this is typically handled is to allow grabbing the stats directly from the running server when running for an integration test. Meaning, just reach directly into the server, grab the stats store, and inspect the stats. I just refreshed my memory of this code and it looks like this is not easily possible, though it would make for much better tests in general, if you want to work on it.

Connecting to the stats endpoint and parsing the output is also a way of doing it though it seems more hacky than necessary.

I think it would be fine to do this as a follow up, but having looked at this change again, I don't understand how the integration testing support you added for the change originally actually tests anything if the tests all pass with the wrong env variable? Shouldn't some integration tests fail if the variable is not set correctly? Or do you not have an integration test with the local cache?

@freedomljc
Copy link
Contributor Author

freedomljc commented Jan 4, 2020

I think it would be fine to do this as a follow up, but having looked at this change again, I don't understand how the integration testing support you added for the change originally actually tests anything if the tests all pass with the wrong env variable? Shouldn't some integration tests fail if the variable is not set correctly? Or do you not have an integration test with the local cache?

The integration test with the local cache works, I got the above stats(#114 (comment)) by temporarily changing the integration test: adding time.sleep, and checking the {debug_port}/stats.

Regarding the reasons why the integration test didn't fail with the wrong env variable before:

I'll continue to improve on it when I get more bandwidth. May ask for your advise later.

@mattklein123
Copy link
Member

Sorry I'm still confused. In https://github.com/lyft/ratelimit/blob/master/test/integration/integration_test.go you have a bunch of test logic around the local cache. If the test thought the local cache was enabled, but it was not, what are those tests testing? Please remove all of that logic if it doesn't actually test anything.

I think having good integration tests for this is likely as easy as exposing the stats scope outside of the runner: https://github.com/lyft/ratelimit/blob/87ed58e3a8c65548e081d4be7097959d873d28ad/src/service_cmd/runner/runner.go#L22

Basically just make the runner into an object with methods, and store the root stat scope in a way that you can access it from tests and read the stat data. Then your integration tests can actually look at stats to verify the right interactions if there is no other way to verify them.

@freedomljc
Copy link
Contributor Author

freedomljc commented Jan 6, 2020

Sorry for the confusion. I initially added the integration test(e6cf1ec), to validate whether it would change the behavior if local_cache is enabled.(in our case, the responses should be same as before). But please let me know if you prefer to remove the added tests.

Thanks for your suggestion, it works (https://github.com/lyft/ratelimit/pull/115/files). Since it changes the interface, prefer to separate it into a different PR. Will let you know when it is ready for review.

@mattklein123
Copy link
Member

Sorry for the confusion. I initially added the integration test(e6cf1ec), to validate whether it would change the behavior if local_cache is enabled.(in our case, the responses should be same as before). But please let me know if you prefer to remove the added tests.

My suggestion is to:

  1. First review/merge Plugin statstore into runner #115. Let me know when that is no longer WIP.
  2. Remove all of the local cache specific logic from the integration tests internals.
  3. Instead test the local cache in the integration tests using the stats you can easily get from 115.

@stale
Copy link

stale bot commented Jan 13, 2020

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale label Jan 13, 2020
@stale stale bot removed the stale label Jan 15, 2020
@freedomljc
Copy link
Contributor Author

freedomljc commented Jan 15, 2020

@mattklein123 , I just made two changes in integration test:

Regarding your suggestions:

Remove all of the local cache specific logic from the integration tests internals.

After undoing the changes on TestBasicConfigLegacy, most changes in integration test have been reverted (check the integration_test.go in diff), except for the logic about validating the stats over_limit and over_limit_with_local_cache when local_cache is enabled.

Instead test the local cache in the integration tests using the stats you can easily get from 115.

There exists some inconvenience to validate the new-added local stats in integration test. We'll have to add time.sleep(10s) before validating those stats, considering current statsstore flushes those StatGenerator stats per 10s. I'm inclined not to add sleep(10s) there.
There also exists other options like passing the customized statsstore as the parameter of run() method in runner, or be able to update the statsstore after the construction of runner. But i'm not sure whether it is worthwhile to make those changes considering the parameter statsstore is not needed in most cases except for validating the stats from StatGenerator.

Pls let me know your thoughts, thanks.

@mattklein123 mattklein123 self-assigned this Jan 16, 2020
@mattklein123
Copy link
Member

There exists some inconvenience to validate the new-added local stats in integration test. We'll have to add time.sleep(10s) before validating those stats, considering current statsstore flushes those StatGenerator stats per 10s. I'm inclined not to add sleep(10s) there.

Why do we care about flushing? Can't you just read the current state from the store?

@freedomljc
Copy link
Contributor Author

Why do we care about flushing? Can't you just read the current state from the store?

The stats from StatGenerator(including new-added local cache stats) are different, and those stats are saved to the store while flushing.
For our case, the new-added local cache stats are saved to the store in the GenerateStats method, and the method GenerateStats gets invoked in the Flush method. The current statsstore invoked the Flush method every 10s, that's why we'll have to wait for 10s before validating the new-added local cache stats.

@mattklein123
Copy link
Member

OK that makes sense, but why can't you just manually flush the store before checking the stats?

@freedomljc
Copy link
Contributor Author

OK that makes sense, but why can't you just manually flush the store before checking the stats?

Sorry, didn't realize that before even though i did the trick in the unit test. Just added it.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Awesome, thanks. LGTM with one question.

Comment on lines -9 to -18
rate_limit:
unit: hour
requests_per_unit: 10

- key: key2_local
rate_limit:
unit: minute
requests_per_unit: 20

- key: key3_local
Copy link
Member

Choose a reason for hiding this comment

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

Sorry why are these removed here and below?

Copy link
Contributor Author

@freedomljc freedomljc Jan 17, 2020

Choose a reason for hiding this comment

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

The test data was added before for the local cache test in TestBasicConfigLegacy. Because we just made the change to undo the local cache test in TestBasicConfigLegacy (#114 (comment)), i removed the related test data as well.

Copy link
Member

Choose a reason for hiding this comment

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

OK got it, thanks.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Nice work!

@mattklein123 mattklein123 merged commit 403b5b5 into envoyproxy:master Jan 17, 2020
mjallday added a commit to verygoodsecurity/ratelimit that referenced this pull request Jan 26, 2021
* Add Docker Compose File (#27)

* docs: match envoy docs for remote_address ratelimiting (#29)

* docs: document dependency on gostats (#30)

* test and document whitelist behavior (#31)

Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>

* update dependencies (#35)

* update dependencies

* proto: use the proto defined in data-plane-api (#39)

* proto: check in protos to allow importing ratelimit as a library (#40)

* docs: update contact info (#42)

* redis: add the option to use a separate redis pool for per second limits (#41)

* fix duplicate mv (#43)

* docker: upgrade docker-compose setup (#46)

* Add gRPC health check (#47)

* logging: set log level (#50)

* go version: update to 1.11 (#53)

* docker compose: expose gRPC port on docker compose setup (#55)

* Configuration to ignore dotfiles. (#52)

This allows ratelimit to run on Kubernetes with configuration from a configmap.

* Add Dockerfile to enable builds (#58)

Signed-off-by: Steve Sloka <steves@heptio.com>

* ci: fix build (#73)

Fixes envoyproxy#71

Signed-off-by: Matt Klein <mklein@lyft.com>

* Run unit and integration tests with race detector enabled (#65)

* deps: update several of ratelimit's dependencies (#76)

* add stalebot (#78)

Signed-off-by: Matt Klein <mklein@lyft.com>

* docs: fix example 4 sample config (#79)

* fix redis-server binary name (envoyproxy#88)

* Fix build Dockerfile (envoyproxy#98)

Fix problem:
src/service_cmd/runner/runner.go:10:2: cannot find package "github.com/lyft/ratelimit/proto/ratelimit" in any of:
        /usr/local/go/src/github.com/lyft/ratelimit/vendor/github.com/lyft/ratelimit/proto/ratelimit (vendor tree)
        /usr/local/go/src/vendor/github.com/lyft/ratelimit/proto/ratelimit
        /usr/local/go/src/github.com/lyft/ratelimit/proto/ratelimit (from $GOROOT)
        /go/src/github.com/lyft/ratelimit/proto/ratelimit (from $GOPATH)
The command '/bin/sh -c go build -o /usr/local/bin/ratelimit src/service_cmd/main.go' returned a non-zero code: 1

* Redis TLS and Auth support (envoyproxy#96)

This adds support for TLS connections to redis as well as support for authentication.
Somewhat related to issue #61

* healthcheck: allow customizable healthcheck name (envoyproxy#102)

Description: this patch allows a consumer of the server package to customize the name of the healthchecker.

Signed-off-by: Jose Nino <jnino@lyft.com>

* health: make a few more types public (envoyproxy#104)

Description: envoyproxy#102 allowed for some customization. This PR makes the types public so that other servers can use this implementation.

Signed-off-by: Jose Nino <jnino@lyft.com>

* Add local cache to store whether it is over the limit (envoyproxy#111)

* Plugin statstore into runner (envoyproxy#115)

* fix: support auth without tls (envoyproxy#116)

Signed-off-by: tangxinfa <tangxinfa@gmail.com>

* add local cache stats (envoyproxy#114)

* Move license to templated Apache-2.0 (envoyproxy#123)

Signed-off-by: Derek Schaller <d_a_schaller@yahoo.com>

* Enable go modules (envoyproxy#124)

Signed-off-by: Steve Sloka <slokas@vmware.com>

* CI: Github Actions (envoyproxy#127)

Signed-off-by: Steve Sloka <slokas@vmware.com>

* community: update contributing guide (envoyproxy#139)

Fixes envoyproxy#138

Signed-off-by: Matt Klein <mklein@lyft.com>

* add http 1 `/json` endpoint (envoyproxy#136)

Signed-off-by: David Black <david.black@autodesk.com>

* Use mockgen version from go.mod instead of from "make bootstrap" (envoyproxy#143)

Even though the Makefile wants to encourage using mockgen@1.4.1, it
seems like the mocks have been generated using a pre-1.0 version of
mockgen. Using "go run github.com/golang/mock/mockgen" as a go:generate
command instead of just "mockgen" avoids the need to pre-install into
the developer's $PATH and uses the go.mod-specified version

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Upgrade gostats dependency from 0.2.6 to 0.4.0 (envoyproxy#141)

My interest is the UDP protocol support which appeared in gotstats 0.3.10

There's a breaking change as of https://github.com/lyft/gostats/releases/tag/v0.3.0
which is that gostats no longer publishes stats as expvars.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Upgrade radix (envoyproxy#137)

Signed-off-by: Tong Cai <caitong93@gmail.com>

* cache_impl_test.go: fix failing test with ipv6 (envoyproxy#144)

A newly-added test in envoyproxy#137 checks the exact text of an error message which
seems to vary when the network is tcp4 vs tcp6. This change relaxes the
assertion to look for "connection refused" in a panic without making
assumptions about what an IP address looks like.

Example failure:

--- FAIL: TestNewClientImpl (0.00s)
    --- FAIL: TestNewClientImpl/connection_refused (0.00s)
        cache_impl_test.go:442:
                Error Trace:    cache_impl_test.go:442
                Error:          func (assert.PanicTestFunc)(0x1724110) should panic with error message: "dial tcp 127.0.0.1:12345: connect: connection refused"
                                        Panic value:    "dial tcp [::1]:12345: connect: connection refused"
                                        Panic stack:    goroutine 27 [running]:

The testify assert package doesn't seem to support inexact matching on error messages, so the code gets a bit uglier than before.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Split redis-specific logic from generic key-value store logic (envoyproxy#142)

This is a pure refactoring with no behavior changes. It's a step toward being able
to add memcache as a backend (see envoyproxy#140).

This PR moves RateLimitCache from the redis package to a new "limiter" package, along with
code for time/jitter, local cache stats,  and constructing cache keys. All that can be reused
with memcache.

After this PR, the redis package is imported in exactly two places:
- in service_cmd/runner/runner.go to call redis.NewRateLimiterCacheImplFromSettings()
- in service/ratelimit.go in ShouldRateLimit to identify if a recovered panic is a redis.RedisError. If so, a stat is incremented and the panic() propagation is ended and in favor of returning the error as a the function result.

The PR also includes changes by goimports to test/service/ratelimit_test.go
so that the difference between package name vs file path name is explicit
instead of implicit.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* json handler: return full ratelimit service response as json (envoyproxy#148)

Previously an HTTP POST to /json would only return an HTTP status code,
not all the other details supported by grpc ratelimit responses.

With this change an HTTP POST to /json receives the full proto3 response
encoded as json by jsonpb.

It seems unlikely that anyone would be parsing the text "over limit" from
the HTTP body instead of just reading the 429 response code, but for anyone
doing that this would be a breaking change.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Update goruntime to latest, 0.2.5.  Add new config for watching changes in runtime config folder directly instead of the runtime root dir. (envoyproxy#151)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Drop support for legacy ratelimit.proto and upgrade to v3 rls.proto (envoyproxy#153)

Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>

* Followups to v3 upgrade (envoyproxy#155)

- Regenerate mocks based on new default protocol
- Manually transform v2 messages to v3 messages - some of the fields
were renamed thus json Marshal/Unmarshal does not work anymore
- Added tests that verify conversion v2<->v3 works for headers fields
- Update tests to use proto.Equal - simple assert.Equals might not
work correctly for protobuf messages.

Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>

* Introduce a Dockerfile for running integration tests (envoyproxy#156)

This diff creates Dockerfile.integration for running integration tests with clearly-defined dependencies. Previously the dependencies of the integration tests were defined within the github actions config.

The new "make docker_tests" target should work for any developer with Docker installed.

Previously there was no single command that would run integration tests across platforms, which makes development and onboarding harder. Even copying the command from github actions wouldn't have worked before, since that command quietly assumed that redis was already running on port 6379.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Add support for rate limit overrides. (envoyproxy#158)

Fixes envoyproxy#154

Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>

* redis client: default to use explicit pipelining (envoyproxy#163)

Signed-off-by: Tong Cai <caitong93@gmail.com>

* Clean go.mod file and update logrus to latest (envoyproxy#166)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Add full test environment example. Fix bug in existing docker-compose. (envoyproxy#170)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Implement LOG_FORMAT=json (envoyproxy#173)

Centralized log collection system works better with logs in json format.
E.g. DataDog strongly encourage setting up your logging library to produce your logs in JSON format to avoid the need for custom parsing rules.
So, the next small fix is all we need to get json logs.

Signed-off-by: Sergey Belyaev <sbelyaev@setronica.com>

* ci: Update github action to push docker image tagged with sha for each merge to master branch (envoyproxy#176)

Updates the github action to also push a tagged image based upon the git sha. The tag also
includes the current version of the release.

Example tag: envoyproxy/ratelimit:f1758150b6dfed3e5c0ae13fb7bb6b8f6ae00b0e

Fixes envoyproxy#174

Signed-off-by: Steve Sloka <slokas@vmware.com>

* Update README.md to refer to existing files (envoyproxy#178)

Signed-off-by: Margaret Gorguissian <margaret.gorguissian@tufts.edu>

* Add redis cluster and sentinel support (envoyproxy#179)

Signed-off-by: Diego Erdody <diego@medallia.com>

* Add support for x-ratelimit-reset header (envoyproxy#182)

Signed-off-by: Clara Andrew-Wani <candrewwani@gmail.com>

* Create repokitteh.star (envoyproxy#187)

Signed-off-by: Itay Donanhirsh <itay@bazoo.org>

* refactor NearLimitRatio to environment variable (envoyproxy#186)

Signed-off-by: zufardhiyaulhaq <zufardhiyaulhaq@gmail.com>

* Fix flakey tests with DurationUntilReset. Update docker example to V3 config. (envoyproxy#192)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Separate Redis cache and driver implementation (envoyproxy#194)

Signed-off-by: William Albertus Dembo <w.albertusd@gmail.com>

* Set ratelimit filter to v3 api (envoyproxy#196)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Add debug logging to indicate descriptor and limit (envoyproxy#197)

Signed-off-by: Sasha Kulbii <okulbii@wayfair.com>

* Implement BACKEND_TYPE=memcache as an alternative k/v store to redis (envoyproxy#172)

MEMCACHE_HOST_PORT=host:port must be set with BACKEND_TYPE=memcache

To minimize roundtrips when getting multiple keys, the memcache implementation
does a GetMulti to fetch the existing rate limit usage and does increments
asynchronously in background goroutines, since the memcache API doesn't offer
multi-increment.

Resolves envoyproxy#140

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Refactoring of duplicated code across backend types (envoyproxy#202)

Signed-off-by: Kateryna Nezdolii <nezdolik@spotify.com>

* Small typo fix in README (envoyproxy#204)

Signed-off-by: cpaika <paika.christopher@gmail.com>

* Circle CI (#1)

* Add Circle Config

* Touch to build

* Move to expected path

* Use Docker Command

* Do it all here then

* Env

* Add Readme

* Actual README

* Add Docker Compose (#2)

* VAULT-893 Fix docker-compose.yml

* VAULT-893 Fix docker-compose.yml

Co-authored-by: Marshall Jones <marshall@offby3.com>
Co-authored-by: Jose Ulises Nino Rivera <junr03@users.noreply.github.com>
Co-authored-by: Daniel Hochman <danielhochman@users.noreply.github.com>
Co-authored-by: Martien Verbruggen <martien.verbruggen@gmail.com>
Co-authored-by: Ben Pope <BenPope@users.noreply.github.com>
Co-authored-by: Steve Sloka <steve@stevesloka.com>
Co-authored-by: Matt Klein <mattklein123@gmail.com>
Co-authored-by: Charlie Vieth <charlie.vieth@gmail.com>
Co-authored-by: Adil Hafeez <ahafeez@lyft.com>
Co-authored-by: Kartograf <kartogrof@gmail.com>
Co-authored-by: repl-david-winiarski <33431229+repl-david-winiarski@users.noreply.github.com>
Co-authored-by: Junchao Lyu <6963707+freedomljc@users.noreply.github.com>
Co-authored-by: tangxinfa <tangxinfa@gmail.com>
Co-authored-by: Steve Sloka <slokas@vmware.com>
Co-authored-by: Matt Klein <mklein@lyft.com>
Co-authored-by: dblackdblack <github@dhb.is>
Co-authored-by: David Weitzman <dweitzman@pinterest.com>
Co-authored-by: Tong Cai <caitong@caicloud.io>
Co-authored-by: Yuki Sawa <yukisawa@gmail.com>
Co-authored-by: Petr Pchelko <petrpchelko@gmail.com>
Co-authored-by: Petr Pchelko <ppchelko@wikimedia.org>
Co-authored-by: Sergey Belyaev <svdba@users.noreply.github.com>
Co-authored-by: Margaret G <Margaret.Gorguissian@tufts.edu>
Co-authored-by: Diego Erdody <erdody@gmail.com>
Co-authored-by: Clara <candrewwani@gmail.com>
Co-authored-by: Itay Donanhirsh <itay@bazoo.org>
Co-authored-by: Zufar Dhiyaulhaq <zufardhiyaulhaq@gmail.com>
Co-authored-by: William Albertus Dembo <w.albertusd@gmail.com>
Co-authored-by: Alex Kulbii <jncneo@gmail.com>
Co-authored-by: Kateryna Nezdolii <nezdolik@spotify.com>
Co-authored-by: Christopher <paika.christopher@gmail.com>
zdmytriv pushed a commit to verygoodsecurity/ratelimit that referenced this pull request Jul 23, 2021
* Add Docker Compose File (#27)

* docs: match envoy docs for remote_address ratelimiting (#29)

* docs: document dependency on gostats (#30)

* test and document whitelist behavior (#31)

Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>

* update dependencies (#35)

* update dependencies

* proto: use the proto defined in data-plane-api (#39)

* proto: check in protos to allow importing ratelimit as a library (#40)

* docs: update contact info (#42)

* redis: add the option to use a separate redis pool for per second limits (#41)

* fix duplicate mv (#43)

* docker: upgrade docker-compose setup (#46)

* Add gRPC health check (#47)

* logging: set log level (#50)

* go version: update to 1.11 (#53)

* docker compose: expose gRPC port on docker compose setup (#55)

* Configuration to ignore dotfiles. (#52)

This allows ratelimit to run on Kubernetes with configuration from a configmap.

* Add Dockerfile to enable builds (#58)

Signed-off-by: Steve Sloka <steves@heptio.com>

* ci: fix build (#73)

Fixes envoyproxy#71

Signed-off-by: Matt Klein <mklein@lyft.com>

* Run unit and integration tests with race detector enabled (#65)

* deps: update several of ratelimit's dependencies (#76)

* add stalebot (#78)

Signed-off-by: Matt Klein <mklein@lyft.com>

* docs: fix example 4 sample config (#79)

* fix redis-server binary name (envoyproxy#88)

* Fix build Dockerfile (envoyproxy#98)

Fix problem:
src/service_cmd/runner/runner.go:10:2: cannot find package "github.com/lyft/ratelimit/proto/ratelimit" in any of:
        /usr/local/go/src/github.com/lyft/ratelimit/vendor/github.com/lyft/ratelimit/proto/ratelimit (vendor tree)
        /usr/local/go/src/vendor/github.com/lyft/ratelimit/proto/ratelimit
        /usr/local/go/src/github.com/lyft/ratelimit/proto/ratelimit (from $GOROOT)
        /go/src/github.com/lyft/ratelimit/proto/ratelimit (from $GOPATH)
The command '/bin/sh -c go build -o /usr/local/bin/ratelimit src/service_cmd/main.go' returned a non-zero code: 1

* Redis TLS and Auth support (envoyproxy#96)

This adds support for TLS connections to redis as well as support for authentication.
Somewhat related to issue #61

* healthcheck: allow customizable healthcheck name (envoyproxy#102)

Description: this patch allows a consumer of the server package to customize the name of the healthchecker.

Signed-off-by: Jose Nino <jnino@lyft.com>

* health: make a few more types public (envoyproxy#104)

Description: envoyproxy#102 allowed for some customization. This PR makes the types public so that other servers can use this implementation.

Signed-off-by: Jose Nino <jnino@lyft.com>

* Add local cache to store whether it is over the limit (envoyproxy#111)

* Plugin statstore into runner (envoyproxy#115)

* fix: support auth without tls (envoyproxy#116)

Signed-off-by: tangxinfa <tangxinfa@gmail.com>

* add local cache stats (envoyproxy#114)

* Move license to templated Apache-2.0 (envoyproxy#123)

Signed-off-by: Derek Schaller <d_a_schaller@yahoo.com>

* Enable go modules (envoyproxy#124)

Signed-off-by: Steve Sloka <slokas@vmware.com>

* CI: Github Actions (envoyproxy#127)

Signed-off-by: Steve Sloka <slokas@vmware.com>

* community: update contributing guide (envoyproxy#139)

Fixes envoyproxy#138

Signed-off-by: Matt Klein <mklein@lyft.com>

* add http 1 `/json` endpoint (envoyproxy#136)

Signed-off-by: David Black <david.black@autodesk.com>

* Use mockgen version from go.mod instead of from "make bootstrap" (envoyproxy#143)

Even though the Makefile wants to encourage using mockgen@1.4.1, it
seems like the mocks have been generated using a pre-1.0 version of
mockgen. Using "go run github.com/golang/mock/mockgen" as a go:generate
command instead of just "mockgen" avoids the need to pre-install into
the developer's $PATH and uses the go.mod-specified version

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Upgrade gostats dependency from 0.2.6 to 0.4.0 (envoyproxy#141)

My interest is the UDP protocol support which appeared in gotstats 0.3.10

There's a breaking change as of https://github.com/lyft/gostats/releases/tag/v0.3.0
which is that gostats no longer publishes stats as expvars.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Upgrade radix (envoyproxy#137)

Signed-off-by: Tong Cai <caitong93@gmail.com>

* cache_impl_test.go: fix failing test with ipv6 (envoyproxy#144)

A newly-added test in envoyproxy#137 checks the exact text of an error message which
seems to vary when the network is tcp4 vs tcp6. This change relaxes the
assertion to look for "connection refused" in a panic without making
assumptions about what an IP address looks like.

Example failure:

--- FAIL: TestNewClientImpl (0.00s)
    --- FAIL: TestNewClientImpl/connection_refused (0.00s)
        cache_impl_test.go:442:
                Error Trace:    cache_impl_test.go:442
                Error:          func (assert.PanicTestFunc)(0x1724110) should panic with error message: "dial tcp 127.0.0.1:12345: connect: connection refused"
                                        Panic value:    "dial tcp [::1]:12345: connect: connection refused"
                                        Panic stack:    goroutine 27 [running]:

The testify assert package doesn't seem to support inexact matching on error messages, so the code gets a bit uglier than before.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Split redis-specific logic from generic key-value store logic (envoyproxy#142)

This is a pure refactoring with no behavior changes. It's a step toward being able
to add memcache as a backend (see envoyproxy#140).

This PR moves RateLimitCache from the redis package to a new "limiter" package, along with
code for time/jitter, local cache stats,  and constructing cache keys. All that can be reused
with memcache.

After this PR, the redis package is imported in exactly two places:
- in service_cmd/runner/runner.go to call redis.NewRateLimiterCacheImplFromSettings()
- in service/ratelimit.go in ShouldRateLimit to identify if a recovered panic is a redis.RedisError. If so, a stat is incremented and the panic() propagation is ended and in favor of returning the error as a the function result.

The PR also includes changes by goimports to test/service/ratelimit_test.go
so that the difference between package name vs file path name is explicit
instead of implicit.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* json handler: return full ratelimit service response as json (envoyproxy#148)

Previously an HTTP POST to /json would only return an HTTP status code,
not all the other details supported by grpc ratelimit responses.

With this change an HTTP POST to /json receives the full proto3 response
encoded as json by jsonpb.

It seems unlikely that anyone would be parsing the text "over limit" from
the HTTP body instead of just reading the 429 response code, but for anyone
doing that this would be a breaking change.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Update goruntime to latest, 0.2.5.  Add new config for watching changes in runtime config folder directly instead of the runtime root dir. (envoyproxy#151)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Drop support for legacy ratelimit.proto and upgrade to v3 rls.proto (envoyproxy#153)

Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>

* Followups to v3 upgrade (envoyproxy#155)

- Regenerate mocks based on new default protocol
- Manually transform v2 messages to v3 messages - some of the fields
were renamed thus json Marshal/Unmarshal does not work anymore
- Added tests that verify conversion v2<->v3 works for headers fields
- Update tests to use proto.Equal - simple assert.Equals might not
work correctly for protobuf messages.

Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>

* Introduce a Dockerfile for running integration tests (envoyproxy#156)

This diff creates Dockerfile.integration for running integration tests with clearly-defined dependencies. Previously the dependencies of the integration tests were defined within the github actions config.

The new "make docker_tests" target should work for any developer with Docker installed.

Previously there was no single command that would run integration tests across platforms, which makes development and onboarding harder. Even copying the command from github actions wouldn't have worked before, since that command quietly assumed that redis was already running on port 6379.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Add support for rate limit overrides. (envoyproxy#158)

Fixes envoyproxy#154

Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>

* redis client: default to use explicit pipelining (envoyproxy#163)

Signed-off-by: Tong Cai <caitong93@gmail.com>

* Clean go.mod file and update logrus to latest (envoyproxy#166)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Add full test environment example. Fix bug in existing docker-compose. (envoyproxy#170)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Implement LOG_FORMAT=json (envoyproxy#173)

Centralized log collection system works better with logs in json format.
E.g. DataDog strongly encourage setting up your logging library to produce your logs in JSON format to avoid the need for custom parsing rules.
So, the next small fix is all we need to get json logs.

Signed-off-by: Sergey Belyaev <sbelyaev@setronica.com>

* ci: Update github action to push docker image tagged with sha for each merge to master branch (envoyproxy#176)

Updates the github action to also push a tagged image based upon the git sha. The tag also
includes the current version of the release.

Example tag: envoyproxy/ratelimit:f1758150b6dfed3e5c0ae13fb7bb6b8f6ae00b0e

Fixes envoyproxy#174

Signed-off-by: Steve Sloka <slokas@vmware.com>

* Update README.md to refer to existing files (envoyproxy#178)

Signed-off-by: Margaret Gorguissian <margaret.gorguissian@tufts.edu>

* Add redis cluster and sentinel support (envoyproxy#179)

Signed-off-by: Diego Erdody <diego@medallia.com>

* Add support for x-ratelimit-reset header (envoyproxy#182)

Signed-off-by: Clara Andrew-Wani <candrewwani@gmail.com>

* Create repokitteh.star (envoyproxy#187)

Signed-off-by: Itay Donanhirsh <itay@bazoo.org>

* refactor NearLimitRatio to environment variable (envoyproxy#186)

Signed-off-by: zufardhiyaulhaq <zufardhiyaulhaq@gmail.com>

* Fix flakey tests with DurationUntilReset. Update docker example to V3 config. (envoyproxy#192)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Separate Redis cache and driver implementation (envoyproxy#194)

Signed-off-by: William Albertus Dembo <w.albertusd@gmail.com>

* Set ratelimit filter to v3 api (envoyproxy#196)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Add debug logging to indicate descriptor and limit (envoyproxy#197)

Signed-off-by: Sasha Kulbii <okulbii@wayfair.com>

* Implement BACKEND_TYPE=memcache as an alternative k/v store to redis (envoyproxy#172)

MEMCACHE_HOST_PORT=host:port must be set with BACKEND_TYPE=memcache

To minimize roundtrips when getting multiple keys, the memcache implementation
does a GetMulti to fetch the existing rate limit usage and does increments
asynchronously in background goroutines, since the memcache API doesn't offer
multi-increment.

Resolves envoyproxy#140

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Refactoring of duplicated code across backend types (envoyproxy#202)

Signed-off-by: Kateryna Nezdolii <nezdolik@spotify.com>

* Small typo fix in README (envoyproxy#204)

Signed-off-by: cpaika <paika.christopher@gmail.com>

* Circle CI (#1)

* Add Circle Config

* Touch to build

* Move to expected path

* Use Docker Command

* Do it all here then

* Env

* Add Readme

* Actual README

* Add Docker Compose (#2)

* VAULT-893 Fix docker-compose.yml

* VAULT-893 Fix docker-compose.yml

Co-authored-by: Marshall Jones <marshall@offby3.com>
Co-authored-by: Jose Ulises Nino Rivera <junr03@users.noreply.github.com>
Co-authored-by: Daniel Hochman <danielhochman@users.noreply.github.com>
Co-authored-by: Martien Verbruggen <martien.verbruggen@gmail.com>
Co-authored-by: Ben Pope <BenPope@users.noreply.github.com>
Co-authored-by: Steve Sloka <steve@stevesloka.com>
Co-authored-by: Matt Klein <mattklein123@gmail.com>
Co-authored-by: Charlie Vieth <charlie.vieth@gmail.com>
Co-authored-by: Adil Hafeez <ahafeez@lyft.com>
Co-authored-by: Kartograf <kartogrof@gmail.com>
Co-authored-by: repl-david-winiarski <33431229+repl-david-winiarski@users.noreply.github.com>
Co-authored-by: Junchao Lyu <6963707+freedomljc@users.noreply.github.com>
Co-authored-by: tangxinfa <tangxinfa@gmail.com>
Co-authored-by: Steve Sloka <slokas@vmware.com>
Co-authored-by: Matt Klein <mklein@lyft.com>
Co-authored-by: dblackdblack <github@dhb.is>
Co-authored-by: David Weitzman <dweitzman@pinterest.com>
Co-authored-by: Tong Cai <caitong@caicloud.io>
Co-authored-by: Yuki Sawa <yukisawa@gmail.com>
Co-authored-by: Petr Pchelko <petrpchelko@gmail.com>
Co-authored-by: Petr Pchelko <ppchelko@wikimedia.org>
Co-authored-by: Sergey Belyaev <svdba@users.noreply.github.com>
Co-authored-by: Margaret G <Margaret.Gorguissian@tufts.edu>
Co-authored-by: Diego Erdody <erdody@gmail.com>
Co-authored-by: Clara <candrewwani@gmail.com>
Co-authored-by: Itay Donanhirsh <itay@bazoo.org>
Co-authored-by: Zufar Dhiyaulhaq <zufardhiyaulhaq@gmail.com>
Co-authored-by: William Albertus Dembo <w.albertusd@gmail.com>
Co-authored-by: Alex Kulbii <jncneo@gmail.com>
Co-authored-by: Kateryna Nezdolii <nezdolik@spotify.com>
Co-authored-by: Christopher <paika.christopher@gmail.com>
zdmytriv pushed a commit to verygoodsecurity/ratelimit that referenced this pull request Aug 2, 2021
* Add Docker Compose File (#27)

* docs: match envoy docs for remote_address ratelimiting (#29)

* docs: document dependency on gostats (#30)

* test and document whitelist behavior (#31)

Signed-off-by: Daniel Hochman <danielhochman@users.noreply.github.com>

* update dependencies (#35)

* update dependencies

* proto: use the proto defined in data-plane-api (#39)

* proto: check in protos to allow importing ratelimit as a library (#40)

* docs: update contact info (#42)

* redis: add the option to use a separate redis pool for per second limits (#41)

* fix duplicate mv (#43)

* docker: upgrade docker-compose setup (#46)

* Add gRPC health check (#47)

* logging: set log level (#50)

* go version: update to 1.11 (#53)

* docker compose: expose gRPC port on docker compose setup (#55)

* Configuration to ignore dotfiles. (#52)

This allows ratelimit to run on Kubernetes with configuration from a configmap.

* Add Dockerfile to enable builds (#58)

Signed-off-by: Steve Sloka <steves@heptio.com>

* ci: fix build (#73)

Fixes envoyproxy#71

Signed-off-by: Matt Klein <mklein@lyft.com>

* Run unit and integration tests with race detector enabled (#65)

* deps: update several of ratelimit's dependencies (#76)

* add stalebot (#78)

Signed-off-by: Matt Klein <mklein@lyft.com>

* docs: fix example 4 sample config (#79)

* fix redis-server binary name (envoyproxy#88)

* Fix build Dockerfile (envoyproxy#98)

Fix problem:
src/service_cmd/runner/runner.go:10:2: cannot find package "github.com/lyft/ratelimit/proto/ratelimit" in any of:
        /usr/local/go/src/github.com/lyft/ratelimit/vendor/github.com/lyft/ratelimit/proto/ratelimit (vendor tree)
        /usr/local/go/src/vendor/github.com/lyft/ratelimit/proto/ratelimit
        /usr/local/go/src/github.com/lyft/ratelimit/proto/ratelimit (from $GOROOT)
        /go/src/github.com/lyft/ratelimit/proto/ratelimit (from $GOPATH)
The command '/bin/sh -c go build -o /usr/local/bin/ratelimit src/service_cmd/main.go' returned a non-zero code: 1

* Redis TLS and Auth support (envoyproxy#96)

This adds support for TLS connections to redis as well as support for authentication.
Somewhat related to issue #61

* healthcheck: allow customizable healthcheck name (envoyproxy#102)

Description: this patch allows a consumer of the server package to customize the name of the healthchecker.

Signed-off-by: Jose Nino <jnino@lyft.com>

* health: make a few more types public (envoyproxy#104)

Description: envoyproxy#102 allowed for some customization. This PR makes the types public so that other servers can use this implementation.

Signed-off-by: Jose Nino <jnino@lyft.com>

* Add local cache to store whether it is over the limit (envoyproxy#111)

* Plugin statstore into runner (envoyproxy#115)

* fix: support auth without tls (envoyproxy#116)

Signed-off-by: tangxinfa <tangxinfa@gmail.com>

* add local cache stats (envoyproxy#114)

* Move license to templated Apache-2.0 (envoyproxy#123)

Signed-off-by: Derek Schaller <d_a_schaller@yahoo.com>

* Enable go modules (envoyproxy#124)

Signed-off-by: Steve Sloka <slokas@vmware.com>

* CI: Github Actions (envoyproxy#127)

Signed-off-by: Steve Sloka <slokas@vmware.com>

* community: update contributing guide (envoyproxy#139)

Fixes envoyproxy#138

Signed-off-by: Matt Klein <mklein@lyft.com>

* add http 1 `/json` endpoint (envoyproxy#136)

Signed-off-by: David Black <david.black@autodesk.com>

* Use mockgen version from go.mod instead of from "make bootstrap" (envoyproxy#143)

Even though the Makefile wants to encourage using mockgen@1.4.1, it
seems like the mocks have been generated using a pre-1.0 version of
mockgen. Using "go run github.com/golang/mock/mockgen" as a go:generate
command instead of just "mockgen" avoids the need to pre-install into
the developer's $PATH and uses the go.mod-specified version

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Upgrade gostats dependency from 0.2.6 to 0.4.0 (envoyproxy#141)

My interest is the UDP protocol support which appeared in gotstats 0.3.10

There's a breaking change as of https://github.com/lyft/gostats/releases/tag/v0.3.0
which is that gostats no longer publishes stats as expvars.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Upgrade radix (envoyproxy#137)

Signed-off-by: Tong Cai <caitong93@gmail.com>

* cache_impl_test.go: fix failing test with ipv6 (envoyproxy#144)

A newly-added test in envoyproxy#137 checks the exact text of an error message which
seems to vary when the network is tcp4 vs tcp6. This change relaxes the
assertion to look for "connection refused" in a panic without making
assumptions about what an IP address looks like.

Example failure:

--- FAIL: TestNewClientImpl (0.00s)
    --- FAIL: TestNewClientImpl/connection_refused (0.00s)
        cache_impl_test.go:442:
                Error Trace:    cache_impl_test.go:442
                Error:          func (assert.PanicTestFunc)(0x1724110) should panic with error message: "dial tcp 127.0.0.1:12345: connect: connection refused"
                                        Panic value:    "dial tcp [::1]:12345: connect: connection refused"
                                        Panic stack:    goroutine 27 [running]:

The testify assert package doesn't seem to support inexact matching on error messages, so the code gets a bit uglier than before.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Split redis-specific logic from generic key-value store logic (envoyproxy#142)

This is a pure refactoring with no behavior changes. It's a step toward being able
to add memcache as a backend (see envoyproxy#140).

This PR moves RateLimitCache from the redis package to a new "limiter" package, along with
code for time/jitter, local cache stats,  and constructing cache keys. All that can be reused
with memcache.

After this PR, the redis package is imported in exactly two places:
- in service_cmd/runner/runner.go to call redis.NewRateLimiterCacheImplFromSettings()
- in service/ratelimit.go in ShouldRateLimit to identify if a recovered panic is a redis.RedisError. If so, a stat is incremented and the panic() propagation is ended and in favor of returning the error as a the function result.

The PR also includes changes by goimports to test/service/ratelimit_test.go
so that the difference between package name vs file path name is explicit
instead of implicit.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* json handler: return full ratelimit service response as json (envoyproxy#148)

Previously an HTTP POST to /json would only return an HTTP status code,
not all the other details supported by grpc ratelimit responses.

With this change an HTTP POST to /json receives the full proto3 response
encoded as json by jsonpb.

It seems unlikely that anyone would be parsing the text "over limit" from
the HTTP body instead of just reading the 429 response code, but for anyone
doing that this would be a breaking change.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Update goruntime to latest, 0.2.5.  Add new config for watching changes in runtime config folder directly instead of the runtime root dir. (envoyproxy#151)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Drop support for legacy ratelimit.proto and upgrade to v3 rls.proto (envoyproxy#153)

Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>

* Followups to v3 upgrade (envoyproxy#155)

- Regenerate mocks based on new default protocol
- Manually transform v2 messages to v3 messages - some of the fields
were renamed thus json Marshal/Unmarshal does not work anymore
- Added tests that verify conversion v2<->v3 works for headers fields
- Update tests to use proto.Equal - simple assert.Equals might not
work correctly for protobuf messages.

Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>

* Introduce a Dockerfile for running integration tests (envoyproxy#156)

This diff creates Dockerfile.integration for running integration tests with clearly-defined dependencies. Previously the dependencies of the integration tests were defined within the github actions config.

The new "make docker_tests" target should work for any developer with Docker installed.

Previously there was no single command that would run integration tests across platforms, which makes development and onboarding harder. Even copying the command from github actions wouldn't have worked before, since that command quietly assumed that redis was already running on port 6379.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Add support for rate limit overrides. (envoyproxy#158)

Fixes envoyproxy#154

Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>

* redis client: default to use explicit pipelining (envoyproxy#163)

Signed-off-by: Tong Cai <caitong93@gmail.com>

* Clean go.mod file and update logrus to latest (envoyproxy#166)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Add full test environment example. Fix bug in existing docker-compose. (envoyproxy#170)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Implement LOG_FORMAT=json (envoyproxy#173)

Centralized log collection system works better with logs in json format.
E.g. DataDog strongly encourage setting up your logging library to produce your logs in JSON format to avoid the need for custom parsing rules.
So, the next small fix is all we need to get json logs.

Signed-off-by: Sergey Belyaev <sbelyaev@setronica.com>

* ci: Update github action to push docker image tagged with sha for each merge to master branch (envoyproxy#176)

Updates the github action to also push a tagged image based upon the git sha. The tag also
includes the current version of the release.

Example tag: envoyproxy/ratelimit:f1758150b6dfed3e5c0ae13fb7bb6b8f6ae00b0e

Fixes envoyproxy#174

Signed-off-by: Steve Sloka <slokas@vmware.com>

* Update README.md to refer to existing files (envoyproxy#178)

Signed-off-by: Margaret Gorguissian <margaret.gorguissian@tufts.edu>

* Add redis cluster and sentinel support (envoyproxy#179)

Signed-off-by: Diego Erdody <diego@medallia.com>

* Add support for x-ratelimit-reset header (envoyproxy#182)

Signed-off-by: Clara Andrew-Wani <candrewwani@gmail.com>

* Create repokitteh.star (envoyproxy#187)

Signed-off-by: Itay Donanhirsh <itay@bazoo.org>

* refactor NearLimitRatio to environment variable (envoyproxy#186)

Signed-off-by: zufardhiyaulhaq <zufardhiyaulhaq@gmail.com>

* Fix flakey tests with DurationUntilReset. Update docker example to V3 config. (envoyproxy#192)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Separate Redis cache and driver implementation (envoyproxy#194)

Signed-off-by: William Albertus Dembo <w.albertusd@gmail.com>

* Set ratelimit filter to v3 api (envoyproxy#196)

Signed-off-by: Yuki Sawa <yukisawa@gmail.com>

* Add debug logging to indicate descriptor and limit (envoyproxy#197)

Signed-off-by: Sasha Kulbii <okulbii@wayfair.com>

* Implement BACKEND_TYPE=memcache as an alternative k/v store to redis (envoyproxy#172)

MEMCACHE_HOST_PORT=host:port must be set with BACKEND_TYPE=memcache

To minimize roundtrips when getting multiple keys, the memcache implementation
does a GetMulti to fetch the existing rate limit usage and does increments
asynchronously in background goroutines, since the memcache API doesn't offer
multi-increment.

Resolves envoyproxy#140

Signed-off-by: David Weitzman <dweitzman@pinterest.com>

* Refactoring of duplicated code across backend types (envoyproxy#202)

Signed-off-by: Kateryna Nezdolii <nezdolik@spotify.com>

* Small typo fix in README (envoyproxy#204)

Signed-off-by: cpaika <paika.christopher@gmail.com>

* Circle CI (#1)

* Add Circle Config

* Touch to build

* Move to expected path

* Use Docker Command

* Do it all here then

* Env

* Add Readme

* Actual README

* Add Docker Compose (#2)

* VAULT-893 Fix docker-compose.yml

* VAULT-893 Fix docker-compose.yml

Co-authored-by: Marshall Jones <marshall@offby3.com>
Co-authored-by: Jose Ulises Nino Rivera <junr03@users.noreply.github.com>
Co-authored-by: Daniel Hochman <danielhochman@users.noreply.github.com>
Co-authored-by: Martien Verbruggen <martien.verbruggen@gmail.com>
Co-authored-by: Ben Pope <BenPope@users.noreply.github.com>
Co-authored-by: Steve Sloka <steve@stevesloka.com>
Co-authored-by: Matt Klein <mattklein123@gmail.com>
Co-authored-by: Charlie Vieth <charlie.vieth@gmail.com>
Co-authored-by: Adil Hafeez <ahafeez@lyft.com>
Co-authored-by: Kartograf <kartogrof@gmail.com>
Co-authored-by: repl-david-winiarski <33431229+repl-david-winiarski@users.noreply.github.com>
Co-authored-by: Junchao Lyu <6963707+freedomljc@users.noreply.github.com>
Co-authored-by: tangxinfa <tangxinfa@gmail.com>
Co-authored-by: Steve Sloka <slokas@vmware.com>
Co-authored-by: Matt Klein <mklein@lyft.com>
Co-authored-by: dblackdblack <github@dhb.is>
Co-authored-by: David Weitzman <dweitzman@pinterest.com>
Co-authored-by: Tong Cai <caitong@caicloud.io>
Co-authored-by: Yuki Sawa <yukisawa@gmail.com>
Co-authored-by: Petr Pchelko <petrpchelko@gmail.com>
Co-authored-by: Petr Pchelko <ppchelko@wikimedia.org>
Co-authored-by: Sergey Belyaev <svdba@users.noreply.github.com>
Co-authored-by: Margaret G <Margaret.Gorguissian@tufts.edu>
Co-authored-by: Diego Erdody <erdody@gmail.com>
Co-authored-by: Clara <candrewwani@gmail.com>
Co-authored-by: Itay Donanhirsh <itay@bazoo.org>
Co-authored-by: Zufar Dhiyaulhaq <zufardhiyaulhaq@gmail.com>
Co-authored-by: William Albertus Dembo <w.albertusd@gmail.com>
Co-authored-by: Alex Kulbii <jncneo@gmail.com>
Co-authored-by: Kateryna Nezdolii <nezdolik@spotify.com>
Co-authored-by: Christopher <paika.christopher@gmail.com>
timcovar pushed a commit to goatapp/ratelimit that referenced this pull request Jan 16, 2024
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