netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Support Redis Unix sockets

Open tacerus opened this issue 1 year ago • 4 comments

NetBox version

3.7.5

Feature type

Change to existing functionality

Proposed functionality

Support Redis connectivity through Unix sockets

Use case

Binding to Redis servers on localhost or sidecars without exposing a TCP listener.

Database changes

No response

External dependencies

No response

tacerus avatar May 06 '24 13:05 tacerus

https://github.com/netbox-community/netbox/issues/15955 https://github.com/netbox-community/netbox/issues/4377 https://github.com/netbox-community/netbox/pull/15590

tacerus avatar May 06 '24 13:05 tacerus

From previous tickets:

Proposed Functionality

Implement unix-socket support for Redis cache and webhook

Use Case

When Redis is installed on the same Server as netbox, then the possible usage of unix sockets for redis would be nice. When using unix sockets, there is no need for localhost loopback with the whole IP-Stack. The usage with unix sockets can improve the performance too (even if it doesn't matter).

Database Changes

No DB-Changes needed. Just some small changes in settings.py and configuration.py

arthanson avatar May 06 '24 14:05 arthanson

Hello, I have a patch that I'm willing to upstream that was made to support Redis Unix sockets.

(Note: the linked patch also modifies STATIC_ROOT, but this modification is not part of the proposed changes)

This patch defines new REDIS['tasks']['URL'] and REDIS['caching']['URL'] settings, which take priority if defined by the user. The user can then set this config if they want to use Unix sockets:

REDIS = {
    "tasks": {"URL": "unix:///run/redis-netbox/redis.sock?db=0", "SSL": False},
    "caching": {"URL": "unix:///run/redis-netbox/redis.sock?db=1", "SSL": False},
}

In the case of the tasks Redis database, if and only if URL is defined, NetBox would use it.

In the case of the caching Redis database, URL is always used, but defaults to the value that was used before the patch.

This should be backwards compatible.

minijackson avatar May 07 '24 08:05 minijackson

@minijackson sounds good, I'll assign this to you for a PR. Thanks!

jeremystretch avatar May 07 '24 12:05 jeremystretch

@minijackson are you still interested in working on this?

jeremystretch avatar May 21 '24 18:05 jeremystretch

Yes, sorry. Went on a quick vacation, then that task fell through the cracks. I'll submit a PR soon.

minijackson avatar May 21 '24 18:05 minijackson