diff --git a/Dockerfile b/Dockerfile index dec14b4f..19f7ac4c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,6 @@ COPY alembic.ini alembic.ini EXPOSE 2017 -ENV prometheus_multiproc_dir /tmp/routemaster/prometheus +ENV PROMETHEUS_MULTIPROC_DIR /tmp/routemaster/prometheus CMD ["routemaster", "--config-file=config.yaml", "serve"] diff --git a/plugins/routemaster-prometheus/README.md b/plugins/routemaster-prometheus/README.md index b3f8e533..c02fee26 100644 --- a/plugins/routemaster-prometheus/README.md +++ b/plugins/routemaster-prometheus/README.md @@ -13,7 +13,7 @@ Usage, in your Routemaster configuration file: This package is based on the official Python Promeutheus bindings in [`prometheus_client`](https://pypi.org/project/prometheus_client/). In order for that package to operate in a multithreaded program such as Routemaster, -the environment variable `prometheus_multiproc_dir` must be set to a writeable +the environment variable `PROMETHEUS_MULTIPROC_DIR` must be set to a writeable directory for temporary files. It does not need to be backed up as nothing is persisted between application launches. diff --git a/plugins/routemaster-prometheus/routemaster_prometheus/__init__.py b/plugins/routemaster-prometheus/routemaster_prometheus/__init__.py index 6a2810b0..2f45e5ff 100644 --- a/plugins/routemaster-prometheus/routemaster_prometheus/__init__.py +++ b/plugins/routemaster-prometheus/routemaster_prometheus/__init__.py @@ -62,12 +62,17 @@ def __init__( path='/metrics', ): self.path = path - metrics_path = os.environ.get('prometheus_multiproc_dir') + # Lower case spelling prometheus_multiproc_dir is deprecated but still + # supported by prometheus_client. + metrics_path = ( + os.environ.get('PROMETHEUS_MULTIPROC_DIR') or + os.environ.get('prometheus_multiproc_dir') + ) if not metrics_path: raise ValueError( "PrometheusLogger requires the environment variable " - "`prometheus_multiproc_dir` to be set to a writeable " + "`PROMETHEUS_MULTIPROC_DIR` to be set to a writeable " "directory.", ) diff --git a/plugins/tests/test_logging_plugins.py b/plugins/tests/test_logging_plugins.py index dc3eb3d3..f6b00314 100644 --- a/plugins/tests/test_logging_plugins.py +++ b/plugins/tests/test_logging_plugins.py @@ -132,7 +132,7 @@ def root(): def test_prometheus_logger_wipes_directory_on_startup(app): - tmp = pathlib.Path(os.environ['prometheus_multiproc_dir']) + tmp = pathlib.Path(os.environ['PROMETHEUS_MULTIPROC_DIR']) tmp.mkdir(parents=True, exist_ok=True) filepath = tmp / 'foo.txt' @@ -181,10 +181,10 @@ def test_prometheus_logger_ignores_metrics_path(routemaster_serve_subprocess): def test_prometheus_logger_validates_metrics_path(app): - orig = os.environ['prometheus_multiproc_dir'] - os.environ['prometheus_multiproc_dir'] = '' + orig = os.environ['PROMETHEUS_MULTIPROC_DIR'] + os.environ['PROMETHEUS_MULTIPROC_DIR'] = '' with pytest.raises(ValueError): PrometheusLogger(app.config) - os.environ['prometheus_multiproc_dir'] = orig + os.environ['PROMETHEUS_MULTIPROC_DIR'] = orig diff --git a/routemaster/conftest.py b/routemaster/conftest.py index 050b9969..d18b9b73 100644 --- a/routemaster/conftest.py +++ b/routemaster/conftest.py @@ -12,13 +12,13 @@ from unittest import mock import pytest +import werkzeug import httpretty import dateutil.tz import pkg_resources from sqlalchemy import create_engine from werkzeug.test import Client from sqlalchemy.orm import sessionmaker -from werkzeug.wrappers import BaseResponse from routemaster import state_machine from routemaster.db import Label, History, metadata @@ -255,15 +255,6 @@ def session(self): return super().session -class TestClientResponse(BaseResponse): - """Test client response format.""" - - @property - def json(self): - """Util property for json responses.""" - return json.loads(self.data) - - def get_test_app(**kwargs): """Instantiate an app with testing parameters.""" return TestApp(Config( @@ -284,7 +275,7 @@ def client(custom_app=None): _app = get_test_app() if custom_app is None else custom_app server.config.app = _app _app.logger.init_flask(server) - return Client(wrap_application(_app, server), TestClientResponse) + return Client(wrap_application(_app, server), werkzeug.Response) @pytest.fixture() @@ -323,7 +314,7 @@ def database_creation(request): yield -@pytest.yield_fixture(autouse=True) +@pytest.fixture(autouse=True) def database_clear(app): """Truncate all tables after each test.""" yield diff --git a/routemaster/tests/test_gunicorn_application.py b/routemaster/tests/test_gunicorn_application.py index 02eb63b2..e8b21133 100644 --- a/routemaster/tests/test_gunicorn_application.py +++ b/routemaster/tests/test_gunicorn_application.py @@ -3,7 +3,6 @@ import pytest import werkzeug.test import werkzeug.testapp -import werkzeug.wrappers from routemaster.gunicorn_application import GunicornWSGIApplication @@ -23,7 +22,7 @@ def test_gunicorn_application_can_be_constructed(debug): client = werkzeug.test.Client( loaded_wsgi_callable, - werkzeug.wrappers.BaseResponse, + werkzeug.Response, ) response = client.get('/') assert response.status_code == 200 diff --git a/scripts/testing/requirements.txt b/scripts/testing/requirements.txt index 4d3de353..1bd8ffb9 100644 --- a/scripts/testing/requirements.txt +++ b/scripts/testing/requirements.txt @@ -8,6 +8,5 @@ freezegun httpretty pytest-pythonpath -# 0.15.0 contains fix https://github.com/pallets/werkzeug/pull/1280 -# 2.1 has breaking BaseResponse removal -werkzeug >=0.15.0, <2.1 +# Version 2 has much better testing tooling +werkzeug >=2 diff --git a/scripts/typechecking/requirements.txt b/scripts/typechecking/requirements.txt index aeee0d62..489b2914 100644 --- a/scripts/typechecking/requirements.txt +++ b/scripts/typechecking/requirements.txt @@ -7,5 +7,4 @@ types-PyYAML types-requests types-setuptools -# 2.1 has breaking BaseResponse removal -werkzeug <2.1 +werkzeug >=2 diff --git a/setup.cfg b/setup.cfg index 08d8d1f5..12471577 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,4 +49,4 @@ extend_skip = [tool:pytest] python_paths=test_data/plugins/ env = - prometheus_multiproc_dir=/tmp/routemaster-tests/prometheus + PROMETHEUS_MULTIPROC_DIR=/tmp/routemaster-tests/prometheus diff --git a/tox.ini b/tox.ini index 3ed1e495..938b3ac1 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,7 @@ passenv= PG_USER PG_PASS setenv = - prometheus_multiproc_dir={envtmpdir} + PROMETHEUS_MULTIPROC_DIR={envtmpdir} commands = mkdir -p build/results mkdir -p build/artifacts