kinto 22.0.0__py3-none-any.whl → 23.0.1__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.

@@ -510,17 +510,16 @@ def setup_metrics(config):
510
510
  request_labels = [
511
511
  ("method", request.method.lower()),
512
512
  ("endpoint", endpoint),
513
- ("status", str(status)),
514
513
  ] + metrics_matchdict_labels
515
514
 
516
515
  # Count served requests.
517
- metrics_service.count("request_summary", unique=request_labels)
516
+ metrics_service.count("request_summary", unique=request_labels + [("status", str(status))])
518
517
 
519
518
  try:
520
519
  current = utils.msec_time()
521
- duration = current - request._received_at
520
+ duration = (current - request._received_at) / 1000
522
521
  metrics_service.timer(
523
- "request_duration",
522
+ "request_duration_seconds",
524
523
  value=duration,
525
524
  labels=request_labels,
526
525
  )
@@ -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, aslist
10
10
  from zope.interface import implementer
11
11
 
12
12
  from kinto.core import metrics
@@ -101,9 +101,17 @@ class Timer:
101
101
  return self
102
102
 
103
103
 
104
+ class NoOpHistogram: # pragma: no cover
105
+ def observe(self, value):
106
+ pass
107
+
108
+ def labels(self, *args):
109
+ return self
110
+
111
+
104
112
  @implementer(metrics.IMetricsService)
105
113
  class PrometheusService:
106
- def __init__(self, prefix=""):
114
+ def __init__(self, prefix="", disabled_metrics=[], histogram_buckets=None):
107
115
  prefix_clean = ""
108
116
  if prefix:
109
117
  # In GCP Console, the metrics are grouped by the first
@@ -112,17 +120,23 @@ class PrometheusService:
112
120
  # (eg. `remote-settings` -> `remotesettings_`, `kinto_` -> `kinto_`)
113
121
  prefix_clean = _fix_metric_name(prefix).replace("_", "") + "_"
114
122
  self.prefix = prefix_clean.lower()
123
+ self.disabled_metrics = [m.replace(self.prefix, "") for m in disabled_metrics]
124
+ self.histogram_buckets = histogram_buckets
115
125
 
116
126
  def timer(self, key, value=None, labels=[]):
117
127
  global _METRICS
118
- key = self.prefix + key
119
128
 
129
+ key = _fix_metric_name(key)
130
+ if key in self.disabled_metrics:
131
+ return Timer(histogram=NoOpHistogram())
132
+
133
+ key = self.prefix + key
120
134
  if key not in _METRICS:
121
135
  _METRICS[key] = prometheus_module.Histogram(
122
- _fix_metric_name(key),
136
+ key,
123
137
  f"Histogram of {key}",
124
- registry=get_registry(),
125
138
  labelnames=[label_name for label_name, _ in labels],
139
+ buckets=self.histogram_buckets,
126
140
  )
127
141
 
128
142
  if not isinstance(_METRICS[key], prometheus_module.Histogram):
@@ -130,7 +144,7 @@ class PrometheusService:
130
144
  f"Metric {key} already exists with different type ({_METRICS[key]})"
131
145
  )
132
146
 
133
- timer = Timer(_METRICS[key])
147
+ timer = Timer(histogram=_METRICS[key])
134
148
  timer.set_labels(labels)
135
149
 
136
150
  if value is not None:
@@ -144,14 +158,17 @@ class PrometheusService:
144
158
 
145
159
  def observe(self, key, value, labels=[]):
146
160
  global _METRICS
147
- key = self.prefix + key
148
161
 
162
+ key = _fix_metric_name(key)
163
+ if key in self.disabled_metrics:
164
+ return
165
+
166
+ key = self.prefix + key
149
167
  if key not in _METRICS:
150
168
  _METRICS[key] = prometheus_module.Summary(
151
- _fix_metric_name(key),
169
+ key,
152
170
  f"Summary of {key}",
153
171
  labelnames=[label_name for label_name, _ in labels],
154
- registry=get_registry(),
155
172
  )
156
173
 
157
174
  if not isinstance(_METRICS[key], prometheus_module.Summary):
@@ -167,10 +184,12 @@ class PrometheusService:
167
184
 
168
185
  def count(self, key, count=1, unique=None):
169
186
  global _METRICS
170
- key = self.prefix + key
171
187
 
172
- labels = []
188
+ key = _fix_metric_name(key)
189
+ if key in self.disabled_metrics:
190
+ return
173
191
 
192
+ labels = []
174
193
  if unique:
175
194
  if isinstance(unique, str):
176
195
  warnings.warn(
@@ -189,12 +208,12 @@ class PrometheusService:
189
208
  (_fix_metric_name(label_name), label_value) for label_name, label_value in unique
190
209
  ]
191
210
 
211
+ key = self.prefix + key
192
212
  if key not in _METRICS:
193
213
  _METRICS[key] = prometheus_module.Counter(
194
- _fix_metric_name(key),
214
+ key,
195
215
  f"Counter of {key}",
196
216
  labelnames=[label_name for label_name, _ in labels],
197
- registry=get_registry(),
198
217
  )
199
218
 
200
219
  if not isinstance(_METRICS[key], prometheus_module.Counter):
@@ -223,6 +242,19 @@ def _reset_multiproc_folder_content(): # pragma: no cover
223
242
  os.makedirs(PROMETHEUS_MULTIPROC_DIR, exist_ok=True)
