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 debug logging to indicate descriptor and limit #197

Merged
merged 2 commits into from
Nov 30, 2020
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
22 changes: 22 additions & 0 deletions src/service/ratelimit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ratelimit

import (
"fmt"
"strings"
"sync"

Expand Down Expand Up @@ -113,7 +114,28 @@ func (this *service) shouldRateLimitWorker(

limitsToCheck := make([]*config.RateLimit, len(request.Descriptors))
for i, descriptor := range request.Descriptors {
if logger.IsLevelEnabled(logger.DebugLevel) {
var descriptorEntryStrings []string
for _, descriptorEntry := range descriptor.GetEntries() {
descriptorEntryStrings = append(
descriptorEntryStrings,
fmt.Sprintf("(%s=%s)", descriptorEntry.Key, descriptorEntry.Value),
)
}
logger.Debugf("got descriptor: %s", strings.Join(descriptorEntryStrings, ","))
}
limitsToCheck[i] = snappedConfig.GetLimit(ctx, request.Domain, descriptor)
if logger.IsLevelEnabled(logger.DebugLevel) {
if limitsToCheck[i] == nil {
logger.Debugf("descriptor does not match any limit, no limits applied")
} else {
logger.Debugf(
"applying limit: %d requests per %s",
limitsToCheck[i].Limit.RequestsPerUnit,
limitsToCheck[i].Limit.Unit.String(),
)
}
}
}

responseDescriptorStatuses := this.cache.DoLimit(ctx, request, limitsToCheck)
Expand Down