dskit icon indicating copy to clipboard operation
dskit copied to clipboard

Add support for "`sd_listen_fds`" socket activation socket support for gRPC and HTTP listeners

Open networkException opened this issue 1 year ago • 1 comments

What this PR does:

This pull request adds support for server to be used with systemd's socket activation by expecting an open file descriptor to be announced using environment variables.

To make use of this set either HTTPListenNetwork or GRPCListenNetwork to "sd_listen_fd" and HTTPListenAddress or GRPCListenAddress either to an ASCII string passed as the FileDescriptorName= from a systemd.socket unit or "LISTEN_FD_$n", where $n is the file descriptor number, starting with 3 (SD_LISTEN_FDS_START).

By default, when using "sd_listen_fd", the address will be "LISTEN_FD_3".

This patch makes use of the coreos/go-systemd/v22/activation library (which was already included as an indirect dependency). Unfortunately their implementation doesn't allow call sites to get a view of the listeners both by file descriptor number and file descriptor name, as the highlevel helpers cannot be used.

This is similar in spirit to https://github.com/grafana/dskit/pull/511, I'll happily include unix socket support in the listen helper this change introduces as part of the rebase.

Which issue(s) this PR fixes:

Checklist

  • [ ] Tests updated
  • [x] CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

networkException avatar Sep 30 '24 19:09 networkException

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 30 '24 20:09 CLAassistant