Skip to content

Option to configure proxy cache TTL - #3880

Merged
milosgajdos merged 1 commit into
distribution:mainfrom
wzshiming:proxy-cache-configurable
Jul 14, 2023
Merged

milosgajdos merged 1 commit into
distribution:mainfrom
wzshiming:proxy-cache-configurable

Conversation

@wzshiming

@wzshiming wzshiming commented Apr 20, 2023 •

Copy link
Copy Markdown
Contributor

Currently when registry is run as proxy it tries to cleanup unused blobs from its cache after 7 days which is hard-coded. This PR makes that value configurable. One can disable caching using this option.

Continue #3238
Fixes #2736
Fixes #2367
Fixes #3704
Fixes #3879

@wzshiming
wzshiming force-pushed the proxy-cache-configurable branch from 3ed03b9 to fd84909 Compare April 20, 2023 04:45
@wzshiming

Copy link
Copy Markdown
Contributor Author

@milosgajdos
Please take a look

@wzshiming
wzshiming force-pushed the proxy-cache-configurable branch 5 times, most recently from 3fc3eab to f85f6dc Compare April 20, 2023 05:03
Currently when registry is run as proxy it tries to cleanup unused blobs
from its cache after 7 days which is hard-coded. This PR makes that
value configurable.

Co-authored-by: Shiming Zhang <[email protected]>
Co-authored-by: Manish Tomar <[email protected]>
Signed-off-by: Shiming Zhang <[email protected]>
@wzshiming
wzshiming force-pushed the proxy-cache-configurable branch from f85f6dc to 8fe4ca4 Compare April 20, 2023 05:03
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Patch coverage has no change and project coverage change: -0.13 ⚠️

Comparison is base (0c95801) 56.58% compared to head (8fe4ca4) 56.45%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3880      +/-   ##
==========================================
- Coverage   56.58%   56.45%   -0.13%     
==========================================
  Files         105      105              
  Lines       10636    10656      +20     
==========================================
- Hits         6018     6016       -2     
- Misses       3946     3966      +20     
- Partials      672      674       +2     
Impacted Files Coverage Δ
configuration/configuration.go 64.38% <ø> (ø)
registry/proxy/proxyblobstore.go 52.08% <0.00%> (-1.44%) ⬇️
registry/proxy/proxymanifeststore.go 42.30% <0.00%> (-3.70%) ⬇️
registry/proxy/proxyregistry.go 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@milosgajdos milosgajdos left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. PTAL @thaJeztah, @wy65701436

@milosgajdos milosgajdos added this to the Registry/3.0.0 milestone May 4, 2023
// TTL is the expiry time of the content and will be cleaned up when it expires
// if not set, defaults to 7 * 24 hours
// If set to zero, will never expire cache
TTL *time.Duration `yaml:"ttl,omitempty"`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why it has to be a pointer to a Duration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The pointer is used to determine if this is set.
If not set we fall back to the old behaviour that defaulted to 7 days

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another approach here could be to consider 0 to be "not configured" (use default), and use a sentinel value (-1 is fairly common) to disable. Golang can be a bit of a pain here to detect "unset" vs "default value", and using a special value for this can help in that respect as well. From a UX perspective it may also make it more explicit that it's deliberately set to "never expire".

Speaking of UX; while I appreciate the use of time.Duration, I'm somewhat concerned about tha UX

disclaimer:

I don't know how we handle other time.Duration in the config; I looked
at the field descriptions, which are very scarce, and most don't even document
accepted formats, defaults, and min/max values (where applicable)

  • I've seen this happen in the Docker API, where some fields also accepted a time.Duration (or similar), and users assumed numeric values were in seconds (e.g., set it to 3600, but now ending up with a value that is a multitude shorter than they expected
  • ^^ from that perspective it would be good if "no unit" would mean something sensible, OR to set a sensible minimum duration, and produce an error when setting values below that.
  • ^^ related; it's technically correct to document all accepted units (ns, us, ms, s, m, or h), but (somewhat depending on what "normal" values are), we could slightly rephrase and omit "unlikely to be used" units (ns, us, ms)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

	fmt.Println(time.Duration(-1))
	// Output:
	// -1ns

The default output is a bit confusing

If we want to use -1 it is better to define a new type to handle negative values, which replaces and is compatible with Duration and supports units such as Day, Month etc.

@milosgajdos milosgajdos May 8, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree. Duration is duration = a time period - we shouldn't be looking for wild solutions where there is no place for one. Negative values can lead to very silly situations (I've experienced misinterpretations of negative time/duration vals in past - none of them was funny to resolve in the middle of the night). My suggestion and preference is to stick with regular duration values.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we define a sensible minimum? Setting 3600 to expect "1 hour" and ending up with 3600 NanoSeconds definitely can be a bit of a footgun

