Skip to content

Commit 705560b

Browse files
authored
docs: Add Prometheus metrics documentation (#5395)
1 parent 9ccae45 commit 705560b

8 files changed

Lines changed: 128 additions & 11 deletions

File tree

.github/workflows/api-pull-request.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ defaults:
1717
run:
1818
working-directory: api
1919

20+
env:
21+
DOTENV_OVERRIDE_FILE: .env-ci
22+
2023
jobs:
2124
test:
2225
runs-on: General-Purpose-8c-Runner
@@ -60,16 +63,18 @@ jobs:
6063

6164
- name: Check for missing migrations
6265
env:
63-
DOTENV_OVERRIDE_FILE: .env-ci
6466
opts: --no-input --dry-run --check
6567
run: make django-make-migrations
6668

6769
- name: Check for new typing errors
6870
run: make typecheck
6971

72+
- name: Check autogenerated documentation
73+
uses: nickcharlton/diff-check@v1.0.0
74+
with:
75+
command: make -C api generate-docs
76+
7077
- name: Run Tests
71-
env:
72-
DOTENV_OVERRIDE_FILE: .env-ci
7378
run: make test
7479

7580
- name: Upload Coverage

.pre-commit-config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ repos:
2828
args:
2929
- --check
3030
types: [javascript, jsx, ts, tsx, markdown, mdx, html, css, json, yaml]
31+
- id: generate-docs
32+
name: generate-docs
33+
language: system
34+
entry: make -C api generate-docs
35+
pass_filenames: false
36+
types: [python,toml]
3137
- id: python-typecheck
3238
name: python-typecheck
3339
language: system
@@ -43,5 +49,5 @@ repos:
4349
args: ["-C", "api"]
4450

4551
ci:
46-
skip: [python-typecheck]
52+
skip: [generate-docs, python-typecheck]
4753
autoupdate_commit_msg: "ci: pre-commit autoupdate"

api/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,7 @@ integrate-private-tests:
140140

141141
git clone https://github.com/flagsmith/flagsmith-task-processor --depth 1 --branch ${TASK_PROCESSOR_REVISION} && mv ./flagsmith-task-processor/tests tests/task_processor_tests
142142
rm -rf ./flagsmith-saml ./flagsmith-rbac ./flagsmith-workflows ./flagsmith-auth-controller ./flagsmith-task-processor
143+
144+
.PHONY: generate-docs
145+
generate-docs:
146+
poetry run flagsmith docgen metrics > ../docs/docs/system-administration/metrics.md

api/app/settings/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,3 +1407,5 @@
14071407
default=prometheus_client.Histogram.DEFAULT_BUCKETS,
14081408
)
14091409
)
1410+
1411+
DOCGEN_MODE = env.bool("DOCGEN_MODE", default=False)

api/environments/metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
flagsmith_environment_document_cache_queries_total = prometheus_client.Counter(
77
"flagsmith_environment_document_cache_queries_total",
8-
"Results of cache retrieval for environment document (hit or miss)",
8+
"Results of cache retrieval for environment document. `result` label is either `hit` or `miss`.",
99
["result"],
1010
)

api/poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/pyproject.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ exclude_also = [
6666
omit = ["scripts/*", "manage.py"]
6767

6868
[tool.pytest.ini_options]
69-
addopts = ['--ds=app.settings.test', '-vvvv', '-p', 'no:warnings', '--dist=worksteal']
69+
addopts = [
70+
'--ds=app.settings.test',
71+
'-vvvv',
72+
'-p',
73+
'no:warnings',
74+
'--dist=worksteal',
75+
]
7076
console_output_style = 'count'
7177

7278
[tool.mypy]
@@ -154,7 +160,7 @@ pygithub = "2.1.1"
154160
hubspot-api-client = "^8.2.1"
155161
djangorestframework-dataclasses = "^1.3.1"
156162
pyotp = "^2.9.0"
157-
flagsmith-common = "^1.11.0"
163+
flagsmith-common = "^1.12.0"
158164
django-stubs = "^5.1.3"
159165
tzdata = "^2024.1"
160166
djangorestframework-simplejwt = "^5.3.1"
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: Metrics
3+
---
4+
5+
## Prometheus
6+
7+
To enable the Prometheus `/metrics` endpoint, set the `PROMETHEUS_ENABLED` environment variable to `true`.
8+
9+
The metrics provided by Flagsmith are described below.
10+
11+
12+
### `flagsmith_build_info`
13+
14+
Gauge.
15+
16+
Flagsmith version and build information.
17+
18+
Labels:
19+
- `ci_commit_sha`
20+
- `version`
21+
22+
### `flagsmith_environment_document_cache_queries`
23+
24+
Counter.
25+
26+
Results of cache retrieval for environment document. `result` label is either `hit` or `miss`.
27+
28+
Labels:
29+
- `result`
30+
31+
### `flagsmith_http_server_request_duration_seconds`
32+
33+
Histogram.
34+
35+
HTTP request duration in seconds.
36+
37+
Labels:
38+
- `route`
39+
- `method`
40+
- `response_status`
41+
42+
### `flagsmith_http_server_requests`
43+
44+
Counter.
45+
46+
Total number of HTTP requests.
47+
48+
Labels:
49+
- `route`
50+
- `method`
51+
- `response_status`
52+
53+
### `flagsmith_http_server_response_size_bytes`
54+
55+
Histogram.
56+
57+
HTTP response size in bytes.
58+
59+
Labels:
60+
- `route`
61+
- `method`
62+
- `response_status`
63+
64+
### `flagsmith_task_processor_enqueued_tasks`
65+
66+
Counter.
67+
68+
Total number of enqueued tasks.
69+
70+
Labels:
71+
- `task_identifier`
72+
73+
### `flagsmith_task_processor_finished_tasks`
74+
75+
Counter.
76+
77+
Total number of finished tasks. Only collected by Task Processor. `task_type` label is either `recurring` or `standard`.
78+
79+
Labels:
80+
- `task_identifier`
81+
- `task_type`
82+
- `result`
83+
84+
### `flagsmith_task_processor_task_duration_seconds`
85+
86+
Histogram.
87+
88+
Task processor task duration in seconds. Only collected by Task Processor. `task_type` label is either `recurring` or `standard`.
89+
90+
Labels:
91+
- `task_identifier`
92+
- `task_type`
93+
- `result`
94+

0 commit comments

Comments
 (0)