kinto 21.0.0__py3-none-any.whl → 21.1.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/__init__.py +1 -1
- kinto/config/__init__.py +23 -0
- kinto/core/views/hello.py +4 -0
- kinto/plugins/prometheus.py +26 -3
- {kinto-21.0.0.dist-info → kinto-21.1.0.dist-info}/METADATA +1 -1
- {kinto-21.0.0.dist-info → kinto-21.1.0.dist-info}/RECORD +10 -10
- {kinto-21.0.0.dist-info → kinto-21.1.0.dist-info}/WHEEL +0 -0
- {kinto-21.0.0.dist-info → kinto-21.1.0.dist-info}/entry_points.txt +0 -0
- {kinto-21.0.0.dist-info → kinto-21.1.0.dist-info}/licenses/LICENSE +0 -0
- {kinto-21.0.0.dist-info → kinto-21.1.0.dist-info}/top_level.txt +0 -0
kinto/__init__.py
CHANGED
kinto/config/__init__.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import codecs
|
|
2
2
|
import logging
|
|
3
3
|
import os
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from functools import lru_cache
|
|
6
|
+
from hashlib import sha256
|
|
4
7
|
from time import strftime
|
|
5
8
|
|
|
6
9
|
from kinto import __version__
|
|
@@ -69,3 +72,23 @@ def init(config_file, backend, cache_backend, host="127.0.0.1"):
|
|
|
69
72
|
values.update(cache_backend_to_values[cache_backend])
|
|
70
73
|
|
|
71
74
|
render_template("kinto.tpl", config_file, **values)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@lru_cache(maxsize=1)
|
|
78
|
+
def config_attributes():
|
|
79
|
+
"""
|
|
80
|
+
Returns a hash of the config `.ini` file content.
|
|
81
|
+
The path is only known from `app.wsgi`, so we have to read
|
|
82
|
+
the environment variable again. Since tests are not run through
|
|
83
|
+
WSGI, then the variable is not set.
|
|
84
|
+
"""
|
|
85
|
+
# WARNING: this default value should be the same as `app.wsgi`
|
|
86
|
+
ini_path = os.environ.get("KINTO_INI", os.path.join(".", "config", "kinto.ini"))
|
|
87
|
+
if not os.path.exists(ini_path):
|
|
88
|
+
logger.error(f"Could not find config file at {ini_path}")
|
|
89
|
+
return None
|
|
90
|
+
return {
|
|
91
|
+
"path": ini_path,
|
|
92
|
+
"hash": sha256(open(ini_path, "rb").read()).hexdigest(),
|
|
93
|
+
"modified": datetime.fromtimestamp(os.path.getmtime(ini_path)).isoformat(),
|
|
94
|
+
}
|
kinto/core/views/hello.py
CHANGED
|
@@ -2,6 +2,7 @@ import colander
|
|
|
2
2
|
from pyramid.authorization import Authenticated
|
|
3
3
|
from pyramid.security import NO_PERMISSION_REQUIRED
|
|
4
4
|
|
|
5
|
+
from kinto.config import config_attributes
|
|
5
6
|
from kinto.core import Service
|
|
6
7
|
|
|
7
8
|
|
|
@@ -26,14 +27,17 @@ hello_response_schemas = {
|
|
|
26
27
|
def get_hello(request):
|
|
27
28
|
"""Return information regarding the current instance."""
|
|
28
29
|
settings = request.registry.settings
|
|
30
|
+
|
|
29
31
|
project_name = settings["project_name"]
|
|
30
32
|
project_version = settings["project_version"]
|
|
33
|
+
|
|
31
34
|
data = dict(
|
|
32
35
|
project_name=project_name,
|
|
33
36
|
project_version=project_version,
|
|
34
37
|
http_api_version=settings["http_api_version"],
|
|
35
38
|
project_docs=settings["project_docs"],
|
|
36
39
|
url=request.route_url(hello.name),
|
|
40
|
+
config=config_attributes(),
|
|
37
41
|
)
|
|
38
42
|
|
|
39
43
|
eos = get_eos(request)
|
kinto/plugins/prometheus.py
CHANGED
|
@@ -6,6 +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, aslist
|
|
9
10
|
from zope.interface import implementer
|
|
10
11
|
|
|
11
12
|
from kinto.core import metrics
|
|
@@ -102,7 +103,7 @@ class Timer:
|
|
|
102
103
|
|
|
103
104
|
@implementer(metrics.IMetricsService)
|
|
104
105
|
class PrometheusService:
|
|
105
|
-
def __init__(self, prefix=""):
|
|
106
|
+
def __init__(self, prefix="", exclude_labels=None):
|
|
106
107
|
prefix_clean = ""
|
|
107
108
|
if prefix:
|
|
108
109
|
# In GCP Console, the metrics are grouped by the first
|
|
@@ -111,10 +112,19 @@ class PrometheusService:
|
|
|
111
112
|
# (eg. `remote-settings` -> `remotesettings_`, `kinto_` -> `kinto_`)
|
|
112
113
|
prefix_clean = _fix_metric_name(prefix).replace("_", "") + "_"
|
|
113
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
|
+
]
|
|
114
123
|
|
|
115
124
|
def timer(self, key, value=None, labels=[]):
|
|
116
125
|
global _METRICS
|
|
117
126
|
key = self.prefix + key
|
|
127
|
+
labels = self._exclude_labels(labels)
|
|
118
128
|
|
|
119
129
|
if key not in _METRICS:
|
|
120
130
|
_METRICS[key] = prometheus_module.Histogram(
|
|
@@ -144,6 +154,7 @@ class PrometheusService:
|
|
|
144
154
|
def observe(self, key, value, labels=[]):
|
|
145
155
|
global _METRICS
|
|
146
156
|
key = self.prefix + key
|
|
157
|
+
labels = self._exclude_labels(labels)
|
|
147
158
|
|
|
148
159
|
if key not in _METRICS:
|
|
149
160
|
_METRICS[key] = prometheus_module.Summary(
|
|
@@ -184,6 +195,7 @@ class PrometheusService:
|
|
|
184
195
|
label_name, label_value = unique.rsplit(".", 1)
|
|
185
196
|
unique = [(label_name, label_value)]
|
|
186
197
|
|
|
198
|
+
unique = self._exclude_labels(unique)
|
|
187
199
|
labels = [
|
|
188
200
|
(_fix_metric_name(label_name), label_value) for label_name, label_value in unique
|
|
189
201
|
]
|
|
@@ -229,6 +241,11 @@ def includeme(config):
|
|
|
229
241
|
)
|
|
230
242
|
raise ConfigurationError(error_msg)
|
|
231
243
|
|
|
244
|
+
settings = config.get_settings()
|
|
245
|
+
|
|
246
|
+
if not asbool(settings.get("prometheus_created_metrics_enabled", True)):
|
|
247
|
+
prometheus_module.disable_created_metrics()
|
|
248
|
+
|
|
232
249
|
config.add_api_capability(
|
|
233
250
|
"prometheus",
|
|
234
251
|
description="Prometheus metrics.",
|
|
@@ -250,7 +267,13 @@ def includeme(config):
|
|
|
250
267
|
pass
|
|
251
268
|
_METRICS.clear()
|
|
252
269
|
|
|
253
|
-
settings = config.get_settings()
|
|
254
270
|
prefix = settings.get("prometheus_prefix", settings["project_name"])
|
|
255
271
|
|
|
256
|
-
|
|
272
|
+
# If we want to reduce the metrics cardinality, we can exclude certain
|
|
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
|
+
)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
kinto/__init__.py,sha256=
|
|
1
|
+
kinto/__init__.py,sha256=OLigXJoAE1frrLwNjfAnuuhgfRrk8yL_OrvZpguRzT8,3299
|
|
2
2
|
kinto/__main__.py,sha256=6XDjWYGtJ36qepn9Of4xL9zc35TfdSeEvHh3s26Aw9c,7913
|
|
3
3
|
kinto/authorization.py,sha256=i3ttdPTFGzE9CqUQmfC4rR_6dDZJu0jWJMLGl_jFzIE,4919
|
|
4
4
|
kinto/contribute.json,sha256=HT9QVB8rA8jWIREQoqWfMibfJXMAzbRsixW8F6O6cQY,792
|
|
5
5
|
kinto/events.py,sha256=NMPvKUdbi25aYHhu9svzQsrEZMa9nyO4mtuMZC5871Q,85
|
|
6
6
|
kinto/schema_validation.py,sha256=mtAmnl5HwiUsjS2gU8MKH4lkZ1380A5wZht-w9s5X7M,5306
|
|
7
|
-
kinto/config/__init__.py,sha256=
|
|
7
|
+
kinto/config/__init__.py,sha256=v3EySgWgyqLr2kV6sFkBVgnEgjHwyylbcgYIpdNveKQ,2979
|
|
8
8
|
kinto/config/kinto.tpl,sha256=Pm9p_oRsBlVoEXPVA2X6Wvv49jMOVv-27jw4rahVlwE,8201
|
|
9
9
|
kinto/core/__init__.py,sha256=s7PshdeKmpiqI5sW-zdC7p3Ig-e60w4kiUwlKi-impY,8655
|
|
10
10
|
kinto/core/authentication.py,sha256=HLA0kREC3GMEsrIsHsQYjVNztYfAF01kb8-pLboByFs,1527
|
|
@@ -95,12 +95,12 @@ kinto/core/views/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
|
|
|
95
95
|
kinto/core/views/batch.py,sha256=sWNn67YqfTbiqwpbwbm1QyumcVGi8aNhlT5AtLToElI,5657
|
|
96
96
|
kinto/core/views/errors.py,sha256=2uTy85UBQL1EDIMotzFBhVl14RmWwb3rupbsB0mycbs,6099
|
|
97
97
|
kinto/core/views/heartbeat.py,sha256=qidZ7fTvuPoJMo7miDnclAm_WsbgqubzsARrv9aCo5U,3336
|
|
98
|
-
kinto/core/views/hello.py,sha256=
|
|
98
|
+
kinto/core/views/hello.py,sha256=DipWK5EuuDOyUSHCGTGZKmNBbgyp_SHyPXUje6hc81E,2042
|
|
99
99
|
kinto/core/views/openapi.py,sha256=PgxplQX1D0zqzlvRxBvd5SzrNMJmsaLfDta_fh-Pr-A,958
|
|
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=WyE3jULDSMe35S4SJiKbh05AVGDyU9Hc-UR3-7baaGs,8957
|
|
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-21.
|
|
145
|
-
kinto-21.
|
|
146
|
-
kinto-21.
|
|
147
|
-
kinto-21.
|
|
148
|
-
kinto-21.
|
|
149
|
-
kinto-21.
|
|
144
|
+
kinto-21.1.0.dist-info/licenses/LICENSE,sha256=oNEIMTuTJzppR5ZEyi86yvvtSagveMYXTYFn56zF0Uk,561
|
|
145
|
+
kinto-21.1.0.dist-info/METADATA,sha256=rTspJQTHQ907FEjyjIM27a3XT_mxRQIILCnGfyZ3-S8,8731
|
|
146
|
+
kinto-21.1.0.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
|
147
|
+
kinto-21.1.0.dist-info/entry_points.txt,sha256=3KlqBWPKY81mrCe_oX0I5s1cRO7Q53nCLbnVr5P9LH4,85
|
|
148
|
+
kinto-21.1.0.dist-info/top_level.txt,sha256=EG_YmbZL6FAug9VwopG7JtF9SvH_r0DEnFp-3twPPys,6
|
|
149
|
+
kinto-21.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|