25 Commits

Author SHA1 Message Date
Clark Boylan
7513b5b74f Reload haproxy when its config updates
Without this our config changes are not applying to the running service
until something else reloads or restarts the service.

Change-Id: I4df229d1c42f06159a4b320d4b6a07c5239ca111
2022-02-16 15:30:01 -08:00
Ian Wienand
3c993c317b haproxy: map in config as ro
The container shouldn't need to write to its config

Change-Id: Iadbe7b663615623fbd6201aa1f2557b0eb267179
2021-12-01 09:57:05 +11:00
Ian Wienand
f29aa2da16 Make haproxy role more generic
This makes the haproxy role more generic so we can run another (or
potentially even more) haproxy instance(s) to manage other services.

The config file is moved to a variable for the haproxy role.  The
gitea specific config is then installed for the gitea-lb service by a
new gitea-lb role.

statsd reporting is made optional with an argument.  This
enables/disables the service in the docker compose.

Role documenation is updated.

Needed-By: https://review.opendev.org/678159
Change-Id: I3506ebbed9dda17d910001e71b17a865eba4225d
2021-12-01 09:55:45 +11:00
Clark Boylan
2828a51ef9 Run haproxy-statsd as uid 1000
This aligns it with what we have done for zookeeper-statsd.

Change-Id: Ida0e3c3e7dbcaf915119f7e2677edf95c7550eea
2021-11-05 16:45:32 +00:00
Ian Wienand
51e3976273 Run haproxy as root user
The usptream haproxy image switched to running as a user, rather than
as root.  This means it can not bind to 80/443 and instantly dies.

I've added a comment with some discussion, but for now, use the root
user.

[1] 82ff028a25

Change-Id: Ic9b04cdd09f73d9df015bcb173871cff1ae58835
2021-05-17 14:28:37 +10:00
Jeremy Stanley
4189add2f7 Temporarily pin haproxy image to 2.3
The haproxy 2.4 images aren't working for us, docker-compose
perpetually reports the container in a "restarting" state. Pin back
from latest to 2.3 until we can sort out what needs to change in how
we integrate this on the server.

Change-Id: I01ae11a31eb8eaeb9e570692d5ec268395f69a97
2021-05-15 12:19:48 +00:00
Ian Wienand
633c4c51ec haproxy: write to container log files
This moves the haproxy containers to syslog with tags that will get
each container's output filtered into /var/log/containers.

Change-Id: I65294baec3c092ede5ee97856d8d879174b0d8d4
2021-03-26 10:16:13 +11:00
Jeremy Stanley
836cb746c8 Remove the tcplog option from haproxy configs
Adding the tcplog option to an haproxy backend definition overrides
the default log format. Remove it so the supplied default (which we
based on the tcplog built-in default with some additions) will be
used instead.

Change-Id: Id302dede950c1c2ab8e74a662cc3cb1186a6593d
2020-06-30 22:22:28 +00:00
Jeremy Stanley
497df9b4d1 Add backend source port to haproxy logs
When forwarding TCP sockets at OSI layer 4 with haproxy, it helps to
know the ephemeral port from which it sources each connection to the
backend. In this way, backend connections can be mapped to actual
client IP addresses by correlating backend service access logs with
haproxy logs.

Add "[%bi]:%bp" between the frontend name and backend name values
for the default log-format documented here:

    https://www.haproxy.com/blog/haproxy-log-customization/

Change-Id: Ic2623d483d98cd686a85d40bc4f2e8577fb9087f
2020-06-30 19:46:26 +00:00
Jeremy Stanley
794799d4ae Revert "Increase allowed number of haproxy connections"
The increase in connection volume is not sustainable for the available memory on the backend servers. We'll likely need to scale the cluster before reattempting this.

This reverts commit 79f363164ed0c81e4c7603885f8e9815164b2df2.

Change-Id: Ibe64f472633a62df659c6183aa96e095dda7fdbc
2020-06-30 17:36:13 +00:00
Clark Boylan
79f363164e Increase allowed number of haproxy connections
We've set maxconn to 4k concurrent connections on the front side of our
haproxy load balancer. Currently that seems to be creating a large
backlog of requests. Looking at cacti it appears that we have maybe up
to ~6-8 times this amount of overhead in resources on the gitea
backends. Be a little conservative and bump this value up by 4x and tune
from there.

Change-Id: I56d43b52c23f251cc632315c3b57e45541722970
2020-06-30 07:26:47 -07:00
Clark Boylan
8eb981b47f Install docker-compose from pypi
We want to use stop_grace_period to manage gerrit service stops. This
feature was added in docker-compose 1.10 but the distro provides 1.5.
Work around this by installing docker-compose from pypi.

This seems like a useful feature and we want to manage docker-compose
the same way globally so move docker-compose installation into the
install-docker role.

