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

Backport of fix rate limit tests flakiness into release/1.15.x #16357

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions test/integration/consul-container/test/ratelimit/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestServerRequestRateLimit(t *testing.T) {
description string
cmd string
operations []operation
mode string
}

getKV := action{
Expand All @@ -70,6 +71,7 @@ func TestServerRequestRateLimit(t *testing.T) {
{
description: "HTTP & net/RPC / Mode: disabled - errors: no / exceeded logs: no / metrics: no",
cmd: `-hcl=limits { request_limits { mode = "disabled" read_rate = 0 write_rate = 0 }}`,
mode: "disabled",
operations: []operation{
{
action: putKV,
Expand All @@ -88,6 +90,7 @@ func TestServerRequestRateLimit(t *testing.T) {
{
description: "HTTP & net/RPC / Mode: permissive - errors: no / exceeded logs: yes / metrics: yes",
cmd: `-hcl=limits { request_limits { mode = "permissive" read_rate = 0 write_rate = 0 }}`,
mode: "permissive",
operations: []operation{
{
action: putKV,
Expand All @@ -106,6 +109,7 @@ func TestServerRequestRateLimit(t *testing.T) {
{
description: "HTTP & net/RPC / Mode: enforcing - errors: yes / exceeded logs: yes / metrics: yes",
cmd: `-hcl=limits { request_limits { mode = "enforcing" read_rate = 0 write_rate = 0 }}`,
mode: "enforcing",
operations: []operation{
{
action: putKV,
Expand Down Expand Up @@ -154,7 +158,7 @@ func TestServerRequestRateLimit(t *testing.T) {
// require.NoError(t, err)
if metricsInfo != nil && err == nil {
if op.expectMetric {
checkForMetric(r, metricsInfo, op.action.rateLimitOperation, op.action.rateLimitType)
checkForMetric(r, metricsInfo, op.action.rateLimitOperation, op.action.rateLimitType, tc.mode)
}
}

Expand All @@ -171,17 +175,17 @@ func TestServerRequestRateLimit(t *testing.T) {
}
}

func checkForMetric(t *retry.R, metricsInfo *api.MetricsInfo, operationName string, expectedLimitType string) {
const counterName = "rpc.rate_limit.exceeded"
func checkForMetric(t *retry.R, metricsInfo *api.MetricsInfo, operationName string, expectedLimitType string, expectedMode string) {
const counterName = "consul.rpc.rate_limit.exceeded"

var counter api.SampledValue
for _, c := range metricsInfo.Counters {
if counter.Name == counterName {
if c.Name == counterName {
counter = c
break
}
}
require.NotNilf(t, counter, "counter not found: %s", counterName)
require.NotEmptyf(t, counter.Name, "counter not found: %s", counterName)

operation, ok := counter.Labels["op"]
require.True(t, ok)
Expand All @@ -193,9 +197,9 @@ func checkForMetric(t *retry.R, metricsInfo *api.MetricsInfo, operationName stri
require.True(t, ok)

if operation == operationName {
require.Equal(t, 2, counter.Count)
require.GreaterOrEqual(t, counter.Count, 1)
require.Equal(t, expectedLimitType, limitType)
require.Equal(t, "disabled", mode)
require.Equal(t, expectedMode, mode)
}
}

Expand Down