Skip to content

Commit 797fb75

Browse files
authored
Add prometheus support (Fixes #3407) (#3453)
* Introduce the Prometheus lib * Start plugin * Unit testing * Adapt usage of unique parameter to groups * Skip test when no prometheus installed * Add test for events * Enable Prometheus in functional test * Add section about Prometheus * Move plugins section above monitoring * Fix link format in docs * Remove TODO * nit docs
1 parent b79907e commit 797fb75

File tree

10 files changed

+399
-96
lines changed

10 files changed

+399
-96
lines changed

constraints.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ psycopg2
2525
zope.sqlalchemy
2626
# monitoring
2727
newrelic
28+
prometheus-client
2829
sentry-sdk[sqlalchemy]
2930
statsd
3031
werkzeug

constraints.txt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# This file is autogenerated by pip-compile with Python 3.10
2+
# This file is autogenerated by pip-compile with Python 3.12
33
# by the following command:
44
#
55
# pip-compile --output-file=constraints.txt --strip-extras constraints.in
@@ -40,16 +40,12 @@ coverage==7.4.0
4040
# via pytest-cov
4141
dockerflow==2024.4.2
4242
# via -r constraints.in
43-
exceptiongroup==1.2.0
44-
# via pytest
4543
execnet==2.0.2
4644
# via pytest-cache
4745
fqdn==1.5.1
4846
# via jsonschema
4947
greenlet==3.0.3
50-
# via
51-
# playwright
52-
# sqlalchemy
48+
# via playwright
5349
hupper==1.12
5450
# via pyramid
5551
idna==3.7
@@ -102,6 +98,8 @@ playwright==1.47.0
10298
# via -r constraints.in
10399
pluggy==1.5.0
104100
# via pytest
101+
prometheus-client==0.21.0
102+
# via -r constraints.in
105103
psycopg2==2.9.9
106104
# via -r constraints.in
107105
pyee==12.0.0
@@ -186,12 +184,6 @@ statsd==4.0.1
186184
# via -r constraints.in
187185
swagger-spec-validator==3.0.3
188186
# via bravado-core
189-
tomli==2.0.1
190-
# via
191-
# build
192-
# coverage
193-
# pyproject-hooks
194-
# pytest
195187
transaction==5.0
196188
# via
197189
# -r constraints.in

docs/configuration/production.rst

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,14 @@ In the configuration of the CDN service, you should also:
220220
Monitoring
221221
----------
222222

223-
In order to enable monitoring features like *statsd*, install
223+
In order to enable monitoring features (eg. *Prometheus* or *StatsD*), install
224224
extra requirements:
225225

226226
::
227227

228228
make install-monitoring
229229

230-
And configure its URL:
231-
232-
.. code-block :: ini
233-
234-
# StatsD
235-
kinto.statsd_url = udp://carbon.server:8125
230+
See :ref:`settings section <monitoring-with-prometheus>` for the configuration aspects.
236231

237232
Counters
238233
::::::::

docs/configuration/settings.rst

Lines changed: 97 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,83 @@ hello view <api-utilities>`.
301301
# kinto.http_host = production.server.com:7777
302302
303303
304+
.. _configuration-plugins:
305+
306+
Plugins
307+
=======
308+
309+
It is possible to extend the default Kinto behaviors by using "plugins".
310+
311+
The list of plugins to load at startup can be specified in the settings, as a
312+
list of Python modules:
313+
314+
.. code-block:: ini
315+
316+
kinto.includes = kinto.plugins.default_bucket
317+
kinto.plugins.history
318+
kinto.plugins.admin
319+
kinto-attachment
320+
custom-myplugin
321+
322+
+---------------------------------------+--------------------------------------------------------------------------+
323+
| Built-in plugins | What does it do? |
324+
+=======================================+==========================================================================+
325+
| ``kinto.plugins.accounts`` | It allows users to sign-up and authenticate using username and password |
326+
| | (:ref:`more details <api-accounts>`). |
327+
+---------------------------------------+--------------------------------------------------------------------------+
328+
| ``kinto.plugins.admin`` | It is a Web admin UI to manage data from a Kinto server. |
329+
| | (:ref:`more details <kinto-admin>`). |
330+
+---------------------------------------+--------------------------------------------------------------------------+
331+
| ``kinto.plugins.default_bucket`` | It enables a personal bucket ``default``, where collections are created |
332+
| | implicitly (:ref:`more details <buckets-default-id>`). |
333+
+---------------------------------------+--------------------------------------------------------------------------+
334+
| ``kinto.plugins.flush`` | Adds an endpoint to completely remove all data from the database backend |
335+
| | for testing/staging purposes. (:ref:`more details <api-flush>`). |
336+
+---------------------------------------+--------------------------------------------------------------------------+
337+
| ``kinto.plugins.history`` | It tracks every action performed on objects within a bucket |
338+
| | (:ref:`more details <api-history>`). |
339+
+---------------------------------------+--------------------------------------------------------------------------+
340+
| ``kinto.plugins.openid`` | It allows to authenticate users using OpenID Connect from Google, |
341+
| | Microsoft, Auth0, etc. (:ref:`more details <api-openid>`). |
342+
+---------------------------------------+--------------------------------------------------------------------------+
343+
| ``kinto.plugins.quotas`` | It allows to limit storage per collection size, number of records, etc. |
344+
| | (:ref:`more details <api-quotas>`). |
345+
+---------------------------------------+--------------------------------------------------------------------------+
346+
| ``kinto.plugins.prometheus`` | Send metrics about backend duration, authentication, endpoints hits, .. |
347+
| | (:ref:`more details <monitoring-with-prometheus>`). |
348+
+---------------------------------------+--------------------------------------------------------------------------+
349+
| ``kinto.plugins.statsd`` | Send metrics about backend duration, authentication, endpoints hits, .. |
350+
| | (:ref:`more details <monitoring-with-statsd>`). |
351+
+---------------------------------------+--------------------------------------------------------------------------+
352+
353+
354+
There are `many available packages`_ in the Pyramid ecosystem, and it is straightforward to build one,
355+
since the specified module must just define an ``includeme(config)`` function.
356+
357+
.. _many available packages: https://github.com/ITCase/awesome-pyramid
358+
359+
See `our list of community plugins <https://github.com/Kinto/kinto/wiki/Plugins>`_.
360+
361+
See also: :ref:`tutorial-write-plugin` for more in-depth informations on how
362+
to create your own plugin.
363+
364+
365+
Pluggable components
366+
::::::::::::::::::::
367+
368+
:term:`Pluggable <pluggable>` components can be substituted from configuration files,
369+
as long as the replacement follows the original component API.
370+
371+
.. code-block:: ini
372+
373+
kinto.logging_renderer = your_log_renderer.CustomRenderer
374+
375+
This is the simplest way to extend *Kinto*, but will be limited to its
376+
existing components (cache, storage, log renderer, ...).
377+
378+
In order to add extra features, including external packages is the way to go!
379+
380+
304381
Logging and Monitoring
305382
======================
306383

@@ -413,13 +490,33 @@ Or the equivalent environment variables:
413490
The application sends an event on startup (mainly for setup check).
414491

415492

493+
.. _monitoring-with-prometheus:
494+
495+
Monitoring with Prometheus
496+
::::::::::::::::::::::::::
497+
498+
Requires the ``prometheus-client`` package (installed with ``kinto[monitoring]``).
499+
500+
Prometheus metrics can be enabled with (disabled by default):
501+
502+
.. code-block:: ini
503+
504+
kinto.includes = kinto.plugins.prometheus
505+
506+
Metrics can then be crawled from the ``/__metrics__`` endpoint.
507+
508+
416509
.. _monitoring-with-statsd:
417510

418511
Monitoring with StatsD
419512
::::::::::::::::::::::
420513

421514
Requires the ``statsd`` package.
422515

516+
.. note::
517+
518+
Only one of *Prometheus* and *StatsD* can be enabled. It will take precedence and the other one will be ignored.
519+
423520
+------------------------+----------------------------------------+--------------------------------------------------------------------------+
424521
| Setting name | Default | What does it do? |
425522
+========================+========================================+==========================================================================+
@@ -475,80 +572,6 @@ New Relic can be enabled (disabled by default):
475572
kinto.newrelic_env = prod
476573
477574
478-
.. _configuration-plugins:
479-
480-
Plugins
481-
=======
482-
483-
It is possible to extend the default Kinto behaviors by using "plugins".
484-
485-
The list of plugins to load at startup can be specified in the settings, as a
486-
list of Python modules:
487-
488-
.. code-block:: ini
489-
490-
kinto.includes = kinto.plugins.default_bucket
491-
kinto.plugins.history
492-
kinto.plugins.admin
493-
kinto-attachment
494-
custom-myplugin
495-
496-
+---------------------------------------+--------------------------------------------------------------------------+
497-
| Built-in plugins | What does it do? |
498-
+=======================================+==========================================================================+
499-
| ``kinto.plugins.accounts`` | It allows users to sign-up and authenticate using username and password |
500-
| | (:ref:`more details <api-accounts>`). |
501-
+---------------------------------------+--------------------------------------------------------------------------+
502-
| ``kinto.plugins.admin`` | It is a Web admin UI to manage data from a Kinto server. |
503-
| | (:ref:`more details <kinto-admin>`). |
504-
+---------------------------------------+--------------------------------------------------------------------------+
505-
| ``kinto.plugins.default_bucket`` | It enables a personal bucket ``default``, where collections are created |
506-
| | implicitly (:ref:`more details <buckets-default-id>`). |
507-
+---------------------------------------+--------------------------------------------------------------------------+
508-
| ``kinto.plugins.flush`` | Adds an endpoint to completely remove all data from the database backend |
509-
| | for testing/staging purposes. (:ref:`more details <api-flush>`). |
510-
+---------------------------------------+--------------------------------------------------------------------------+
511-
| ``kinto.plugins.history`` | It tracks every action performed on objects within a bucket |
512-
| | (:ref:`more details <api-history>`). |
513-
+---------------------------------------+--------------------------------------------------------------------------+
514-
| ``kinto.plugins.openid`` | It allows to authenticate users using OpenID Connect from Google, |
515-
| | Microsoft, Auth0, etc. (:ref:`more details <api-openid>`). |
516-
+---------------------------------------+--------------------------------------------------------------------------+
517-
| ``kinto.plugins.quotas`` | It allows to limit storage per collection size, number of records, etc. |
518-
| | (:ref:`more details <api-quotas>`). |
519-
+---------------------------------------+--------------------------------------------------------------------------+
520-
| ``kinto.plugins.statsd`` | Send metrics about backend duration, authentication, endpoints hits, .. |
521-
| | (:ref:`more details <monitoring-with-statsd>`). |
522-
+---------------------------------------+--------------------------------------------------------------------------+
523-
524-
525-
There are `many available packages`_ in Pyramid ecosystem, and it is straightforward to build one,
526-
since the specified module must just define an ``includeme(config)`` function.
527-
528-
.. _many available packages: https://github.com/ITCase/awesome-pyramid
529-
530-
See `our list of community plugins <https://github.com/Kinto/kinto/wiki/Plugins>`_.
531-
532-
See also: :ref:`tutorial-write-plugin` for more in-depth informations on how
533-
to create your own plugin.
534-
535-
536-
Pluggable components
537-
::::::::::::::::::::
538-
539-
:term:`Pluggable <pluggable>` components can be substituted from configuration files,
540-
as long as the replacement follows the original component API.
541-
542-
.. code-block:: ini
543-
544-
kinto.logging_renderer = your_log_renderer.CustomRenderer
545-
546-
This is the simplest way to extend *Kinto*, but will be limited to its
547-
existing components (cache, storage, log renderer, ...).
548-
549-
In order to add extra features, including external packages is the way to go!
550-
551-
552575
.. _configuration-authentication:
553576

554577
Authentication

kinto/core/testing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
from kinto.core import DEFAULT_SETTINGS
1212
from kinto.core.storage import generators
1313
from kinto.core.utils import encode64, follow_subrequest, memcache, sqlalchemy
14-
from kinto.plugins import statsd
14+
from kinto.plugins import prometheus, statsd
1515

1616

1717
skip_if_ci = unittest.skipIf("CI" in os.environ, "ci")
1818
skip_if_no_postgresql = unittest.skipIf(sqlalchemy is None, "postgresql is not installed.")
1919
skip_if_no_memcached = unittest.skipIf(memcache is None, "memcached is not installed.")
2020
skip_if_no_statsd = unittest.skipIf(not statsd.statsd_module, "statsd is not installed.")
21+
skip_if_no_prometheus = unittest.skipIf(
22+
not prometheus.prometheus_module, "prometheus is not installed."
23+
)
2124

2225

2326
class DummyRequest(mock.MagicMock):

0 commit comments

Comments
 (0)