Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 25, 2024
1 parent ab3ad4b commit fcd3dc9
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 13 deletions.
1 change: 0 additions & 1 deletion acceptance_tests/gunicorn_app/app_alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions acceptance_tests/gunicorn_app/c2cwsgiutils_app/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import prometheus_client
import requests
import sqlalchemy.sql.expression
from pyramid.httpexceptions import (
HTTPBadRequest,
HTTPForbidden,
Expand Down
2 changes: 1 addition & 1 deletion acceptance_tests/tests/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
- C2C_REDIS_DB=1
- PYTHONMALLOC=debug
- DEBUG_LOGCONFIG
- GUNICORN_WORKERS=1
- GUNICORN_WORKERS=2
- GUNICORN_THREADS=10
# Test problematic environment variable (values contains % and duplicated with different cass)
- TEST='%1'
Expand Down
8 changes: 4 additions & 4 deletions acceptance_tests/tests/tests/test_prometheus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion acceptance_tests/waitress_app/app_alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions acceptance_tests/waitress_app/c2cwsgiutils_app/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import prometheus_client
import requests
import sqlalchemy.sql.expression
from pyramid.httpexceptions import (
HTTPBadRequest,
HTTPForbidden,
Expand Down
22 changes: 20 additions & 2 deletions c2cwsgiutils/loader.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
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__)

Expand All @@ -19,3 +19,21 @@ def _get_defaults(self, defaults: Optional[dict[str, str]] = None) -> dict[str,
def __repr__(self) -> str:
"""Get the object representation."""
return f'c2cwsgiutils.loader.Loader(uri="{self.uri}")'

def setup_logging(self, defaults: Optional[dict[str, str]] = None) -> None:
"""
Set up logging via :func:`logging.config.fileConfig`.
Defaults are specified for the special ``__file__`` and ``here``
variables, similar to PasteDeploy config loading. Extra defaults can
optionally be specified as a dict in ``defaults``.
Arguments:
defaults: The defaults that will be used when passed to
:func:`logging.config.fileConfig`.
"""
if "loggers" in self.get_sections():
logging.config.dictConfig(get_logconfig_dict(self.uri.path))
else:
logging.basicConfig()
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ prometheus-client = { version = "0.21.0", optional = true}
pyramid_mako = { version = "1.1.0", optional = true}
psutil = { version = "6.1.0", optional = true}
Paste = { version = "3.10.1", optional = true}
coverage = { version = "7.6.4", optional = true}

[tool.poetry.extras]
standard = [
Expand Down Expand Up @@ -123,7 +124,7 @@ standard = [
"Paste",
]
alembic = ["alembic"]
debug = ["objgraph", "psutil"]
debug = ["objgraph", "psutil", "coverage"]
oauth2 = ["pyjwt", "requests-oauthlib"]
sentry = ["sentry-sdk"]
dev = ["waitress"]
Expand Down Expand Up @@ -160,6 +161,7 @@ all = [
# debug
"objgraph",
"psutil",
"coverage",
# oauth2
"pyjwt",
"requests-oauthlib",
Expand Down

0 comments on commit fcd3dc9

Please sign in to comment.