Skip to content

Commit 0ee9cc1

Browse files
Merge pull request #129 from vishalanandl177/SCRUM-12-P0-Strengthen-production-trust-and-operations
production trust and operations diagnostics
2 parents 73db013 + cfe4091 commit 0ee9cc1

10 files changed

Lines changed: 1123 additions & 0 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,21 @@ For detailed testing instructions, see [TESTING.md](TESTING.md).
625625

626626
## 🚀 Performance & Production
627627

628+
### Production Diagnostics
629+
630+
Run production diagnostics before deploying database logging:
631+
632+
```bash
633+
python manage.py drf_api_logger_doctor
634+
python manage.py drf_api_logger_doctor --format json
635+
python manage.py drf_api_logger_doctor --fail-level warning
636+
```
637+
638+
The doctor command is read-only. It checks logging mode, database readiness,
639+
migrations, table availability, queue settings, worker status, payload limits,
640+
masking configuration, and profiling risk. Use `--fail-level error` when a
641+
deployment should fail only for blocking misconfiguration.
642+
628643
### Database Optimization
629644

630645
For high-traffic applications:

TESTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ make check-package
6363
- `tests/test_middleware.py`: request/response logging, filtering, tracing, body limits, and content types.
6464
- `tests/test_models.py`: model fields, admin display, filters, and CSV export.
6565
- `tests/test_signals.py`: event listeners, background queue behavior, app startup, and worker stats.
66+
- `tests/test_diagnostics.py`: production doctor checks for logging mode, database readiness, queue status, payload limits, masking, and profiling risk.
6667
- `tests/test_observability.py`: dependency-free Prometheus, OpenTelemetry, and Sentry helper behavior.
6768
- `tests/test_policy.py`: logging policy decisions, endpoint rules, callable overrides, extra mask keys, and safe failure behavior.
6869
- `tests/test_profiling.py`: profiling settings, SQL tracking, admin diagnosis, and nullable profiling fields.
@@ -116,6 +117,14 @@ python manage.py prune_api_logs --days 30 --dry-run
116117
python manage.py prune_api_logs --days 30 --batch-size 1000
117118
```
118119

120+
Production diagnostics:
121+
122+
```bash
123+
python manage.py drf_api_logger_doctor
124+
python manage.py drf_api_logger_doctor --format json
125+
python manage.py drf_api_logger_doctor --fail-level warning
126+
```
127+
119128
Queue health check:
120129

121130
```python

docs/developer_testing.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ Add or update tests for every behavior change. Cover the touched surface:
8888
label prevention.
8989
- Policy gate behavior for full log drops, metadata-only logging, extra mask
9090
keys, signal/export gating, safe failures, and default backward compatibility.
91+
- Production diagnostics and doctor command behavior, including JSON output,
92+
fail-level behavior, database readiness, queue health, payload limits,
93+
masking, and profiling risk.
9194
- Background queue flushing, stats, shutdown, and database alias handling.
9295
- Admin display, filters, CSV export, and profiling diagnosis.
9396
- Management commands such as ``prune_api_logs``.
@@ -103,6 +106,14 @@ Retention command:
103106
python manage.py prune_api_logs --days 30 --dry-run
104107
python manage.py prune_api_logs --days 30 --batch-size 1000
105108
109+
Production diagnostics:
110+
111+
.. code-block:: bash
112+
113+
python manage.py drf_api_logger_doctor
114+
python manage.py drf_api_logger_doctor --format json
115+
python manage.py drf_api_logger_doctor --fail-level warning
116+
106117
Queue health:
107118

108119
.. code-block:: python

docs/index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,18 @@ Model Schema
612612
Performance & Production
613613
=========================
614614

615+
Run production diagnostics during deployment:
616+
617+
.. code-block:: bash
618+
619+
python manage.py drf_api_logger_doctor
620+
python manage.py drf_api_logger_doctor --format json
621+
python manage.py drf_api_logger_doctor --fail-level warning
622+
623+
The command is read-only and reports database readiness, queue health, payload
624+
limits, masking configuration, and profiling risk. Use ``--fail-level error``
625+
when deployment checks should fail only on blocking misconfiguration.
626+
615627
.. code-block:: python
616628
617629
# Use a dedicated database for logs

docs/operations.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,73 @@ DRF API Logger 1.2.3 supports:
1616
The GitHub Actions workflow tests representative Django versions from this
1717
support range before publishing package artifacts.
1818

19+
Production Doctor Command
20+
-------------------------
21+
22+
Run ``drf_api_logger_doctor`` before enabling database logging in production
23+
and after deployment changes that affect logging, storage, retention, masking,
24+
payload limits, or profiling.
25+
26+
.. code-block:: bash
27+
28+
python manage.py drf_api_logger_doctor
29+
30+
The command is read-only. It validates logging mode, database alias readiness,
31+
DRF API Logger migrations, the log table, queue settings, background worker
32+
status, payload limits, masking configuration, and profiling settings. It does
33+
not create tables, run migrations, prune rows, or inspect stored request or
34+
response payloads.
35+
36+
Use JSON output in CI or deployment checks:
37+
38+
.. code-block:: bash
39+
40+
python manage.py drf_api_logger_doctor --format json
41+
42+
Fail a deployment on warnings or errors:
43+
44+
.. code-block:: bash
45+
46+
python manage.py drf_api_logger_doctor --fail-level warning
47+
python manage.py drf_api_logger_doctor --fail-level error
48+
49+
Use ``--database`` when ``DRF_API_LOGGER_DEFAULT_DATABASE`` points to a
50+
dedicated log database and the deployment check must inspect that alias
51+
explicitly:
52+
53+
.. code-block:: bash
54+
55+
python manage.py drf_api_logger_doctor --database logs_db --format json
56+
57+
Result levels:
58+
59+
``OK``
60+
The checked condition is valid for the current configuration.
61+
62+
``WARNING``
63+
The package can run, but the setting or runtime state deserves operator
64+
attention before production use.
65+
66+
``ERROR``
67+
The package is likely misconfigured for the selected logging mode. Fix the
68+
issue before relying on production database logging.
69+
70+
Deployment Checklist
71+
--------------------
72+
73+
Before enabling database logging in production:
74+
75+
- Run ``python manage.py migrate drf_api_logger`` on the configured log
76+
database.
77+
- Run ``python manage.py drf_api_logger_doctor --fail-level warning``.
78+
- Keep finite body limits with ``DRF_API_LOGGER_MAX_REQUEST_BODY_SIZE`` and
79+
``DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE``.
80+
- Add application-specific secrets to ``DRF_API_LOGGER_EXCLUDE_KEYS``.
81+
- Skip health and metrics endpoints with ``DRF_API_LOGGER_SKIP_URL_NAME`` or
82+
``DRF_API_LOGGER_SKIP_NAMESPACE``.
83+
- Schedule ``prune_api_logs`` with a dry run first.
84+
- Monitor ``queue_backlog``, ``dropped_count``, and ``failed_insert_count``.
85+
1986
Database Growth
2087
---------------
2188

0 commit comments

Comments
 (0)