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
Replace custom Redis config struct with go-redis UniversalOptions (adds sentinel & cluster support) #4306
base: main
Are you sure you want to change the base?
Conversation
4431aa2
to
b09dbb1
Compare
Please sign your commits as per https://github.com/distribution/distribution/blob/main/CONTRIBUTING.md#contributing-code |
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.
The problem with this change is, it's tying the code to a specific Go module, which I'm not entirely sure is a good idea.
b09dbb1
to
d8a1f01
Compare
@Jamstah done. p.s.: I figured out the test failure: The marshaller is trying to serialize the |
Also, it looks like |
d8a1f01
to
c6615dc
Compare
@milosgajdos, replicating the struct actually fixes the marshalling sooo 🤷♂️ fixed :-D |
c6615dc
to
f74a981
Compare
We're already using the go module to provide the client itself, so why not also use it to provide the config struct? If we ever change go module it would need rewriting anyway. I like the idea of matching our config to be more "standard". |
@Jamstah I agree. In that case the marshalling (or the test) needs some work though. I don't know how to exclude the functions that are referenced in those configs, any ideas? |
*ping after the holidays. I would love if we could figure out how to progress with this. |
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.
We are still missing doc updates here:
distribution/docs/content/about/configuration.md
Lines 953 to 1020 in 0d1792f
## `redis` | |
```yaml | |
redis: | |
addr: localhost:6379 | |
password: asecret | |
db: 0 | |
dialtimeout: 10ms | |
readtimeout: 10ms | |
writetimeout: 10ms | |
pool: | |
maxidle: 16 | |
maxactive: 64 | |
idletimeout: 300s | |
tls: | |
enabled: false | |
``` | |
Declare parameters for constructing the `redis` connections. Registry instances | |
may use the Redis instance for several applications. Currently, it caches | |
information about immutable blobs. Most of the `redis` options control | |
how the registry connects to the `redis` instance. You can control the pool's | |
behavior with the [pool](#pool) subsection. Additionally, you can control | |
TLS connection settings with the [tls](#tls) subsection (in-transit encryption). | |
You should configure Redis with the **allkeys-lru** eviction policy, because the | |
registry does not set an expiration value on keys. | |
| Parameter | Required | Description | | |
|-----------|----------|-------------------------------------------------------| | |
| `addr` | yes | The address (host and port) of the Redis instance. | | |
| `password`| no | A password used to authenticate to the Redis instance.| | |
| `db` | no | The name of the database to use for each connection. | | |
| `dialtimeout` | no | The timeout for connecting to the Redis instance. | | |
| `readtimeout` | no | The timeout for reading from the Redis instance. | | |
| `writetimeout` | no | The timeout for writing to the Redis instance. | | |
### `pool` | |
```yaml | |
pool: | |
maxidle: 16 | |
maxactive: 64 | |
idletimeout: 300s | |
``` | |
Use these settings to configure the behavior of the Redis connection pool. | |
| Parameter | Required | Description | | |
|-----------|----------|-------------------------------------------------------| | |
| `maxidle` | no | The maximum number of idle connections in the pool. | | |
| `maxactive`| no | The maximum number of connections which can be open before blocking a connection request. | | |
| `idletimeout`| no | How long to wait before closing inactive connections. | | |
### `tls` | |
```yaml | |
tls: | |
enabled: false | |
``` | |
Use these settings to configure Redis TLS. | |
| Parameter | Required | Description | | |
|-----------|----------|-------------------------------------- | | |
| `enabled` | no | Whether or not to use TLS in-transit. | | |
Also, it looks like redis.tls.enabled had no effect previously? I don't see it used anywhere...
Yes, that was an oversight on my side when switching to the new module. There is an issue someone opened recently: #4284
My other comment is...there is now a boat load of new config items. What are they initialized to when omitted from the config file? Is not having a config value for each of them going to make the user confused? I guess what I'm trying to say is: what's the behaviour like when they're initialized to their default Go vals when omitted.
configuration/configuration.go
Outdated
|
||
// DB specifies the database to connect to on the redis instance. | ||
DB int `yaml:"db,omitempty"` | ||
Protocol int |
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 does Protocol
stand 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.
Protocol 2 or 3. Use the version to negotiate RESP version with redis-server. Default is 3.
It seems to have been removed in the latest v9.
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.
Probably would be useful to carry the comments from here https://github.com/redis/go-redis/blob/v9.1.0/options.go#L31-L139 into this struct as well in case questions like these come up again.
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.
That's not the UniversalOptions
struct though :-/
I carried over all the comments from that one.
Again, it's probably a lot smarter to simply use that struct directly. The indirection just adds a lot of confusion. If the go-redis struct is referenced directly you know there isn't any tomfoolery happening.
Here are the structs with all the options specified:
I'm starting to think that using the redis-go UniversalOptions struct directly is the better option here. It cuts down on maintenance and documentation. We can simply link out to e.g. https://pkg.go.dev/github.com/go-redis/redis/v9#UniversalOptions. All that is needed for that is figuring out how to get around the marshalling issue. |
I think that might be the best course of action should we decide to go forth with this. |
f74a981
to
2fa441f
Compare
@andsens can you sign your commit, please |
@milosgajdos ah crap, sry. I reverted to the previous version and forgot to amend. Will do when I get back to my work PC. In the meantime, what do we do about the failed marshalling of the config? |
There is some silly reflection stuff in |
Signed-off-by: Anders Ingemann <aim@orbit.online>
2fa441f
to
51037d3
Compare
Less code more features! :-D
This PR replaces the custom
Redis
config struct withUniversalOptions
fromgo-redis
, which implicitly adds support for both redis sentinel and redis clustering.I have two failing tests that I can't quite figure out how to fix:
Associated stack trace
As v3 is still in alpha I was hoping that there would still be time for this to make it into the release.