New docker-compose has slightly different output that we must check for
in the gitea start/stop machinery. We also need to check for different
container name formatting in our test cases. We should pause here and
consider if this has any upgrade implications for our existing services.

Change-Id: Ia8249a2b84a2ef167ee4ffd66d7a7e7cff8e21fb
2020-04-16 12:08:00 -07:00
Monty Taylor
5de73f6c36 Use explicit image paths
To make it clear that docker hub is but one of many possible registries,
update our usage of FROM and image: lines to include docker.io in the
path.

There are a few other FROM lines for the gitea images which are handled
in a separate stack.

Change-Id: I6fafd5f659ad19de6951574afc9a6b6a4cf184df
2019-12-17 08:13:34 -05:00
Zuul
60d4a1bdd3 Merge "Reload haproxy configuration when config changes" 2019-07-23 18:55:05 +00:00
Jeremy Stanley
df23d48949 Reload haproxy configuration when config changes
Add an Ansible handler to send a hangup signal through
docker-compose to the running haproxy daemon any time the task to
update its configuration fires.

Change-Id: I1946c1e7eaaa8a8e2209007b5d065dba952ec6e2
2019-07-23 16:48:23 +00:00
Clark Boylan
08a113d4a8 Actually check backends are alive in haproxy
This adds the simplest form of health checking to haproxy, a tcp check
to the backends. We can do more sophisticated checks like checking ssl
negotiates or even HTTP requests but for now this is probably a good
improvement.

Change-Id: I3c6b07df4b3e0c380c757e1e5cb51ae0be655f34
2019-07-23 08:13:12 -07:00
Clark Boylan
d80f4a93ab Collect haproxy logs via syslog
Haproxy wants to log to syslog (and not stdout for performance reasons,
see https://github.com/dockerfile/haproxy/issues/3). However there is no
running syslog in our haproxy container. What we can do is mount in the
host's /dev/log and have haproxy write to the hosts syslog to get
logging.

Do this via a docker compose volume bind mount.

Change-Id: Icf4a91c2bc5f5dbb0bfb9d36e7ec0210c6dc4e90
2019-07-17 13:40:53 -07:00
Clark Boylan
b50a748d44 Switch git lb to source balance method
We were using the leastconn method which sends new connections to the
backend with the least number of connections. Unfortunately git clients
seem to have trouble with varying backend repo state (due to GC and
packing) and the thought is sending all requests from a single client to
a single backend will alleviate this.

To do this we switch to the source balance method which hashes the
source IP and finds a stable backend to talk to. This method handles
backend outages fine as it will hash to a new backend if the older one
goes offline.

Change-Id: I2c7a4ec0809a2f4ef6556833ac6a0ff3651904dd
2019-05-28 08:17:05 -07:00
James E. Blair
5faf89f566 Add haproxy-statsd to haproxy server
Build a container image with the haproxy-statsd script, and run that
along with the haproxy container.

Change-Id: I18be70d339df613bf9a72e115e80a6da876111e0
2019-05-24 15:40:28 -07:00
Zuul
157ad6d521 Merge "Prune docker images after docker-compose up" 2019-05-16 22:55:04 +00:00
Clark Boylan
625d45567f Install socat where we install haproxy
Socat is useful for managing haproxy through the haproxy management
socket. Install it when we install haproxy.

Change-Id: Ie2b16cef62f661669756d24d4a69ac1683401268
2019-05-03 08:18:05 -07:00
Clark Boylan
f4bf952f34 Prune docker images after docker-compose up
This ensures that we cleanup images that are superceded and no longer
necessary. We do this to avoid filling the disk with docker images.

Note that we use the -f flag to avoid being prompted by docker image
prune for confirmation.

Change-Id: I8eb5bb97d8c66755e695498707220c9e6e7b2de0
2019-05-02 15:09:37 -07:00
James E. Blair
65563f226e Bind to v4 and v6 in haproxy
Also, add a newline between listener stanzas in the config for
readability.

Change-Id: I599ca06f933e746fae3769e7872ae9911c4b00ed
2019-04-18 15:38:15 -07:00
James E. Blair
4d91f29b39 Run docker-compose pull before docker-compose up
This will make sure that the latest relevant images are in the
local image storage, and therefore, will cause docker-compose up
to recreate containers when the images are updated.

Change-Id: Ic6f0bc8c8aea5b5c16501f4ab5d3095fb70c0ff7
2019-03-04 14:40:35 -08:00
James E. Blair
4b031f9f24 Run an haproxy load balancer for gitea
This runs an haproxy which is strikingly similar to the one we
currently run for git.openstack.org, but it is run in a docker
container.

Change-Id: I647ae8c02eb2cd4f3db2b203d61a181f7eb632d2
2019-02-22 12:54:04 -08:00