Repository navigation
Option to configure proxy cache TTL - #3880
Conversation
3ed03b9 to
fd84909
Compare
|
@milosgajdos |
3fc3eab to
f85f6dc
Compare
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]>
f85f6dc to
8fe4ca4
Compare
Codecov ReportPatch coverage has no change and project coverage change:
📣 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
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. |
| // 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"` |
There was a problem hiding this comment.
why it has to be a pointer to a Duration?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.Durationin 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 to3600, 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, orh), but (somewhat depending on what "normal" values are), we could slightly rephrase and omit "unlikely to be used" units (ns,us,ms)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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.Durationin 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 to3600, 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, orh), but (somewhat depending on what "normal" values are), we could slightly rephrase and omit "unlikely to be used" units (ns,us,ms)
| | `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. | |
There was a problem hiding this comment.
| | `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;
- duration does not accept day as unit (if that's likely to be used)
- it also accepts complex formats(?);
1h10m10s; see https://pkg.go.dev/time#example-ParseDuration - and floats (
1.234h)
So somewhat wondering if we should have our own type 🤔
There was a problem hiding this comment.
This description is referred from another configuration https://github.com/search?q=repo%3Adistribution%2Fdistribution%20%22The%20suffix%20is%20one%20of%20%60ns%60%2C%20%60us%60%2C%20%60ms%60%2C%20%60s%60%2C%20%60m%60%2C%20or%20%60h%60%22&type=code
I don't have a hard opinion.
There was a problem hiding this comment.
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.
|
what's happening folks? |
|
PTAL @squizzi |
…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).
…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).
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