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

Remove support for legacy v2 api #278

Merged
merged 13 commits into from
Aug 3, 2021
Prev Previous commit
Next Next commit
delete legacy int tests
Signed-off-by: Yuki Sawa <yukisawa@gmail.com>
ysawa0 committed Aug 3, 2021
commit 37bb8fc4b5a7c93ac4980a21da4374c260453e7b
113 changes: 0 additions & 113 deletions test/integration/integration_test.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ import (
"testing"
"time"

pb_legacy "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2"
pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3"
"github.com/envoyproxy/ratelimit/src/memcached"
"github.com/envoyproxy/ratelimit/src/service_cmd/runner"
@@ -64,17 +63,6 @@ func newDescriptorStatus(status pb.RateLimitResponse_Code, requestsPerUnit uint3
}
}

func newDescriptorStatusLegacy(
status pb_legacy.RateLimitResponse_Code, requestsPerUnit uint32,
unit pb_legacy.RateLimitResponse_RateLimit_Unit, limitRemaining uint32) *pb_legacy.RateLimitResponse_DescriptorStatus {

return &pb_legacy.RateLimitResponse_DescriptorStatus{
Code: status,
CurrentLimit: &pb_legacy.RateLimitResponse_RateLimit{RequestsPerUnit: requestsPerUnit, Unit: unit},
LimitRemaining: limitRemaining,
}
}

func makeSimpleRedisSettings(redisPort int, perSecondPort int, perSecond bool, localCacheSize int) settings.Settings {
s := defaultSettings()

@@ -600,107 +588,6 @@ func testBasicBaseConfig(s settings.Settings) func(*testing.T) {
}
}

func TestBasicConfigLegacy(t *testing.T) {
common.WithMultiRedis(t, []common.RedisConfig{
{Port: 6383},
}, func() {
testBasicConfigLegacy(t)
})
}

func testBasicConfigLegacy(t *testing.T) {
s := makeSimpleRedisSettings(6383, 6380, false, 0)

runner := startTestRunner(t, s)
defer runner.Stop()

assert := assert.New(t)
conn, err := grpc.Dial("localhost:8083", grpc.WithInsecure())

assert.NoError(err)
defer conn.Close()
c := pb_legacy.NewRateLimitServiceClient(conn)

_, err := c.ShouldRateLimit(
context.Background(),
common.NewRateLimitRequestLegacy("foo", [][][2]string{{{"hello", "world"}}}, 1))
//common.AssertProtoEqual(
// assert,
// &pb_legacy.RateLimitResponse{
// OverallCode: pb_legacy.RateLimitResponse_OK,
// Statuses: []*pb_legacy.RateLimitResponse_DescriptorStatus{{Code: pb_legacy.RateLimitResponse_OK, CurrentLimit: nil, LimitRemaining: 0}}},
// response)
assert.Error(err)

_, err = c.ShouldRateLimit(
context.Background(),
common.NewRateLimitRequestLegacy("basic_legacy", [][][2]string{{{"key1", "foo"}}}, 1))
//common.AssertProtoEqual(
// assert,
// &pb_legacy.RateLimitResponse{
// OverallCode: pb_legacy.RateLimitResponse_OK,
// Statuses: []*pb_legacy.RateLimitResponse_DescriptorStatus{
// newDescriptorStatusLegacy(pb_legacy.RateLimitResponse_OK, 50, pb_legacy.RateLimitResponse_RateLimit_SECOND, 49)}},
// response)
assert.Error(err)

// Now come up with a random key, and go over limit for a minute limit which should always work.
r := rand.New(rand.NewSource(time.Now().UnixNano()))
randomInt := r.Int()
for i := 0; i < 25; i++ {
_, err = c.ShouldRateLimit(
context.Background(),
common.NewRateLimitRequestLegacy(
"another", [][][2]string{{{"key2", strconv.Itoa(randomInt)}}}, 1))

status := pb_legacy.RateLimitResponse_OK
limitRemaining := uint32(20 - (i + 1))
if i >= 20 {
status = pb_legacy.RateLimitResponse_OVER_LIMIT
limitRemaining = 0
}

//common.AssertProtoEqual(
// assert,
// &pb_legacy.RateLimitResponse{
// OverallCode: status,
// Statuses: []*pb_legacy.RateLimitResponse_DescriptorStatus{
// newDescriptorStatusLegacy(status, 20, pb_legacy.RateLimitResponse_RateLimit_MINUTE, limitRemaining)}},
// response)
assert.Error(err)
}

// Limit now against 2 keys in the same domain.
randomInt = r.Int()
for i := 0; i < 15; i++ {
_, err = c.ShouldRateLimit(
context.Background(),
common.NewRateLimitRequestLegacy(
"another_legacy",
[][][2]string{
{{"key2", strconv.Itoa(randomInt)}},
{{"key3", strconv.Itoa(randomInt)}}}, 1))

status := pb_legacy.RateLimitResponse_OK
limitRemaining1 := uint32(20 - (i + 1))
limitRemaining2 := uint32(10 - (i + 1))
if i >= 10 {
status = pb_legacy.RateLimitResponse_OVER_LIMIT
limitRemaining2 = 0
}

//common.AssertProtoEqual(
// assert,
// &pb_legacy.RateLimitResponse{
// OverallCode: status,
// Statuses: []*pb_legacy.RateLimitResponse_DescriptorStatus{
// newDescriptorStatusLegacy(pb_legacy.RateLimitResponse_OK, 20, pb_legacy.RateLimitResponse_RateLimit_MINUTE, limitRemaining1),
// newDescriptorStatusLegacy(status, 10, pb_legacy.RateLimitResponse_RateLimit_HOUR, limitRemaining2)}},
// response)
assert.Error(err)
}
}

func startTestRunner(t *testing.T, s settings.Settings) *runner.Runner {
t.Helper()
runner := runner.NewRunner(s)