c2cwsgiutils 6.2.0.dev153__py3-none-any.whl → 6.2.0.dev158__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of c2cwsgiutils might be problematic. Click here for more details.
- c2cwsgiutils/db.py +7 -4
- c2cwsgiutils/stats_pyramid/_db_spy.py +8 -5
- {c2cwsgiutils-6.2.0.dev153.dist-info → c2cwsgiutils-6.2.0.dev158.dist-info}/METADATA +4 -3
- {c2cwsgiutils-6.2.0.dev153.dist-info → c2cwsgiutils-6.2.0.dev158.dist-info}/RECORD +7 -7
- {c2cwsgiutils-6.2.0.dev153.dist-info → c2cwsgiutils-6.2.0.dev158.dist-info}/WHEEL +1 -1
- {c2cwsgiutils-6.2.0.dev153.dist-info → c2cwsgiutils-6.2.0.dev158.dist-info}/entry_points.txt +0 -0
- {c2cwsgiutils-6.2.0.dev153.dist-info → c2cwsgiutils-6.2.0.dev158.dist-info/licenses}/LICENSE +0 -0
c2cwsgiutils/db.py
CHANGED
|
@@ -51,7 +51,7 @@ def setup_session(
|
|
|
51
51
|
With an accompanying tween that switches between the master and the slave DB
|
|
52
52
|
connection. Uses prefixed entries in the application's settings.
|
|
53
53
|
|
|
54
|
-
The slave DB will be used for anything that is GET and OPTIONS queries. The master DB will be used for
|
|
54
|
+
The slave DB will be used for anything that is GET, HEAD and OPTIONS queries. The master DB will be used for
|
|
55
55
|
all the other queries. You can tweak this behavior with the force_master and force_slave parameters.
|
|
56
56
|
Those parameters are lists of regex that are going to be matched against "{VERB} {PATH}". Warning, the
|
|
57
57
|
path includes the route_prefix.
|
|
@@ -111,7 +111,7 @@ def create_session(
|
|
|
111
111
|
With an accompanying tween that switches between the master and the slave DB
|
|
112
112
|
connection.
|
|
113
113
|
|
|
114
|
-
The slave DB will be used for anything that is GET and OPTIONS queries. The master DB will be used for
|
|
114
|
+
The slave DB will be used for anything that is GET, HEAD and OPTIONS queries. The master DB will be used for
|
|
115
115
|
all the other queries. You can tweak this behavior with the force_master and force_slave parameters.
|
|
116
116
|
Those parameters are lists of regex that are going to be matched against "{VERB} {PATH}". Warning, the
|
|
117
117
|
path includes the route_prefix.
|
|
@@ -187,7 +187,10 @@ def _add_tween(
|
|
|
187
187
|
has_force_master = any(r.match(method_path) for r in master_paths)
|
|
188
188
|
if FORCE_READONLY or (
|
|
189
189
|
not has_force_master
|
|
190
|
-
and (
|
|
190
|
+
and (
|
|
191
|
+
request.method in ("GET", "HEAD", "OPTIONS")
|
|
192
|
+
or any(r.match(method_path) for r in slave_paths)
|
|
193
|
+
)
|
|
191
194
|
):
|
|
192
195
|
_LOG.debug(
|
|
193
196
|
"Using %s database for: %s",
|
|
@@ -260,7 +263,7 @@ class SessionFactory(_sessionmaker):
|
|
|
260
263
|
if FORCE_READONLY or (
|
|
261
264
|
not has_force_master
|
|
262
265
|
and (
|
|
263
|
-
request.method in ("GET", "OPTIONS")
|
|
266
|
+
request.method in ("GET", "OPTIONS", "HEAD")
|
|
264
267
|
or any(r.match(method_path) for r in self.slave_paths)
|
|
265
268
|
)
|
|
266
269
|
):
|
|
@@ -16,7 +16,7 @@ _LOG = logging.getLogger(__name__)
|
|
|
16
16
|
_PROMETHEUS_DB_SUMMARY = prometheus_client.Summary(
|
|
17
17
|
prometheus.build_metric_name("database"),
|
|
18
18
|
"Database requests",
|
|
19
|
-
["what"],
|
|
19
|
+
["what", "engine"],
|
|
20
20
|
unit="seconds",
|
|
21
21
|
)
|
|
22
22
|
|
|
@@ -67,12 +67,14 @@ def _simplify_sql(sql: str) -> str:
|
|
|
67
67
|
return re.sub(r"%\(\w+\)\w", "?", sql)
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
def _create_sqlalchemy_timer_cb(what: str) -> Callable[..., Any]:
|
|
70
|
+
def _create_sqlalchemy_timer_cb(what: str, engine_name: str | None = None) -> Callable[..., Any]:
|
|
71
71
|
start = time.perf_counter()
|
|
72
72
|
|
|
73
73
|
def after(*_args: Any, **_kwargs: Any) -> None:
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
elapsed_time = time.perf_counter() - start
|
|
75
|
+
_PROMETHEUS_DB_SUMMARY.labels(what=what, engine=engine_name).observe(elapsed_time)
|
|
76
|
+
engine_suffix = f", on {engine_name}" if engine_name else ""
|
|
77
|
+
_LOG.debug("Execute statement '%s' in %.3f%ss.", what, elapsed_time, engine_suffix)
|
|
76
78
|
|
|
77
79
|
return after
|
|
78
80
|
|
|
@@ -85,10 +87,11 @@ def _before_cursor_execute(
|
|
|
85
87
|
_context: Any,
|
|
86
88
|
_executemany: Any,
|
|
87
89
|
) -> None:
|
|
90
|
+
engine_name = getattr(conn.engine, "c2c_name", None)
|
|
88
91
|
sqlalchemy.event.listen(
|
|
89
92
|
conn,
|
|
90
93
|
"after_cursor_execute",
|
|
91
|
-
_create_sqlalchemy_timer_cb(_simplify_sql(statement)),
|
|
94
|
+
_create_sqlalchemy_timer_cb(_simplify_sql(statement), engine_name),
|
|
92
95
|
once=True,
|
|
93
96
|
)
|
|
94
97
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: c2cwsgiutils
|
|
3
|
-
Version: 6.2.0.
|
|
3
|
+
Version: 6.2.0.dev158
|
|
4
4
|
Summary: Common utilities for Camptocamp WSGI applications
|
|
5
|
-
License: BSD-2-Clause
|
|
5
|
+
License-Expression: BSD-2-Clause
|
|
6
|
+
License-File: LICENSE
|
|
6
7
|
Keywords: geo,gis,sqlalchemy,orm,wsgi
|
|
7
8
|
Author: Camptocamp
|
|
8
9
|
Author-email: info@camptocamp.com
|
|
@@ -16,7 +16,7 @@ c2cwsgiutils/broadcast/utils.py,sha256=0fQZXPu3p_5LEJpGenJwiiMxECQjJhjZBjIkBk8h-
|
|
|
16
16
|
c2cwsgiutils/client_info.py,sha256=pik4rMw_GFIEjNVDO0b4aspO_eTLS3ts7dwGXmywdNE,4039
|
|
17
17
|
c2cwsgiutils/config_utils.py,sha256=vtMrVFU_fI41rbNrgjD7Msr4d8CXfPU2PRtjExX30E8,1528
|
|
18
18
|
c2cwsgiutils/coverage_setup.py,sha256=4xz9nRoYxC-8cCkMNhE06DGk0pr1azNSQK36u6wgBSM,935
|
|
19
|
-
c2cwsgiutils/db.py,sha256=
|
|
19
|
+
c2cwsgiutils/db.py,sha256=KtR5Aiwvh23580OZaO-0xsFhjX_HD9Kd6LL3pzAeEdM,16658
|
|
20
20
|
c2cwsgiutils/db_maintenance_view.py,sha256=mOXSwA7oI03lY_WGwcZnEKoTVeQloxGikk-uQ65YbE4,3049
|
|
21
21
|
c2cwsgiutils/debug/__init__.py,sha256=-MM2PJ1Dhpi7T1CvDO8JpTuO9cnRNv4DFVoCxkCZuLo,1333
|
|
22
22
|
c2cwsgiutils/debug/_listeners.py,sha256=XTtA7ix9FnTCXltGd_wAmq8huYnTaECSk0_RrELJvbE,4273
|
|
@@ -57,12 +57,12 @@ c2cwsgiutils/sqlalchemylogger/handlers.py,sha256=HscsnuhzxfIA_E63XDF3jH9RX2K5qCL
|
|
|
57
57
|
c2cwsgiutils/static/favicon-16x16.png,sha256=LKk6RFvb3NlPIZdDfAodE8H9IN8KM6CMGnMx4vOHlUQ,887
|
|
58
58
|
c2cwsgiutils/static/favicon-32x32.png,sha256=i4ucx08zAZARd8e7JTMGK-gb5WcOmyuDN6IN4brsEOo,1216
|
|
59
59
|
c2cwsgiutils/stats_pyramid/__init__.py,sha256=0NizIUbaPbNf6bPye7pGrF9AaFerIN30EhEMts1XgfY,801
|
|
60
|
-
c2cwsgiutils/stats_pyramid/_db_spy.py,sha256=
|
|
60
|
+
c2cwsgiutils/stats_pyramid/_db_spy.py,sha256=wc1oEXnsKI31d4aoU8bvnbwqI-T-bOlVR03oZX-bRBg,3228
|
|
61
61
|
c2cwsgiutils/stats_pyramid/_pyramid_spy.py,sha256=KFxxKdEKrmDeA1zpps-BPiB2c4hhR2GlgJvq6KOTyjU,3498
|
|
62
62
|
c2cwsgiutils/templates/index.html.mako,sha256=Yqf6xkq-RtlUnHBAmJFMCJO_XwqGVDQfSjOTx3p70_o,1416
|
|
63
63
|
c2cwsgiutils/version.py,sha256=b8rwN7vATtBWvVKyvxW_-ixbmMJGQBZhW3gNvGdAyVg,3156
|
|
64
|
-
c2cwsgiutils-6.2.0.
|
|
65
|
-
c2cwsgiutils-6.2.0.
|
|
66
|
-
c2cwsgiutils-6.2.0.
|
|
67
|
-
c2cwsgiutils-6.2.0.
|
|
68
|
-
c2cwsgiutils-6.2.0.
|
|
64
|
+
c2cwsgiutils-6.2.0.dev158.dist-info/METADATA,sha256=C9mhuNt4KkE88wd8EX5xUhikTZJeBaCXG_G_bsrAljw,37599
|
|
65
|
+
c2cwsgiutils-6.2.0.dev158.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
66
|
+
c2cwsgiutils-6.2.0.dev158.dist-info/entry_points.txt,sha256=ujgqMTL1awN9qDg8WXmrF7m0fgR-hslUM6zKH86pvy0,703
|
|
67
|
+
c2cwsgiutils-6.2.0.dev158.dist-info/licenses/LICENSE,sha256=6bEOU0n7ued3SA-DQCsHQaACONMMRzGHmH5XhDVeD-U,1304
|
|
68
|
+
c2cwsgiutils-6.2.0.dev158.dist-info/RECORD,,
|
{c2cwsgiutils-6.2.0.dev153.dist-info → c2cwsgiutils-6.2.0.dev158.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{c2cwsgiutils-6.2.0.dev153.dist-info → c2cwsgiutils-6.2.0.dev158.dist-info/licenses}/LICENSE
RENAMED
|
File without changes
|