kinto 20.6.0__py3-none-any.whl → 21.0.0__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 kinto might be problematic. Click here for more details.
- kinto/core/initialization.py +24 -20
- kinto/core/metrics.py +6 -5
- kinto/plugins/prometheus.py +41 -12
- kinto/plugins/statsd.py +8 -1
- {kinto-20.6.0.dist-info → kinto-21.0.0.dist-info}/METADATA +1 -1
- {kinto-20.6.0.dist-info → kinto-21.0.0.dist-info}/RECORD +10 -10
- {kinto-20.6.0.dist-info → kinto-21.0.0.dist-info}/WHEEL +1 -1
- {kinto-20.6.0.dist-info → kinto-21.0.0.dist-info}/entry_points.txt +0 -0
- {kinto-20.6.0.dist-info → kinto-21.0.0.dist-info}/licenses/LICENSE +0 -0
- {kinto-20.6.0.dist-info → kinto-21.0.0.dist-info}/top_level.txt +0 -0
kinto/core/initialization.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import random
|
|
3
3
|
import re
|
|
4
|
-
import urllib.parse
|
|
5
4
|
import warnings
|
|
6
5
|
from datetime import datetime
|
|
7
6
|
|
|
@@ -466,14 +465,6 @@ def setup_metrics(config):
|
|
|
466
465
|
request = event.request
|
|
467
466
|
metrics_service = config.registry.metrics
|
|
468
467
|
|
|
469
|
-
try:
|
|
470
|
-
endpoint = utils.strip_uri_prefix(request.path)
|
|
471
|
-
endpoint = urllib.parse.quote_plus(endpoint, safe="/?&=-_")
|
|
472
|
-
except UnicodeDecodeError as e:
|
|
473
|
-
# This `on_new_response` callback is also called when a HTTP 400
|
|
474
|
-
# is returned because of an invalid UTF-8 path. We still want metrics.
|
|
475
|
-
endpoint = str(e)
|
|
476
|
-
|
|
477
468
|
# Count unique users.
|
|
478
469
|
user_id = request.prefixed_userid
|
|
479
470
|
if user_id:
|
|
@@ -496,13 +487,27 @@ def setup_metrics(config):
|
|
|
496
487
|
(field, enhanced_matchdict.get(field, "")) for field in metrics_matchdict_fields
|
|
497
488
|
]
|
|
498
489
|
|
|
490
|
+
status = event.response.status_code
|
|
491
|
+
|
|
492
|
+
service = request.current_service
|
|
493
|
+
if service:
|
|
494
|
+
# Use the service name as endpoint if available.
|
|
495
|
+
endpoint = service.name
|
|
496
|
+
elif route := request.matched_route:
|
|
497
|
+
# Use the route name as endpoint if we're not on a Cornice service.
|
|
498
|
+
endpoint = route.name
|
|
499
|
+
else:
|
|
500
|
+
endpoint = (
|
|
501
|
+
"unnamed" if status != 404 else "unknown"
|
|
502
|
+
) # Do not multiply cardinality for unknown endpoints.
|
|
503
|
+
|
|
499
504
|
# Count served requests.
|
|
500
505
|
metrics_service.count(
|
|
501
506
|
"request_summary",
|
|
502
507
|
unique=[
|
|
503
508
|
("method", request.method.lower()),
|
|
504
509
|
("endpoint", endpoint),
|
|
505
|
-
("status", str(
|
|
510
|
+
("status", str(status)),
|
|
506
511
|
]
|
|
507
512
|
+ metrics_matchdict_labels,
|
|
508
513
|
)
|
|
@@ -510,10 +515,11 @@ def setup_metrics(config):
|
|
|
510
515
|
try:
|
|
511
516
|
current = utils.msec_time()
|
|
512
517
|
duration = current - request._received_at
|
|
513
|
-
metrics_service.
|
|
518
|
+
metrics_service.timer(
|
|
514
519
|
"request_duration",
|
|
515
|
-
duration,
|
|
516
|
-
labels=[("endpoint", endpoint)
|
|
520
|
+
value=duration,
|
|
521
|
+
labels=[("endpoint", endpoint), ("method", request.method.lower())]
|
|
522
|
+
+ metrics_matchdict_labels,
|
|
517
523
|
)
|
|
518
524
|
except AttributeError: # pragma: no cover
|
|
519
525
|
# Logging was not setup in this Kinto app (unlikely but possible)
|
|
@@ -527,13 +533,11 @@ def setup_metrics(config):
|
|
|
527
533
|
)
|
|
528
534
|
|
|
529
535
|
# Count authentication verifications.
|
|
530
|
-
|
|
531
|
-
metrics_service.count(
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
if service:
|
|
536
|
-
metrics_service.count(f"view.{service.name}.{request.method}")
|
|
536
|
+
try:
|
|
537
|
+
metrics_service.count("authentication", unique=[("type", request.authn_type)])
|
|
538
|
+
except AttributeError:
|
|
539
|
+
# Not authenticated
|
|
540
|
+
pass
|
|
537
541
|
|
|
538
542
|
config.add_subscriber(on_new_response, NewResponse)
|
|
539
543
|
|
kinto/core/metrics.py
CHANGED
|
@@ -47,7 +47,7 @@ class NoOpTimer:
|
|
|
47
47
|
|
|
48
48
|
@implementer(IMetricsService)
|
|
49
49
|
class NoOpMetricsService:
|
|
50
|
-
def timer(self, key):
|
|
50
|
+
def timer(self, key, value=None, labels=[]):
|
|
51
51
|
return NoOpTimer()
|
|
52
52
|
|
|
53
53
|
def observe(self, key, value, labels=[]):
|
|
@@ -65,11 +65,12 @@ def watch_execution_time(metrics_service, obj, prefix="", classname=None):
|
|
|
65
65
|
classname = classname or utils.classname(obj)
|
|
66
66
|
members = dir(obj)
|
|
67
67
|
for name in members:
|
|
68
|
-
|
|
69
|
-
is_method = isinstance(
|
|
68
|
+
method = getattr(obj, name)
|
|
69
|
+
is_method = isinstance(method, types.MethodType)
|
|
70
70
|
if not name.startswith("_") and is_method:
|
|
71
|
-
statsd_key = f"{prefix}.{classname}
|
|
72
|
-
|
|
71
|
+
statsd_key = f"{prefix}.{classname}"
|
|
72
|
+
labels = [("method", name)]
|
|
73
|
+
decorated_method = metrics_service.timer(statsd_key, labels=labels)(method)
|
|
73
74
|
setattr(obj, name, decorated_method)
|
|
74
75
|
|
|
75
76
|
|
kinto/plugins/prometheus.py
CHANGED
|
@@ -49,10 +49,27 @@ def _fix_metric_name(s):
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
class Timer:
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
"""
|
|
53
|
+
A decorator to time the execution of a function. It will use the
|
|
54
|
+
`prometheus_client.Histogram` to record the time taken by the function
|
|
55
|
+
in milliseconds. The histogram is passed as an argument to the
|
|
56
|
+
constructor.
|
|
57
|
+
|
|
58
|
+
Main limitation: it does not support `labels` on the decorator.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def __init__(self, histogram):
|
|
62
|
+
self.histogram = histogram
|
|
54
63
|
self._start_time = None
|
|
55
64
|
|
|
65
|
+
def set_labels(self, labels):
|
|
66
|
+
if not labels:
|
|
67
|
+
return
|
|
68
|
+
self.histogram = self.histogram.labels(*(label_value for _, label_value in labels))
|
|
69
|
+
|
|
70
|
+
def observe(self, value):
|
|
71
|
+
return self.histogram.observe(value)
|
|
72
|
+
|
|
56
73
|
def __call__(self, f):
|
|
57
74
|
@safe_wraps(f)
|
|
58
75
|
def _wrapped(*args, **kwargs):
|
|
@@ -61,7 +78,7 @@ class Timer:
|
|
|
61
78
|
return f(*args, **kwargs)
|
|
62
79
|
finally:
|
|
63
80
|
dt_ms = 1000.0 * (time_now() - start_time)
|
|
64
|
-
self.
|
|
81
|
+
self.histogram.observe(dt_ms)
|
|
65
82
|
|
|
66
83
|
return _wrapped
|
|
67
84
|
|
|
@@ -79,7 +96,7 @@ class Timer:
|
|
|
79
96
|
if self._start_time is None: # pragma: nocover
|
|
80
97
|
raise RuntimeError("Timer has not started.")
|
|
81
98
|
dt_ms = 1000.0 * (time_now() - self._start_time)
|
|
82
|
-
self.
|
|
99
|
+
self.histogram.observe(dt_ms)
|
|
83
100
|
return self
|
|
84
101
|
|
|
85
102
|
|
|
@@ -95,21 +112,34 @@ class PrometheusService:
|
|
|
95
112
|
prefix_clean = _fix_metric_name(prefix).replace("_", "") + "_"
|
|
96
113
|
self.prefix = prefix_clean.lower()
|
|
97
114
|
|
|
98
|
-
def timer(self, key):
|
|
115
|
+
def timer(self, key, value=None, labels=[]):
|
|
99
116
|
global _METRICS
|
|
100
117
|
key = self.prefix + key
|
|
101
118
|
|
|
102
119
|
if key not in _METRICS:
|
|
103
|
-
_METRICS[key] = prometheus_module.
|
|
104
|
-
_fix_metric_name(key),
|
|
120
|
+
_METRICS[key] = prometheus_module.Histogram(
|
|
121
|
+
_fix_metric_name(key),
|
|
122
|
+
f"Histogram of {key}",
|
|
123
|
+
registry=get_registry(),
|
|
124
|
+
labelnames=[label_name for label_name, _ in labels],
|
|
105
125
|
)
|
|
106
126
|
|
|
107
|
-
if not isinstance(_METRICS[key], prometheus_module.
|
|
127
|
+
if not isinstance(_METRICS[key], prometheus_module.Histogram):
|
|
108
128
|
raise RuntimeError(
|
|
109
129
|
f"Metric {key} already exists with different type ({_METRICS[key]})"
|
|
110
130
|
)
|
|
111
131
|
|
|
112
|
-
|
|
132
|
+
timer = Timer(_METRICS[key])
|
|
133
|
+
timer.set_labels(labels)
|
|
134
|
+
|
|
135
|
+
if value is not None:
|
|
136
|
+
# We are timing something.
|
|
137
|
+
return timer.observe(value)
|
|
138
|
+
|
|
139
|
+
# We are not timing anything, just returning the timer object
|
|
140
|
+
# (eg. to be used as decorator or context manager).
|
|
141
|
+
# Note that in this case, the labels values will be the same for all calls.
|
|
142
|
+
return timer
|
|
113
143
|
|
|
114
144
|
def observe(self, key, value, labels=[]):
|
|
115
145
|
global _METRICS
|
|
@@ -188,9 +218,8 @@ def metrics_view(request):
|
|
|
188
218
|
|
|
189
219
|
|
|
190
220
|
def _reset_multiproc_folder_content(): # pragma: no cover
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
os.mkdir(PROMETHEUS_MULTIPROC_DIR)
|
|
221
|
+
shutil.rmtree(PROMETHEUS_MULTIPROC_DIR, ignore_errors=True)
|
|
222
|
+
os.makedirs(PROMETHEUS_MULTIPROC_DIR, exist_ok=True)
|
|
194
223
|
|
|
195
224
|
|
|
196
225
|
def includeme(config):
|
kinto/plugins/statsd.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import warnings
|
|
2
|
+
from datetime import timedelta
|
|
2
3
|
from urllib.parse import urlparse
|
|
3
4
|
|
|
4
5
|
from pyramid.exceptions import ConfigurationError
|
|
@@ -26,7 +27,13 @@ class StatsDService:
|
|
|
26
27
|
def __init__(self, host, port, prefix):
|
|
27
28
|
self._client = statsd_module.StatsClient(host, port, prefix=prefix)
|
|
28
29
|
|
|
29
|
-
def timer(self, key):
|
|
30
|
+
def timer(self, key, value=None, labels=[]):
|
|
31
|
+
if labels:
|
|
32
|
+
# [("method", "get")] -> "method.get"
|
|
33
|
+
key = f"{key}." + ".".join(f"{label[0]}.{sanitize(label[1])}" for label in labels)
|
|
34
|
+
if value:
|
|
35
|
+
value = timedelta(seconds=value)
|
|
36
|
+
return self._client.timing(key, value)
|
|
30
37
|
return self._client.timer(key)
|
|
31
38
|
|
|
32
39
|
def observe(self, key, value, labels=[]):
|
|
@@ -12,8 +12,8 @@ kinto/core/authorization.py,sha256=GywY25KEzuSSAI709dFHDfdLnKxy3SLEYGwW5FkQ7Qc,1
|
|
|
12
12
|
kinto/core/decorators.py,sha256=3SAPWXlyPNUSICZ9mz04bcN-UdbnDuFOtU0bQHHzLis,2178
|
|
13
13
|
kinto/core/errors.py,sha256=JXZjkPYjjC0I6x02d2VJRGeaQ2yZYS2zm5o7_ljfyes,8946
|
|
14
14
|
kinto/core/events.py,sha256=SYpXgKMtVjiD9fwYJA2Omdom9yA3nBqi9btdvU1I_nc,10345
|
|
15
|
-
kinto/core/initialization.py,sha256=
|
|
16
|
-
kinto/core/metrics.py,sha256=
|
|
15
|
+
kinto/core/initialization.py,sha256=1m3lFLjFpApLKRXBa650GkYkR5u71ZUJRGogRYyo0Vs,26299
|
|
16
|
+
kinto/core/metrics.py,sha256=h582cAZawzgJ9AL16t1ScgyVi0trXoJx-6147Ig-Vns,2693
|
|
17
17
|
kinto/core/openapi.py,sha256=92sZviff4NCxN0jMnu5lPUnF5iQbrKMGy7Cegf-VAME,3876
|
|
18
18
|
kinto/core/schema.py,sha256=d5L5TQynRYJPkZ8Mu2X7F72xEh6SKDbrHK1CNTdOf2E,3646
|
|
19
19
|
kinto/core/scripts.py,sha256=02SXVjo579W82AsDF8dyVCRxYVcrMFkjjaNVIgLChh0,1412
|
|
@@ -100,8 +100,8 @@ kinto/core/views/openapi.py,sha256=PgxplQX1D0zqzlvRxBvd5SzrNMJmsaLfDta_fh-Pr-A,9
|
|
|
100
100
|
kinto/core/views/version.py,sha256=-m5G_o0oHTpCgrtfFrHFve6Zqw_gs_szT0Bd8jnNmD4,1419
|
|
101
101
|
kinto/plugins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
102
102
|
kinto/plugins/flush.py,sha256=poiBOLGXjml0xXHjqDMRdbXJSd6N3SL0mfeGK2vxeHY,812
|
|
103
|
-
kinto/plugins/prometheus.py,sha256=
|
|
104
|
-
kinto/plugins/statsd.py,sha256
|
|
103
|
+
kinto/plugins/prometheus.py,sha256=Isr8mhDJHG5pcAC0_1RtFnbZHko1iCfw-cQicFkqVIU,8065
|
|
104
|
+
kinto/plugins/statsd.py,sha256=k9sewYZUwm60k9Z799VxbShBP3uPwGVlImaGCPnIrkE,2801
|
|
105
105
|
kinto/plugins/accounts/__init__.py,sha256=2DeIaXJmMqRca3xVHeJ6xBWmeXAfrCdyg3EvK5jzIak,3670
|
|
106
106
|
kinto/plugins/accounts/authentication.py,sha256=pCb269FquKGFd6DH8AVTjFnBFlfxcDEYVyxhQp5Y08o,2117
|
|
107
107
|
kinto/plugins/accounts/scripts.py,sha256=_LNkSpFprOMGHFKkRmmOqK31uoQW28yttPQztmfUt5Q,2001
|
|
@@ -141,9 +141,9 @@ kinto/views/contribute.py,sha256=PJoIMLj9_IszSjgZkaCd_TUjekDgNqjpmVTmRN9ztaA,983
|
|
|
141
141
|
kinto/views/groups.py,sha256=jOq5fX0-4lwZE8k1q5HME2tU7x9052rtBPF7YqcJ-Qg,3181
|
|
142
142
|
kinto/views/permissions.py,sha256=F0_eKx201WyLonXJ5vLdGKa9RcFKjvAihrEEhU1JuLw,9069
|
|
143
143
|
kinto/views/records.py,sha256=lYfACW2L8qcQoyYBD5IX-fTPjFWmGp7GjHq_U4InlyE,5037
|
|
144
|
-
kinto-
|
|
145
|
-
kinto-
|
|
146
|
-
kinto-
|
|
147
|
-
kinto-
|
|
148
|
-
kinto-
|
|
149
|
-
kinto-
|
|
144
|
+
kinto-21.0.0.dist-info/licenses/LICENSE,sha256=oNEIMTuTJzppR5ZEyi86yvvtSagveMYXTYFn56zF0Uk,561
|
|
145
|
+
kinto-21.0.0.dist-info/METADATA,sha256=rn2hxy6jgnxDk8FMz_kKe_ammE_kfHpmJ5ieV5G2XtE,8731
|
|
146
|
+
kinto-21.0.0.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
|
147
|
+
kinto-21.0.0.dist-info/entry_points.txt,sha256=3KlqBWPKY81mrCe_oX0I5s1cRO7Q53nCLbnVr5P9LH4,85
|
|
148
|
+
kinto-21.0.0.dist-info/top_level.txt,sha256=EG_YmbZL6FAug9VwopG7JtF9SvH_r0DEnFp-3twPPys,6
|
|
149
|
+
kinto-21.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|