Allow to configure own URL instead of relying on httpd.listenUrl
The JGroupsPeerInfoProvider was using the value of httpd.listenUrl [1]
from the gerrit.config to detect its own URL, which is broadcast to
the jgroups channel for other peers to discover.
There were several problems with this approach.
- The httpd.listenUrl can be configured with a reverse proxy, for
example:
[httpd]
listenUrl = proxy-https://localhost:9080
When a site is configured in such a way, using the URL as-is causes
the peer's HTTP POST requests to fail with the error:
"proxy-https protocol is not supported"
- When configured with a reverse-proxy, the listenUrl's port might be
bound only to 127.0.0.1, which means it will be inaccessible from
the peer machine.
- The listenUrl's hostname may be configured as `*` to listen on all
local addresses. In this case the URL must be rewritten to replace
the `*` with a valid hostname.
- It is allowed to specify multiple values for httpd.listenUrl, but
the provider is only reading a single value from the configuration.
Rather than trying to handle these cases, allow to explicitly specify
the own URL in the JGroups peer info section of the plugin's config
file (etc/high-availability.config):
[peerInfo]
strategy = jgroups
[peerInfo "jgroups"]
myUrl = https://myserver:8080/
If the myUrl value is not specified, fall back to httpd.listenUrl, but
fail early if its value is not reasonable, i.e. require it to be a
single value with an explicit hostname.
[1] http://gerrit-documentation.storage.googleapis.com/Documentation/2.14/config-gerrit.html#httpd.listenUrl
Change-Id: Ifd97c751eea5e1eb99e70b3f02f5d80d8c368540
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index e537545..1c7caaf 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -22,6 +22,7 @@
[peerInfo]
: strategy = jgroups
[peerInfo "jgroups"]
+: myUrl = local_instance_url
: cluster = foo
: skipInterface = lo*
: skipInterface = eth2
@@ -66,6 +67,14 @@
Defaults to the list of: `lo*`, `utun*`, `awdl*` which are known to be
inappropriate for JGroups communication.
+peerInfo.jgroups.myUrl
+: The URL of this instance to be broadcast to other peers. If not specified, the
+ URL is determined from the `httpd.listenUrl` in the `gerrit.config`.
+ If `httpd.listenUrl` is configured with multiple values, is configured to work
+ with a reverse proxy (i.e. uses `proxy-http` or `proxy-https` scheme), or is
+ configured to listen on all local addresses (i.e. using hostname `*`), then
+ the URL must be explicitly specified with `myUrl`.
+
NOTE: To work properly in certain environments, JGroups needs the System property
`java.net.preferIPv4Stack` to be set to `true`.
See (http://jgroups.org/tutorial/index.html#_trouble_shooting).