kinto 21.1.0__py3-none-any.whl → 22.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 +18 -17
- kinto/core/metrics.py +4 -4
- kinto/plugins/prometheus.py +8 -26
- {kinto-21.1.0.dist-info → kinto-22.0.0.dist-info}/METADATA +1 -1
- {kinto-21.1.0.dist-info → kinto-22.0.0.dist-info}/RECORD +9 -9
- {kinto-21.1.0.dist-info → kinto-22.0.0.dist-info}/WHEEL +1 -1
- {kinto-21.1.0.dist-info → kinto-22.0.0.dist-info}/entry_points.txt +0 -0
- {kinto-21.1.0.dist-info → kinto-22.0.0.dist-info}/licenses/LICENSE +0 -0
- {kinto-21.1.0.dist-info → kinto-22.0.0.dist-info}/top_level.txt +0 -0
kinto/core/initialization.py
CHANGED
|
@@ -472,10 +472,18 @@ def setup_metrics(config):
|
|
|
472
472
|
auth, user_id = user_id.split(":")
|
|
473
473
|
metrics_service.count("users", unique=[("auth", auth), ("userid", user_id)])
|
|
474
474
|
|
|
475
|
+
status = event.response.status_code
|
|
476
|
+
|
|
477
|
+
if status >= 400:
|
|
478
|
+
# Prevent random values of 404 responses to become label values.
|
|
479
|
+
request_matchdict = {}
|
|
480
|
+
else:
|
|
481
|
+
request_matchdict = dict(request.matchdict or {})
|
|
482
|
+
|
|
475
483
|
# Add extra labels to metrics, based on fields extracted from the request matchdict.
|
|
476
484
|
metrics_matchdict_fields = aslist(settings["metrics_matchdict_fields"])
|
|
477
485
|
# Turn the `id` field of object endpoints into `{resource}_id` (eg. `mushroom_id`, `bucket_id`)
|
|
478
|
-
enhanced_matchdict =
|
|
486
|
+
enhanced_matchdict = request_matchdict
|
|
479
487
|
try:
|
|
480
488
|
enhanced_matchdict[request.current_resource_name + "_id"] = enhanced_matchdict.get(
|
|
481
489
|
"id", ""
|
|
@@ -487,8 +495,6 @@ def setup_metrics(config):
|
|
|
487
495
|
(field, enhanced_matchdict.get(field, "")) for field in metrics_matchdict_fields
|
|
488
496
|
]
|
|
489
497
|
|
|
490
|
-
status = event.response.status_code
|
|
491
|
-
|
|
492
498
|
service = request.current_service
|
|
493
499
|
if service:
|
|
494
500
|
# Use the service name as endpoint if available.
|
|
@@ -501,16 +507,14 @@ def setup_metrics(config):
|
|
|
501
507
|
"unnamed" if status != 404 else "unknown"
|
|
502
508
|
) # Do not multiply cardinality for unknown endpoints.
|
|
503
509
|
|
|
510
|
+
request_labels = [
|
|
511
|
+
("method", request.method.lower()),
|
|
512
|
+
("endpoint", endpoint),
|
|
513
|
+
("status", str(status)),
|
|
514
|
+
] + metrics_matchdict_labels
|
|
515
|
+
|
|
504
516
|
# Count served requests.
|
|
505
|
-
metrics_service.count(
|
|
506
|
-
"request_summary",
|
|
507
|
-
unique=[
|
|
508
|
-
("method", request.method.lower()),
|
|
509
|
-
("endpoint", endpoint),
|
|
510
|
-
("status", str(status)),
|
|
511
|
-
]
|
|
512
|
-
+ metrics_matchdict_labels,
|
|
513
|
-
)
|
|
517
|
+
metrics_service.count("request_summary", unique=request_labels)
|
|
514
518
|
|
|
515
519
|
try:
|
|
516
520
|
current = utils.msec_time()
|
|
@@ -518,8 +522,7 @@ def setup_metrics(config):
|
|
|
518
522
|
metrics_service.timer(
|
|
519
523
|
"request_duration",
|
|
520
524
|
value=duration,
|
|
521
|
-
labels=
|
|
522
|
-
+ metrics_matchdict_labels,
|
|
525
|
+
labels=request_labels,
|
|
523
526
|
)
|
|
524
527
|
except AttributeError: # pragma: no cover
|
|
525
528
|
# Logging was not setup in this Kinto app (unlikely but possible)
|
|
@@ -527,9 +530,7 @@ def setup_metrics(config):
|
|
|
527
530
|
|
|
528
531
|
# Observe response size.
|
|
529
532
|
metrics_service.observe(
|
|
530
|
-
"request_size",
|
|
531
|
-
len(event.response.body or b""),
|
|
532
|
-
labels=[("endpoint", endpoint)] + metrics_matchdict_labels,
|
|
533
|
+
"request_size", len(event.response.body or b""), labels=request_labels
|
|
533
534
|
)
|
|
534
535
|
|
|
535
536
|
# Count authentication verifications.
|
kinto/core/metrics.py
CHANGED
|
@@ -13,7 +13,7 @@ class IMetricsService(Interface):
|
|
|
13
13
|
|
|
14
14
|
def timer(key):
|
|
15
15
|
"""
|
|
16
|
-
Watch execution time.
|
|
16
|
+
Watch execution time in seconds.
|
|
17
17
|
"""
|
|
18
18
|
|
|
19
19
|
def observe(self, key, value, labels=[]):
|
|
@@ -68,9 +68,9 @@ def watch_execution_time(metrics_service, obj, prefix="", classname=None):
|
|
|
68
68
|
method = getattr(obj, name)
|
|
69
69
|
is_method = isinstance(method, types.MethodType)
|
|
70
70
|
if not name.startswith("_") and is_method:
|
|
71
|
-
|
|
71
|
+
metric_name = f"{prefix}.{classname}.seconds"
|
|
72
72
|
labels = [("method", name)]
|
|
73
|
-
decorated_method = metrics_service.timer(
|
|
73
|
+
decorated_method = metrics_service.timer(metric_name, labels=labels)(method)
|
|
74
74
|
setattr(obj, name, decorated_method)
|
|
75
75
|
|
|
76
76
|
|
|
@@ -88,7 +88,7 @@ def listener_with_timer(config, key, func):
|
|
|
88
88
|
# not listed in the `initialization_sequence` setting.
|
|
89
89
|
return func(*args, **kwargs)
|
|
90
90
|
# If metrics are enabled, monitor execution time of listeners.
|
|
91
|
-
with metrics_service.timer(key):
|
|
91
|
+
with metrics_service.timer(key + ".seconds" if not key.endswith(".seconds") else key):
|
|
92
92
|
return func(*args, **kwargs)
|
|
93
93
|
|
|
94
94
|
return wrapped
|
kinto/plugins/prometheus.py
CHANGED
|
@@ -6,7 +6,7 @@ from time import perf_counter as time_now
|
|
|
6
6
|
|
|
7
7
|
from pyramid.exceptions import ConfigurationError
|
|
8
8
|
from pyramid.response import Response
|
|
9
|
-
from pyramid.settings import asbool
|
|
9
|
+
from pyramid.settings import asbool
|
|
10
10
|
from zope.interface import implementer
|
|
11
11
|
|
|
12
12
|
from kinto.core import metrics
|
|
@@ -53,7 +53,7 @@ class Timer:
|
|
|
53
53
|
"""
|
|
54
54
|
A decorator to time the execution of a function. It will use the
|
|
55
55
|
`prometheus_client.Histogram` to record the time taken by the function
|
|
56
|
-
in
|
|
56
|
+
in seconds. The histogram is passed as an argument to the
|
|
57
57
|
constructor.
|
|
58
58
|
|
|
59
59
|
Main limitation: it does not support `labels` on the decorator.
|
|
@@ -78,8 +78,8 @@ class Timer:
|
|
|
78
78
|
try:
|
|
79
79
|
return f(*args, **kwargs)
|
|
80
80
|
finally:
|
|
81
|
-
|
|
82
|
-
self.histogram.observe(
|
|
81
|
+
dt_sec = time_now() - start_time
|
|
82
|
+
self.histogram.observe(dt_sec)
|
|
83
83
|
|
|
84
84
|
return _wrapped
|
|
85
85
|
|
|
@@ -96,14 +96,14 @@ class Timer:
|
|
|
96
96
|
def stop(self):
|
|
97
97
|
if self._start_time is None: # pragma: nocover
|
|
98
98
|
raise RuntimeError("Timer has not started.")
|
|
99
|
-
|
|
100
|
-
self.histogram.observe(
|
|
99
|
+
dt_sec = time_now() - self._start_time
|
|
100
|
+
self.histogram.observe(dt_sec)
|
|
101
101
|
return self
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
@implementer(metrics.IMetricsService)
|
|
105
105
|
class PrometheusService:
|
|
106
|
-
def __init__(self, prefix=""
|
|
106
|
+
def __init__(self, prefix=""):
|
|
107
107
|
prefix_clean = ""
|
|
108
108
|
if prefix:
|
|
109
109
|
# In GCP Console, the metrics are grouped by the first
|
|
@@ -112,19 +112,10 @@ class PrometheusService:
|
|
|
112
112
|
# (eg. `remote-settings` -> `remotesettings_`, `kinto_` -> `kinto_`)
|
|
113
113
|
prefix_clean = _fix_metric_name(prefix).replace("_", "") + "_"
|
|
114
114
|
self.prefix = prefix_clean.lower()
|
|
115
|
-
self.exclude_labels = exclude_labels or []
|
|
116
|
-
|
|
117
|
-
def _exclude_labels(self, labels):
|
|
118
|
-
return [
|
|
119
|
-
(label_name, label_value)
|
|
120
|
-
for label_name, label_value in labels
|
|
121
|
-
if label_name not in self.exclude_labels
|
|
122
|
-
]
|
|
123
115
|
|
|
124
116
|
def timer(self, key, value=None, labels=[]):
|
|
125
117
|
global _METRICS
|
|
126
118
|
key = self.prefix + key
|
|
127
|
-
labels = self._exclude_labels(labels)
|
|
128
119
|
|
|
129
120
|
if key not in _METRICS:
|
|
130
121
|
_METRICS[key] = prometheus_module.Histogram(
|
|
@@ -154,7 +145,6 @@ class PrometheusService:
|
|
|
154
145
|
def observe(self, key, value, labels=[]):
|
|
155
146
|
global _METRICS
|
|
156
147
|
key = self.prefix + key
|
|
157
|
-
labels = self._exclude_labels(labels)
|
|
158
148
|
|
|
159
149
|
if key not in _METRICS:
|
|
160
150
|
_METRICS[key] = prometheus_module.Summary(
|
|
@@ -195,7 +185,6 @@ class PrometheusService:
|
|
|
195
185
|
label_name, label_value = unique.rsplit(".", 1)
|
|
196
186
|
unique = [(label_name, label_value)]
|
|
197
187
|
|
|
198
|
-
unique = self._exclude_labels(unique)
|
|
199
188
|
labels = [
|
|
200
189
|
(_fix_metric_name(label_name), label_value) for label_name, label_value in unique
|
|
201
190
|
]
|
|
@@ -269,11 +258,4 @@ def includeme(config):
|
|
|
269
258
|
|
|
270
259
|
prefix = settings.get("prometheus_prefix", settings["project_name"])
|
|
271
260
|
|
|
272
|
-
|
|
273
|
-
# labels (eg. records_id). This way all metrics will be grouped by the
|
|
274
|
-
# remaining labels.
|
|
275
|
-
exclude_labels = aslist(settings.get("prometheus_exclude_labels", ""))
|
|
276
|
-
|
|
277
|
-
config.registry.registerUtility(
|
|
278
|
-
PrometheusService(prefix=prefix, exclude_labels=exclude_labels), metrics.IMetricsService
|
|
279
|
-
)
|
|
261
|
+
config.registry.registerUtility(PrometheusService(prefix=prefix), metrics.IMetricsService)
|
|
@@ -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=OMnwre6roy_JkOCA0wf47wUJv7erxOfACI9CT78tD5k,26329
|
|
16
|
+
kinto/core/metrics.py,sha256=wlTThw_pSESrgwJfGdVBcM3r0b09gleZV4aSiu5pWq8,2768
|
|
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,7 +100,7 @@ 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=
|
|
103
|
+
kinto/plugins/prometheus.py,sha256=xoqCnJEF2dmGxZFN5Fql2bSMWaNFDYAdR94Yik-gKLM,8209
|
|
104
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
|
|
@@ -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-22.0.0.dist-info/licenses/LICENSE,sha256=oNEIMTuTJzppR5ZEyi86yvvtSagveMYXTYFn56zF0Uk,561
|
|
145
|
+
kinto-22.0.0.dist-info/METADATA,sha256=CQoL_8oC-kdhnfzaaywv5fZgTW4riJrSrGywkzRxFLU,8731
|
|
146
|
+
kinto-22.0.0.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
|
147
|
+
kinto-22.0.0.dist-info/entry_points.txt,sha256=3KlqBWPKY81mrCe_oX0I5s1cRO7Q53nCLbnVr5P9LH4,85
|
|
148
|
+
kinto-22.0.0.dist-info/top_level.txt,sha256=EG_YmbZL6FAug9VwopG7JtF9SvH_r0DEnFp-3twPPys,6
|
|
149
|
+
kinto-22.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|