-
Notifications
You must be signed in to change notification settings - Fork 823
Support memcached max_item_size #3929
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
Support memcached max_item_size #3929
Conversation
@@ -183,6 +189,11 @@ func (c *memcachedClient) Stop() { | |||
} | |||
|
|||
func (c *memcachedClient) Set(item *memcache.Item) error { | |||
// Skip hitting memcached at all if the item is bigger than the max allowed size. | |||
if c.maxItemSize > 0 && uint64(len(item.Value)) > uint64(c.maxItemSize) { | |||
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.
Please let me know if you think it would be better to have a counter metric for this like thanos
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.
I would appreciate a metric similar to Thanos.
Signed-off-by: yeya24 <yb532204897@gmail.com>
396879c
to
ff0a498
Compare
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.
LGTM, thanks! I left a couple of comments that should be quick to address.
pkg/chunk/cache/memcached_client.go
Outdated
@@ -86,6 +90,7 @@ func (cfg *MemcachedClientConfig) RegisterFlagsWithPrefix(prefix, description st | |||
f.UintVar(&cfg.CBFailures, prefix+"memcached.circuit-breaker-consecutive-failures", 10, description+"Trip circuit-breaker after this number of consecutive dial failures (if zero then circuit-breaker is disabled).") | |||
f.DurationVar(&cfg.CBTimeout, prefix+"memcached.circuit-breaker-timeout", 10*time.Second, description+"Duration circuit-breaker remains open after tripping (if zero then 60 seconds is used).") | |||
f.DurationVar(&cfg.CBInterval, prefix+"memcached.circuit-breaker-interval", 10*time.Second, description+"Reset circuit-breaker counts after this long (if zero then never reset).") | |||
f.IntVar(&cfg.MaxItemSize, prefix+"memcached.max-item-size", 1024*1024, description+"The maximum size of an item stored in memcached. Bigger items are not stored. If set to 0, no maximum size is enforced.") |
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.
I would default it to 0, otherwise it's a "breaking change".
pkg/chunk/cache/memcached_client.go
Outdated
@@ -52,6 +53,8 @@ type memcachedClient struct { | |||
cbTimeout time.Duration | |||
cbInterval time.Duration | |||
|
|||
maxItemSize model.Bytes |
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.
No need to use model.Bytes
. You can just use an int.
@@ -183,6 +189,11 @@ func (c *memcachedClient) Stop() { | |||
} | |||
|
|||
func (c *memcachedClient) Set(item *memcache.Item) error { | |||
// Skip hitting memcached at all if the item is bigger than the max allowed size. | |||
if c.maxItemSize > 0 && uint64(len(item.Value)) > uint64(c.maxItemSize) { | |||
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.
I would appreciate a metric similar to Thanos.
Signed-off-by: yeya24 <yb532204897@gmail.com>
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.
LGTM (modulo a nit)
pkg/chunk/cache/memcached_client.go
Outdated
@@ -183,6 +196,12 @@ func (c *memcachedClient) Stop() { | |||
} | |||
|
|||
func (c *memcachedClient) Set(item *memcache.Item) error { | |||
// Skip hitting memcached at all if the item is bigger than the max allowed size. | |||
if c.maxItemSize > 0 && uint64(len(item.Value)) > uint64(c.maxItemSize) { |
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.
No need to cast to uint64
:
if c.maxItemSize > 0 && uint64(len(item.Value)) > uint64(c.maxItemSize) { | |
if c.maxItemSize > 0 && len(item.Value) > c.maxItemSize { |
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.
Thanks! Updated.
Signed-off-by: yeya24 <yb532204897@gmail.com>
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.
LGTM
* support memcached max_item_size configuration Signed-off-by: yeya24 <yb532204897@gmail.com> * add new metric Signed-off-by: yeya24 <yb532204897@gmail.com> * dont cast to uint Signed-off-by: yeya24 <yb532204897@gmail.com>
Signed-off-by: yeya24 yb532204897@gmail.com
What this PR does:
Add
max_item_size
support to Cortex Memcached client.Which issue(s) this PR fixes:
Fixes #
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]