224
243
 
225
244
 
245
+ def reset_registry():
246
+ # This is mainly useful in tests, where the plugin is included
247
+ # several times with different settings.
248
+ registry = get_registry()
249
+
250
+ for collector in _METRICS.values():
251
+ try:
252
+ registry.unregister(collector)
253
+ except KeyError: # pragma: no cover
254
+ pass
255
+ _METRICS.clear()
256
+
257
+
226
258
  def includeme(config):
227
259
  if prometheus_module is None:
228
260
  error_msg = (
@@ -235,27 +267,34 @@ def includeme(config):
235
267
  if not asbool(settings.get("prometheus_created_metrics_enabled", True)):
236
268
  prometheus_module.disable_created_metrics()
237
269
 
270
+ prefix = settings.get("prometheus_prefix", settings["project_name"])
271
+ disabled_metrics = aslist(settings.get("prometheus_disabled_metrics", ""))
272
+
273
+ # Default buckets for histogram metrics are (.005, .01, .025, .05, .075, .1, .25, .5, .75, 1.0, 2.5, 5.0, 7.5, 10.0, INF)
274
+ # we reduce it from 15 to 8 values by default here, and let the user override it if needed.
275
+ histogram_buckets_values = aslist(
276
+ settings.get(
277
+ "prometheus_histogram_buckets", "0.01 0.05 0.1 0.5 1.0 3.0 6.0 Inf"
278
+ ) # Note: Inf is added by default.
279
+ )
280
+ histogram_buckets = [float(x) for x in histogram_buckets_values]
281
+ # Note: we don't need to check for INF or list size, it's done in the prometheus_client library.
282
+
283
+ get_registry() # Initialize the registry.
284
+
285
+ metrics_impl = PrometheusService(
286
+ prefix=prefix, disabled_metrics=disabled_metrics, histogram_buckets=histogram_buckets
287
+ )
288
+
238
289
  config.add_api_capability(
239
290
  "prometheus",
240
291
  description="Prometheus metrics.",
241
292
  url="https://github.com/Kinto/kinto/",
293
+ prefix=metrics_impl.prefix,
294
+ disabled_metrics=disabled_metrics,
242
295
  )
243
296
 
244
297
  config.add_route("prometheus_metrics", "/__metrics__")
245
298
  config.add_view(metrics_view, route_name="prometheus_metrics")
246
299
 
247
- # Reinitialize the registry on initialization.
248
- # This is mainly useful in tests, where the plugin is included
249
- # several times with different settings.
250
- registry = get_registry()
251
-
252
- for collector in _METRICS.values():
253
- try:
254
- registry.unregister(collector)
255
- except KeyError: # pragma: no cover
256
- pass
257
- _METRICS.clear()
258
-
259
- prefix = settings.get("prometheus_prefix", settings["project_name"])
260
-
261
- config.registry.registerUtility(PrometheusService(prefix=prefix), metrics.IMetricsService)
300
+ config.registry.registerUtility(metrics_impl, metrics.IMetricsService)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kinto
3
- Version: 22.0.0
3
+ Version: 23.0.1
4
4
  Summary: Kinto Web Service - Store, Sync, Share, and Self-Host.
5
5
  Author-email: Mozilla Services <developers@kinto-storage.org>
6
6
  License: Copyright 2012 - Mozilla Foundation
@@ -70,6 +70,7 @@ Provides-Extra: dev
70
70
  Requires-Dist: build; extra == "dev"
71
71
  Requires-Dist: ruff; extra == "dev"
72
72
  Requires-Dist: twine; extra == "dev"
73
+ Requires-Dist: uwsgi; extra == "dev"
73
74
  Dynamic: license-file
74
75
 
75
76
  Kinto
@@ -12,7 +12,7 @@ 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=OMnwre6roy_JkOCA0wf47wUJv7erxOfACI9CT78tD5k,26329
15
+ kinto/core/initialization.py,sha256=TXU9JTenlNurKga4FLX1ov6KzxGJJ2zviGz9Gd-Wnz4,26337
16
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
@@ -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=xoqCnJEF2dmGxZFN5Fql2bSMWaNFDYAdR94Yik-gKLM,8209
103
+ kinto/plugins/prometheus.py,sha256=MXI79XQ9Uq_1hwAONgiySiKrLP-cwa26A_s4eeHrAvY,9621
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-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,,
144
+ kinto-23.0.1.dist-info/licenses/LICENSE,sha256=oNEIMTuTJzppR5ZEyi86yvvtSagveMYXTYFn56zF0Uk,561
145
+ kinto-23.0.1.dist-info/METADATA,sha256=o0wKYniN1mdhcMwvWSTXU-LNZiqLxJhwWEYjCj3wX_I,8768
146
+ kinto-23.0.1.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
147
+ kinto-23.0.1.dist-info/entry_points.txt,sha256=3KlqBWPKY81mrCe_oX0I5s1cRO7Q53nCLbnVr5P9LH4,85
148
+ kinto-23.0.1.dist-info/top_level.txt,sha256=EG_YmbZL6FAug9VwopG7JtF9SvH_r0DEnFp-3twPPys,6
149
+ kinto-23.0.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.3.1)
2
+ Generator: setuptools (80.7.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5