Adjust Praefect server address based on peer info
Currently, Praefect will inject either its local Unix socket path or its listen address into the context, based on which one is set up in its configuration. There's multiple problems with this, though:
- First, it could be that both addresses are required based on which
Gitaly node it reaches out to. E.g. if one Gitaly node is running
on the same machine, it may use a Unix socket instead of a TCP
connection. In that case, we should use Praefect's Unix socket to
reach back out to it. But for another node, we may want to use a
TCP socket instead as it's hosted on a different machine. So
injecting either Unix socket or TCP address needs to depend on the
node we're reaching out to.
- Second, if Praefect's configured to only have a wildcard listen
address, we'd currently inject "0.0.0.0:$PORT" into the context.
That's not really helpful at all to Gitaly and doesn't help much
in connecting to Praefect.
In order to fix both issues, we now start injecting both Unix socket path as well as the listen address into the context. Gitaly will then extract peer information from the incoming Praefect connection and choose the correct one based on whether it's a Unix or TCP connection. Furthermore, in case of a TCP connection, Gitaly nodes will now replace the host part of the injected listen address with the peer address, only keeping the port information intact.
Fixes #2793 (closed)