if err != nil {
return err
}
var s *scheduler.TTLExpirationScheduler

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I feel all right with it, but this piece can be parsed with the built-in typed parsing, there is no need to weaken it to the insecure parsing of the plugin.

// TTL is the expiry time of the content and will be cleaned up when it expires
// if not set, defaults to 7 * 24 hours
// If set to zero, will never expire cache
TTL *time.Duration `yaml:"ttl,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another approach here could be to consider 0 to be "not configured" (use default), and use a sentinel value (-1 is fairly common) to disable. Golang can be a bit of a pain here to detect "unset" vs "default value", and using a special value for this can help in that respect as well. From a UX perspective it may also make it more explicit that it's deliberately set to "never expire".

Speaking of UX; while I appreciate the use of time.Duration, I'm somewhat concerned about tha UX

disclaimer:

I don't know how we handle other time.Duration in the config; I looked
at the field descriptions, which are very scarce, and most don't even document
accepted formats, defaults, and min/max values (where applicable)

  • I've seen this happen in the Docker API, where some fields also accepted a time.Duration (or similar), and users assumed numeric values were in seconds (e.g., set it to 3600, but now ending up with a value that is a multitude shorter than they expected
  • ^^ from that perspective it would be good if "no unit" would mean something sensible, OR to set a sensible minimum duration, and produce an error when setting values below that.
  • ^^ related; it's technically correct to document all accepted units (ns, us, ms, s, m, or h), but (somewhat depending on what "normal" values are), we could slightly rephrase and omit "unlikely to be used" units (ns, us, ms)

Comment thread docs/configuration.md
| `remoteurl`| yes | The URL for the repository on Docker Hub. |
| `username` | no | The username registered with Docker Hub which has access to the repository. |
| `password` | no | The password used to authenticate to Docker Hub using the username specified in `username`. |
| `ttl` | no | Expire proxy cache configured in "storage" after this time. Cache 168h(7 days) by default, set to 0 to disable cache expiration, The suffix is one of `ns`, `us`, `ms`, `s`, `m`, or `h`. If you specify a value but omit the suffix, the value is interpreted as a number of nanoseconds. |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
| `ttl` | no | Expire proxy cache configured in "storage" after this time. Cache 168h(7 days) by default, set to 0 to disable cache expiration, The suffix is one of `ns`, `us`, `ms`, `s`, `m`, or `h`. If you specify a value but omit the suffix, the value is interpreted as a number of nanoseconds. |
| `ttl` | no | Expire proxy cache configured in "storage" after this time. This configuration accepts a numeric value, optionally followed by a [duration unit](https://pkg.go.dev/time#ParseDuration), such as `s` (seconds), `m` (minutes) or `h` (hours). It no unit is specified, the default is `ns` (nanoseconds). Set to `0` to disable cache expiration. The default is 168h (7 days). |

Looking at that, it's also very unfortunate that;

So somewhat wondering if we should have our own type 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe we should stay consistent across the codebase. Days can be represented to as multiples of 24h. If the users find it unwieldy we can come up with some solution to it - there is no risk of breaking anything by sticking with the current approach, IMHO.

@ToroNZ

ToroNZ commented May 30, 2023

Copy link
Copy Markdown

what's happening folks?

@milosgajdos
milosgajdos requested a review from squizzi July 7, 2023 09:46
@milosgajdos

Copy link
Copy Markdown
Member

PTAL @squizzi

@wy65701436 wy65701436 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@milosgajdos
milosgajdos merged commit 69023c7 into distribution:main Jul 14, 2023
@wzshiming
wzshiming deleted the proxy-cache-configurable branch July 14, 2023 07:46
ialidzhikov added a commit to ialidzhikov/gardener-extension-registry-cache that referenced this pull request Sep 29, 2023
…bled`

The API change is done to make it easier in future to add new fields related to the garbage collection. For example there is a TTL field that we would like to expose when there is a distribution/distribution release with the PR that introduced the TTL future (ref distribution/distribution#3880).
gardener-prow Bot pushed a commit to gardener/gardener-extension-registry-cache that referenced this pull request Oct 6, 2023
…bled` (#53)

The API change is done to make it easier in future to add new fields related to the garbage collection. For example there is a TTL field that we would like to expose when there is a distribution/distribution release with the PR that introduced the TTL future (ref distribution/distribution#3880).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

6 participants