Skip to content

Commit 5225f90

Browse files
committed
fix: bumped-version
2 parents 9dce20a + ecce903 commit 5225f90

File tree

21 files changed

+344
-35
lines changed

21 files changed

+344
-35
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
33
# Ruff version.
4-
rev: v0.11.6
4+
rev: v0.11.7
55
hooks:
66
# Run the linter.
77
- id: ruff

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.11.0"
2+
".": "1.12.0"
33
}

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
<a name="v1.5.2"></a>
44

5+
## [1.12.0](https://github.com/Flagsmith/flagsmith-common/compare/v1.11.0...v1.12.0) (2025-04-30)
6+
7+
8+
### CI
9+
10+
* pre-commit autoupdate ([#66](https://github.com/Flagsmith/flagsmith-common/issues/66)) ([9c38998](https://github.com/Flagsmith/flagsmith-common/commit/9c38998f405ce59bf67b3db7790ec83a0a9abdd9))
11+
12+
13+
### Features
14+
15+
* Generate metrics documentation ([#65](https://github.com/Flagsmith/flagsmith-common/issues/65)) ([c9c4935](https://github.com/Flagsmith/flagsmith-common/commit/c9c4935afd12f24665779c0a0a7b98f3e9da7dc3))
16+
* **test-tools:** Add `snapshot` fixture for snapshot testing ([c9c4935](https://github.com/Flagsmith/flagsmith-common/commit/c9c4935afd12f24665779c0a0a7b98f3e9da7dc3))
17+
18+
19+
### Bug Fixes
20+
21+
* **tests:** `clear_lru_caches` fixture conflicts with `saas_mode`/`enterprise_mode` pytest markers ([c9c4935](https://github.com/Flagsmith/flagsmith-common/commit/c9c4935afd12f24665779c0a0a7b98f3e9da7dc3))
22+
523
## [1.11.0](https://github.com/Flagsmith/flagsmith-common/compare/v1.10.0...v1.11.0) (2025-04-25)
624

725

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "flagsmith-common"
3-
version = "1.11.1"
3+
version = "1.12.1"
44
description = "Flagsmith's common library"
55
requires-python = ">=3.11,<4.0"
66
dependencies = [
@@ -27,6 +27,8 @@ authors = [
2727
{ name = "Zach Aysan" },
2828
{ name = "Francesco Lo Franco" },
2929
{ name = "Rodrigo López Dato" },
30+
{ name = "Evandro Myller" },
31+
{ name = "Wadii Zaim" },
3032
]
3133
maintainers = [{ name = "Flagsmith Team", email = "support@flagsmith.com" }]
3234
license = "BSD-3-Clause"

settings/dev.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88

99
env = Env()
1010

11+
TEMPLATES = [
12+
{
13+
"BACKEND": "django.template.backends.django.DjangoTemplates",
14+
"DIRS": ["templates"],
15+
"APP_DIRS": True,
16+
},
17+
]
18+
1119
# Settings expected by `mypy_django_plugin`
1220
AWS_SES_REGION_ENDPOINT: str
1321
SEGMENT_RULES_CONDITIONS_LIMIT: int
@@ -48,7 +56,8 @@
4856
TASK_DELETE_RETENTION_DAYS = 15
4957
TASK_DELETE_RUN_EVERY = timedelta(days=1)
5058
TASK_DELETE_RUN_TIME = time(5, 0, 0)
51-
TASK_PROCESSOR_MODE = False
59+
TASK_PROCESSOR_MODE = env.bool("RUN_BY_PROCESSOR", default=False)
60+
DOCGEN_MODE = env.bool("DOCGEN_MODE", default=False)
5261
TASK_RUN_METHOD = TaskRunMethod.TASK_PROCESSOR
5362

5463
# Avoid models.W042 warnings

src/common/core/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def ensure_cli_env() -> typing.Generator[None, None, None]:
5252
)
5353
os.environ["PROMETHEUS_MULTIPROC_DIR"] = prometheus_multiproc_dir_name
5454

55+
if "docgen" in sys.argv:
56+
os.environ["DOCGEN_MODE"] = "true"
57+
5558
if "task-processor" in sys.argv:
5659
# A hacky way to signal we're not running the API
5760
os.environ["RUN_BY_PROCESSOR"] = "true"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from operator import itemgetter
2+
from typing import Any, Callable
3+
4+
import prometheus_client
5+
from django.core.management import BaseCommand, CommandParser
6+
from django.template.loader import get_template
7+
from django.utils.module_loading import autodiscover_modules
8+
from prometheus_client.metrics import MetricWrapperBase
9+
10+
11+
class Command(BaseCommand):
12+
help = "Generate documentation for the Flagsmith codebase."
13+
14+
def add_arguments(self, parser: CommandParser) -> None:
15+
subparsers = parser.add_subparsers(
16+
title="sub-commands",
17+
required=True,
18+
)
19+
20+
metric_parser = subparsers.add_parser(
21+
"metrics",
22+
help="Generate metrics documentation.",
23+
)
24+
metric_parser.set_defaults(handle_method=self.handle_metrics)
25+
26+
def initialise(self) -> None:
27+
from common.gunicorn import metrics # noqa: F401
28+
29+
autodiscover_modules(
30+
"metrics",
31+
)
32+
33+
def handle(
34+
self,
35+
*args: Any,
36+
handle_method: Callable[..., None],
37+
**options: Any,
38+
) -> None:
39+
self.initialise()
40+
handle_method(*args, **options)
41+
42+
def handle_metrics(self, *args: Any, **options: Any) -> None:
43+
template = get_template("docgen-metrics.md")
44+
45+
flagsmith_metrics = sorted(
46+
(
47+
{
48+
"name": collector._name,
49+
"documentation": collector._documentation,
50+
"labels": collector._labelnames,
51+
"type": collector._type,
52+
}
53+
for collector in prometheus_client.REGISTRY._collector_to_names
54+
if isinstance(collector, MetricWrapperBase)
55+
),
56+
key=itemgetter("name"),
57+
)
58+
59+
self.stdout.write(
60+
template.render(
61+
context={"flagsmith_metrics": flagsmith_metrics},
62+
)
63+
)

src/common/core/metrics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import prometheus_client
2+
from django.conf import settings
23

34
from common.core.utils import get_version_info
45

56
flagsmith_build_info = prometheus_client.Gauge(
67
"flagsmith_build_info",
7-
"Flagsmith version and build information",
8+
"Flagsmith version and build information.",
89
["ci_commit_sha", "version"],
910
multiprocess_mode="livemax",
1011
)
@@ -20,4 +21,5 @@ def advertise() -> None:
2021
).set(1)
2122

2223

23-
advertise()
24+
if not settings.DOCGEN_MODE:
25+
advertise()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
{% for metric in flagsmith_metrics %}
12+
### `{{ metric.name }}`
13+
14+
{{ metric.type|title }}.
15+
16+
{{ metric.documentation }}
17+
18+
Labels:
19+
{% for label in metric.labels %} - `{{ label }}`
20+
{% endfor %}{% endfor %}

src/common/gunicorn/metrics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
flagsmith_http_server_requests_total = prometheus_client.Counter(
88
"flagsmith_http_server_requests_total",
9-
"Total number of HTTP requests",
9+
"Total number of HTTP requests.",
1010
["route", "method", "response_status"],
1111
)
1212
flagsmith_http_server_request_duration_seconds = Histogram(
1313
"flagsmith_http_server_request_duration_seconds",
14-
"HTTP request duration in seconds",
14+
"HTTP request duration in seconds.",
1515
["route", "method", "response_status"],
1616
)
1717
flagsmith_http_server_response_size_bytes = Histogram(
1818
"flagsmith_http_server_response_size_bytes",
19-
"HTTP response size in bytes",
19+
"HTTP response size in bytes.",
2020
["route", "method", "response_status"],
2121
buckets=getattr(
2222
settings,

0 commit comments

Comments
 (0)