From 5290824fe8b73d45943a8797a73faef4ec135187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Mon, 25 Nov 2024 10:20:50 +0100 Subject: [PATCH] f --- BREAKING_CHANGES.md | 2 +- .../gunicorn_app/app_alembic/env.py | 1 - .../gunicorn_app/c2cwsgiutils_app/services.py | 1 + .../tests/tests/test_prometheus_client.py | 8 ++++---- .../waitress_app/app_alembic/env.py | 1 - .../waitress_app/c2cwsgiutils_app/services.py | 1 + acceptance_tests/waitress_app/production.ini | 2 +- c2cwsgiutils/loader.py | 20 +++---------------- c2cwsgiutils/setup_process.py | 3 --- 9 files changed, 11 insertions(+), 28 deletions(-) diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 0270877c3..adcfc9574 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -3,7 +3,7 @@ ## Release 6.1 - The `handlers` in the `.ini` files don't support `args` anymore. You must use `kwargs` - arguments. Example `args = (sys.stdout,)` becomes `kwargs = {'stream': sys.stdout}`. + arguments. Example `args = (sys.stdout,)` becomes `kwargs = {'stream': 'ext://sys.stdout'}`. - SqlAlchemy logger must now be instantiated by your app's `main` method and not by your `.ini` file. Read the example in the sqlalchemylogger folder. diff --git a/acceptance_tests/gunicorn_app/app_alembic/env.py b/acceptance_tests/gunicorn_app/app_alembic/env.py index c2b987e82..e414e8e82 100644 --- a/acceptance_tests/gunicorn_app/app_alembic/env.py +++ b/acceptance_tests/gunicorn_app/app_alembic/env.py @@ -63,7 +63,6 @@ def run_migrations_online(): context.run_migrations() -c2cwsgiutils.setup_process.bootstrap_application() if context.is_offline_mode(): run_migrations_offline() else: diff --git a/acceptance_tests/gunicorn_app/c2cwsgiutils_app/services.py b/acceptance_tests/gunicorn_app/c2cwsgiutils_app/services.py index 084ec31f7..d9461ce9d 100644 --- a/acceptance_tests/gunicorn_app/c2cwsgiutils_app/services.py +++ b/acceptance_tests/gunicorn_app/c2cwsgiutils_app/services.py @@ -2,6 +2,7 @@ import prometheus_client import requests +import sqlalchemy.sql.expression from pyramid.httpexceptions import ( HTTPBadRequest, HTTPForbidden, diff --git a/acceptance_tests/tests/tests/test_prometheus_client.py b/acceptance_tests/tests/tests/test_prometheus_client.py index 0ea8c3d06..fca2630c8 100644 --- a/acceptance_tests/tests/tests/test_prometheus_client.py +++ b/acceptance_tests/tests/tests/test_prometheus_client.py @@ -13,7 +13,7 @@ def test_prometheus_1(prometheus_1_connection): def test_prometheus_2(prometheus_2_connection): # One for the root process, one for each workers - assert ( - len(set(_PID_RE.findall(prometheus_2_connection.get("metrics", cache_expected=False, cors=False)))) - == 3 - ) + metrics = prometheus_2_connection.get("metrics", cache_expected=False, cors=False) + assert len(set(_PID_RE.findall(metrics))) == 0 + assert re.search(r"^c2cwsgiutils_python_resource\{.*", metrics, re.MULTILINE) is not None + assert re.search(r"^c2cwsgiutils_python_memory_info\{.*", metrics, re.MULTILINE) is not None diff --git a/acceptance_tests/waitress_app/app_alembic/env.py b/acceptance_tests/waitress_app/app_alembic/env.py index c2b987e82..e414e8e82 100644 --- a/acceptance_tests/waitress_app/app_alembic/env.py +++ b/acceptance_tests/waitress_app/app_alembic/env.py @@ -63,7 +63,6 @@ def run_migrations_online(): context.run_migrations() -c2cwsgiutils.setup_process.bootstrap_application() if context.is_offline_mode(): run_migrations_offline() else: diff --git a/acceptance_tests/waitress_app/c2cwsgiutils_app/services.py b/acceptance_tests/waitress_app/c2cwsgiutils_app/services.py index 084ec31f7..d9461ce9d 100644 --- a/acceptance_tests/waitress_app/c2cwsgiutils_app/services.py +++ b/acceptance_tests/waitress_app/c2cwsgiutils_app/services.py @@ -2,6 +2,7 @@ import prometheus_client import requests +import sqlalchemy.sql.expression from pyramid.httpexceptions import ( HTTPBadRequest, HTTPForbidden, diff --git a/acceptance_tests/waitress_app/production.ini b/acceptance_tests/waitress_app/production.ini index be7235e63..595b7c549 100644 --- a/acceptance_tests/waitress_app/production.ini +++ b/acceptance_tests/waitress_app/production.ini @@ -88,7 +88,7 @@ qualname = c2cwsgiutils_app [handler_console] class = logging.StreamHandler -kwargs = "{'stream': 'ext://sys.stdout'}" +kwargs = {'stream': 'ext://sys.stdout'} level = NOTSET formatter = generic diff --git a/c2cwsgiutils/loader.py b/c2cwsgiutils/loader.py index 9d84b5577..fc7491f4b 100644 --- a/c2cwsgiutils/loader.py +++ b/c2cwsgiutils/loader.py @@ -1,11 +1,9 @@ -import logging -import tempfile -from logging.config import fileConfig +import logging.config from typing import Optional, cast from plaster_pastedeploy import Loader as BaseLoader -from c2cwsgiutils import get_config_defaults +from c2cwsgiutils import get_config_defaults, get_logconfig_dict _LOG = logging.getLogger(__name__) @@ -36,18 +34,6 @@ def setup_logging(self, defaults: Optional[dict[str, str]] = None) -> None: """ if "loggers" in self.get_sections(): - parser = self._get_parser(defaults) - - handlers = [k.strip() for k in parser["handlers"]["keys"].split(",")] - for hh in handlers: - block = parser[f"handler_{hh}"] - if "kwargs" in block: - block["kwargs"] = block["kwargs"].replace("'ext://sys.stdout'", "sys.stdout") - - defaults = self._get_defaults(defaults) - with tempfile.NamedTemporaryFile("w+t", encoding="utf-8") as temp_file: - parser.write(temp_file) - temp_file.flush() - fileConfig(temp_file.name, defaults, disable_existing_loggers=False) + logging.config.dictConfig(get_logconfig_dict(self.uri.path)) else: logging.basicConfig() diff --git a/c2cwsgiutils/setup_process.py b/c2cwsgiutils/setup_process.py index f85e9a98f..329d6c861 100644 --- a/c2cwsgiutils/setup_process.py +++ b/c2cwsgiutils/setup_process.py @@ -58,7 +58,6 @@ def init_logging(config_file: str = "c2c:///app/production.ini") -> None: """Initialize the non-WSGI application.""" warnings.warn("init_logging function is deprecated; use init instead so that all features are enabled") loader = get_config_loader(config_file) - loader.setup_logging(None) @@ -96,8 +95,6 @@ def bootstrap_application( https://docs.pylonsproject.org/projects/pyramid/en/latest/api/paster.html?highlight=bootstrap#pyramid.paster.bootstrap """ loader = get_config_loader(config_uri) - print(dir(loader)) - loader.setup_logging(options) logging.getLogger(__name__).info("Loading the application from %s", config_uri) return cast(PyramidEnv, bootstrap(config_uri, options=options))