-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Request Limiter reloadable config #25095
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
limits: Introduce a reloadable disable configuration for the Request Limiter. | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package configutil | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/go-multierror" | ||
"github.com/hashicorp/go-secure-stdlib/parseutil" | ||
"github.com/hashicorp/hcl" | ||
"github.com/hashicorp/hcl/hcl/ast" | ||
) | ||
|
||
type RequestLimiter struct { | ||
UnusedKeys UnusedKeyMap `hcl:",unusedKeyPositions"` | ||
|
||
Disable bool `hcl:"-"` | ||
DisableRaw interface{} `hcl:"disable"` | ||
} | ||
|
||
func (r *RequestLimiter) Validate(source string) []ConfigError { | ||
return ValidateUnusedFields(r.UnusedKeys, source) | ||
} | ||
|
||
func (r *RequestLimiter) GoString() string { | ||
return fmt.Sprintf("*%#v", *r) | ||
} | ||
|
||
var DefaultRequestLimiter = &RequestLimiter{ | ||
Disable: false, | ||
} | ||
|
||
func parseRequestLimiter(result *SharedConfig, list *ast.ObjectList) error { | ||
if len(list.Items) > 1 { | ||
return fmt.Errorf("only one 'request_limiter' block is permitted") | ||
} | ||
|
||
result.RequestLimiter = DefaultRequestLimiter | ||
|
||
// Get our one item | ||
item := list.Items[0] | ||
|
||
if err := hcl.DecodeObject(&result.RequestLimiter, item.Val); err != nil { | ||
return multierror.Prefix(err, "request_limiter:") | ||
} | ||
|
||
if result.RequestLimiter.DisableRaw != nil { | ||
var err error | ||
if result.RequestLimiter.Disable, err = parseutil.ParseBool(result.RequestLimiter.DisableRaw); err != nil { | ||
return err | ||
} | ||
result.RequestLimiter.DisableRaw = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a common pattern, setting it to nil after parsing it? I haven't seen that before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, for some reason we clear the raw entry after parsing. I'm not sure I understand it, but copied it from other implementations. |
||
} else { | ||
result.RequestLimiter.Disable = false | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for tests? Truthfully not sure, but other configs used this so I followed suit.