Skip to content

Commit

Permalink
naming
Browse files Browse the repository at this point in the history
  • Loading branch information
jalvz committed Oct 7, 2019
1 parent 1ee3a7f commit 0788847
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion beater/api/config/agent/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Handler(kbClient kibana.Client, config *config.AgentConfig) request.Handler
// error handling
c.Header().Set(headers.CacheControl, errCacheControl)

ok := c.IPRateLimiter == nil || c.IPRateLimiter.Allow()
ok := c.RateLimiter == nil || c.RateLimiter.Allow()
if !ok {
c.Result.SetDefault(request.IDResponseErrorsRateLimit)
c.Write()
Expand Down
2 changes: 1 addition & 1 deletion beater/api/config/agent/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func TestAgentConfigRateLimit(t *testing.T) {
ctx := &request.Context{}
ctx.Reset(w, r)
ctx.IsRum = true
ctx.IPRateLimiter = rate.NewLimiter(rate.Limit(0), 0)
ctx.RateLimiter = rate.NewLimiter(rate.Limit(0), 0)
h(ctx)
var actual map[string]string
json.Unmarshal(w.Body.Bytes(), &actual)
Expand Down
4 changes: 2 additions & 2 deletions beater/api/intake/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Handler(dec decoder.ReqDecoder, processor *stream.Processor, report publish
return
}

ok := c.IPRateLimiter == nil || c.IPRateLimiter.Allow()
ok := c.RateLimiter == nil || c.RateLimiter.Allow()
if !ok {
sendError(c, &stream.Error{
Type: stream.RateLimitErrType, Message: "rate limit exceeded"})
Expand All @@ -71,7 +71,7 @@ func Handler(dec decoder.ReqDecoder, processor *stream.Processor, report publish
sendResponse(c, &sr)
return
}
res := processor.HandleStream(c.Request.Context(), c.IPRateLimiter, reqMeta, reader, report)
res := processor.HandleStream(c.Request.Context(), c.RateLimiter, reqMeta, reader, report)

sendResponse(c, res)
}
Expand Down
2 changes: 1 addition & 1 deletion beater/api/intake/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestIntakeHandler(t *testing.T) {
tc.setup(t)

if tc.rateLimit != nil {
tc.c.IPRateLimiter = tc.rateLimit.ForIP(&http.Request{})
tc.c.RateLimiter = tc.rateLimit.ForIP(&http.Request{})
}
// call handler
h := Handler(tc.dec, tc.processor, tc.reporter)
Expand Down
2 changes: 1 addition & 1 deletion beater/api/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func backendMiddleware(cfg *config.Config, m map[request.ResultID]*monitoring.In
func rumMiddleware(cfg *config.Config, m map[request.ResultID]*monitoring.Int) []middleware.Middleware {
return append(apmMiddleware(m),
middleware.SetRumFlagMiddleware(),
middleware.SetRateLimitMiddleware(cfg.RumConfig.EventRate),
middleware.SetIPRateLimitMiddleware(cfg.RumConfig.EventRate),
middleware.CORSMiddleware(cfg.RumConfig.AllowOrigins),
middleware.KillSwitchMiddleware(cfg.RumConfig.IsEnabled()))
}
Expand Down
6 changes: 3 additions & 3 deletions beater/middleware/rate_limit_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (

const burstMultiplier = 3

// SetRateLimitMiddleware sets a rate limiter
func SetRateLimitMiddleware(cfg *config.EventRate) Middleware {
// SetIPRateLimitMiddleware sets a rate limiter
func SetIPRateLimitMiddleware(cfg *config.EventRate) Middleware {
store, err := ratelimit.NewStore(cfg.LruSize, cfg.Limit, burstMultiplier)

return func(h request.Handler) (request.Handler, error) {
return func(c *request.Context) {
c.IPRateLimiter = store.ForIP(c.Request)
c.RateLimiter = store.ForIP(c.Request)
h(c)
}, err
}
Expand Down
4 changes: 2 additions & 2 deletions beater/request/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
type Context struct {
Request *http.Request
Logger *logp.Logger
IPRateLimiter *rate.Limiter
RateLimiter *rate.Limiter
TokenSet bool
Authorized bool
IsRum bool
Expand All @@ -58,7 +58,7 @@ func (c *Context) Reset(w http.ResponseWriter, r *http.Request) {
c.TokenSet = false
c.Authorized = false
c.IsRum = false
c.IPRateLimiter = nil
c.RateLimiter = nil
c.Result.Reset()
c.w = w
c.writeAttempts = 0
Expand Down

0 comments on commit 0788847

Please sign in to comment.