Skip to content

Commit

Permalink
Configure Toolforge health-check-path
Browse files Browse the repository at this point in the history
With this, `webservice restart` should perform a no-downtime rolling
restart, where Kubernetes only terminates the old pod once the new one
is ready. The tool might also be restarted automatically if the health
check starts failing (though I’m not sure how often this would happen
with the “blank” health check we configure here, which really only
confirms uWSGI is running).

Add a new /healthz route, and put it in the service.template; also,
since this route is going to be hit by a lot of requests, disable
logging for it. And since this means we now have an uwsgi.ini file
anyway, we might as well also configure automatic log rotation, as
documented at [1] – though I prefer a slightly larger maximum file size
than suggested there.

[1]: https://wikitech.wikimedia.org/wiki/Help:Toolforge/Web/Python#Logs

Bug: T341919
  • Loading branch information
lucaswerkmeister committed Feb 28, 2024
1 parent 9d69de4 commit 621944e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions {{cookiecutter.tool_identifier}}/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ def logout(){% if cookiecutter.set_up_mypy == "True" %} -> RRV{% endif %}:
return flask.redirect(flask.url_for('index'))


@app.route('/healthz')
def health(){% if cookiecutter.set_up_mypy == "True" %} -> RRV{% endif %}:
return ''


def full_url(endpoint{% if cookiecutter.set_up_mypy == "True" %}: str{% endif %}, **kwargs){% if cookiecutter.set_up_mypy == "True" %} -> str{% endif %}:
scheme = flask.request.headers.get('X-Forwarded-Proto', 'http')
return flask.url_for(endpoint, _external=True, _scheme=scheme, **kwargs)
Expand Down
1 change: 1 addition & 0 deletions {{cookiecutter.tool_identifier}}/service.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# Provide default arguments for `webservice` commands for this tool.
backend: kubernetes
type: python3.11
health-check-path: /healthz
6 changes: 6 additions & 0 deletions {{cookiecutter.tool_identifier}}/uwsgi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[uwsgi]
# rotate ~/uwsgi.log after 100 MiB
log-maxsize = 104857600
# don’t log the /healthz health-check endpoint to ~/uwsgi.log
# (it’s included in Kubernetes startup and liveness probes so it gets lots of requests)
route = ^/healthz donotlog:

0 comments on commit 621944e

Please sign in to comment.