Skip to content

Commit 7062986

Browse files
Merge pull request #10 from RefaceAI/add-readthedocs
Add readthedocs
2 parents c90b116 + 46564de commit 7062986

File tree

6 files changed

+199
-0
lines changed

6 files changed

+199
-0
lines changed

.readthedocs.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "2"
2+
3+
build:
4+
os: "ubuntu-22.04"
5+
tools:
6+
python: "3.10"
7+
8+
python:
9+
install:
10+
- requirements: docs/requirements.txt
11+
12+
sphinx:
13+
configuration: docs/source/conf.py

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

docs/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sphinx==7.1.2
2+
sphinx-rtd-theme==1.3.0rc1

docs/source/conf.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -- Project information
2+
3+
project = "prometheus-summary"
4+
copyright = "2025, RefaceAI"
5+
author = "RefaceAI"
6+
7+
# -- General configuration
8+
9+
extensions = [
10+
"sphinx.ext.duration",
11+
"sphinx.ext.doctest",
12+
"sphinx.ext.autodoc",
13+
"sphinx.ext.autosummary",
14+
"sphinx.ext.intersphinx",
15+
]
16+
17+
intersphinx_mapping = {
18+
"python": ("https://docs.python.org/3/", None),
19+
"sphinx": ("https://www.sphinx-doc.org/en/master/", None),
20+
}
21+
intersphinx_disabled_domains = ["std"]
22+
23+
templates_path = ["_templates"]
24+
25+
# -- Options for HTML output
26+
27+
html_theme = "sphinx_rtd_theme"
28+
29+
# -- Options for EPUB output
30+
epub_show_urls = "footnote"

docs/source/index.rst

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
Welcome to prometheus-summary documentation!
2+
============================================
3+
4+
`Prometheus-summary library <https://github.com/RefaceAI/prometheus-summary>`_ adds support of quantiles calculation for the Summary metric.
5+
It is fully compatible with the official `Python Prometheus client library <https://github.com/prometheus/client_python>`_.
6+
7+
Installation
8+
------------
9+
10+
.. code-block:: console
11+
12+
pip install prometheus-summary==0.1.4
13+
14+
This package can be found on `PyPI <https://pypi.org/project/prometheus-summary/>`_.
15+
16+
Collecting
17+
----------
18+
19+
Basic usage
20+
^^^^^^^^^^^
21+
22+
.. code-block:: python
23+
24+
from prometheus_summary import Summary
25+
26+
s = Summary("request_latency_seconds", "Description of summary")
27+
s.observe(4.7)
28+
29+
Usage with labels
30+
^^^^^^^^^^^^^^^^^^^^^
31+
32+
.. code-block:: python
33+
34+
from prometheus_summary import Summary
35+
36+
s = Summary("request_latency_seconds", "Description of summary", ["method", "endpoint"])
37+
s.labels(method="GET", endpoint="/profile").observe(1.2)
38+
s.labels(method="POST", endpoint="/login").observe(3.4)
39+
40+
Usage with custom quantiles and precisions
41+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
43+
By default, metrics are observed for the following (quantile, precision (inaccuracy)) pairs:
44+
45+
``((0.50, 0.05), (0.90, 0.01), (0.99, 0.001))``
46+
47+
You can also provide your own values when creating the metric.
48+
49+
.. code-block:: python
50+
from prometheus_summary import Summary
51+
52+
s = Summary(
53+
"request_latency_seconds", "Description of summary",
54+
invariants=((0.50, 0.05), (0.75, 0.02), (0.90, 0.01), (0.95, 0.005), (0.99, 0.001)),
55+
)
56+
s.observe(4.7)
57+
58+
Usage with custom time window settings
59+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60+
61+
Typically, you don't want to have a Summary representing the entire runtime of the application,
62+
but you want to look at a reasonable time interval. This Summary metric implement a configurable sliding time window.
63+
64+
The default is a time window of 10 minutes and 5 age buckets, i.e. the time window is 10 minutes wide, and
65+
we slide it forward every 10 / 5 = 2 minutes, but you can configure this values for your own purposes.
66+
67+
.. code-block:: python
68+
from prometheus_summary import Summary
69+
70+
s = Summary(
71+
"request_latency_seconds", "Description of summary",
72+
# time window 5 minutes wide with 10 age buckets (sliding every 30 seconds)
73+
max_age_seconds=5 * 60,
74+
age_buckets=10,
75+
)
76+
s.observe(4.7)
77+
78+
Querying
79+
--------
80+
81+
Suppose we have a metric:
82+
83+
.. code-block:: python
84+
85+
from prometheus_summary import Summary
86+
87+
s = Summary("request_latency_seconds", "Description of summary", ["method", "endpoint"])
88+
89+
To show request latency by `method`, `endpoint` and `quantile` use the following PromQL query:
90+
91+
.. code-block:: promql
92+
93+
max by (method, endpoint, quantile) (request_latency_seconds)
94+
95+
To show only 99-th quantile:
96+
97+
.. code-block:: promql
98+
99+
max by (method, endpoint) (request_latency_seconds{quantile="0.99"})

0 commit comments

Comments
 (0)