Skip to content

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

Merged
merged 3 commits into from
Mar 11, 2021

Conversation

yeya24
Copy link
Contributor

@yeya24 yeya24 commented Mar 8, 2021

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

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
@@ -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
Copy link
Contributor Author

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

Copy link
Contributor

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>
@yeya24 yeya24 force-pushed the support-memcached-maxitemsize branch from 396879c to ff0a498 Compare March 8, 2021 21:21
Copy link
Contributor

@pracucci pracucci left a 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.

@@ -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.")
Copy link
Contributor

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".

@@ -52,6 +53,8 @@ type memcachedClient struct {
cbTimeout time.Duration
cbInterval time.Duration

maxItemSize model.Bytes
Copy link
Contributor

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
Copy link
Contributor

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>
Copy link
Contributor

@pracucci pracucci left a 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)

@@ -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) {
Copy link
Contributor

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:

Suggested change
if c.maxItemSize > 0 && uint64(len(item.Value)) > uint64(c.maxItemSize) {
if c.maxItemSize > 0 && len(item.Value) > c.maxItemSize {
Copy link
Contributor Author

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>
Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pracucci pracucci merged commit 040ce32 into cortexproject:master Mar 11, 2021
roystchiang pushed a commit to roystchiang/cortex that referenced this pull request Apr 6, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 participants