Skip to content

Commit

Permalink
Merge branch 'fix-deprecations'
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJCLaw committed Apr 4, 2022
2 parents 2e36fa1 + 59ea34f commit f0f044e
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion plugins/routemaster-prometheus/README.md
Expand Up @@ -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.

Expand Down
Expand Up @@ -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.",
)

Expand Down
8 changes: 4 additions & 4 deletions plugins/tests/test_logging_plugins.py
Expand Up @@ -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'
Expand Down Expand Up @@ -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
15 changes: 3 additions & 12 deletions routemaster/conftest.py
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions routemaster/tests/test_gunicorn_application.py
Expand Up @@ -3,7 +3,6 @@
import pytest
import werkzeug.test
import werkzeug.testapp
import werkzeug.wrappers

from routemaster.gunicorn_application import GunicornWSGIApplication

Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions scripts/testing/requirements.txt
Expand Up @@ -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
3 changes: 1 addition & 2 deletions scripts/typechecking/requirements.txt
Expand Up @@ -7,5 +7,4 @@ types-PyYAML
types-requests
types-setuptools

# 2.1 has breaking BaseResponse removal
werkzeug <2.1
werkzeug >=2
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -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
Expand Down

0 comments on commit f0f044e

Please sign in to comment.