Skip to content

Commit a2451fe

Browse files
valentijnscholtenValentijn Scholten
andauthored
auditlog: switch to pghistory (for real) (#13587)
* auditlog: switch to pghistory * ruff * pghistory: add finding.reviewers to tracked models * fix finding reviewers model registration * remove more references * add migration * rebase migrations * rebase migrations * rebase * ruff * rebase * cleanup * remove obsolete test * ruff * move auditlog in settings.dist.py --------- Co-authored-by: Valentijn Scholten <valentijn.scholten@iodigital.com>
1 parent 05ec712 commit a2451fe

28 files changed

+824
-1138
lines changed

.github/workflows/integration-tests.yml

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

33
on:
44
workflow_call:
5-
inputs:
6-
auditlog_type:
7-
type: string
8-
default: "django-auditlog"
95

106
jobs:
117
integration_tests:
128
# run tests with docker compose
139
name: User Interface Tests
1410
runs-on: ubuntu-latest
15-
env:
16-
AUDITLOG_TYPE: ${{ inputs.auditlog_type }}
1711
strategy:
1812
matrix:
1913
test-case: [

.github/workflows/rest-framework-tests.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ on:
66
platform:
77
type: string
88
default: "linux/amd64"
9-
auditlog_type:
10-
type: string
11-
default: "django-auditlog"
129

1310
jobs:
1411
unit_tests:
1512
name: Rest Framework Unit Tests
1613
runs-on: ${{ inputs.platform == 'linux/arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
17-
env:
18-
AUDITLOG_TYPE: ${{ inputs.auditlog_type }}
1914

2015
strategy:
2116
matrix:

.github/workflows/unit-tests.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,18 @@ jobs:
2525
strategy:
2626
matrix:
2727
platform: ['linux/amd64', 'linux/arm64']
28-
auditlog_type: ['django-auditlog', 'django-pghistory']
2928
fail-fast: false
3029
needs: build-docker-containers
3130
uses: ./.github/workflows/rest-framework-tests.yml
3231
secrets: inherit
3332
with:
3433
platform: ${{ matrix.platform}}
35-
auditlog_type: ${{ matrix.auditlog_type }}
3634

3735
# only run integration tests for linux/amd64 (default)
3836
test-user-interface:
3937
needs: build-docker-containers
4038
uses: ./.github/workflows/integration-tests.yml
4139
secrets: inherit
42-
strategy:
43-
matrix:
44-
auditlog_type: ['django-auditlog', 'django-pghistory']
45-
fail-fast: false
46-
with:
47-
auditlog_type: ${{ matrix.auditlog_type }}
4840

4941
# only run k8s tests for linux/amd64 (default)
5042
test-k8s:

docs/content/en/open_source/upgrading/2.53.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 'Upgrading to DefectDojo Version 2.53.x'
2+
title: "Upgrading to DefectDojo Version 2.53.x"
33
toc_hide: true
44
weight: -20251103
55
description: "Helm chart: changes for initializer annotations + Replaced Redis with Valkey + HPA & PDB support"
@@ -17,9 +17,9 @@ Added Helm chart support for Celery and Django deployments for Horizontal Pod Au
1717

1818
### Breaking changes
1919

20-
#### Valkey
20+
#### Valkey
2121

22-
##### Renamed values
22+
##### Renamed values
2323

2424
HELM values had been changed to the following:
2525
- `createRedisSecret``createValkeySecret`
@@ -40,7 +40,7 @@ If an external Redis instance is being used, set the parameter `valkey.enabled`
4040
0. As always, perform a backup of your instance
4141
1. If you would like to be 100% sure that you do not miss any async event (triggered deduplication, email notification, ...) it is recommended to perform the following substeps (if your system is not in production and/or you are willing to miss some notifications or postpone deduplication to a later time, feel free to skip these substeps)
4242
0. Perform the following steps with your previous version of HELM chart (not with the upgraded one - you might lose your data)
43-
1. Downscale all producers of async tasks:
43+
1. Downscale all producers of async tasks:
4444
- Set `django.replicas` to 0 (if you used HPA, adjust it based on your needs)
4545
- Set `celery.beat.replicas` to 0 (if you used HPA, adjust it based on your needs)
4646
- Do not change `celery.worker.replicas` (they are responsible for processing your async tasks)
Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,47 @@
11
---
22
title: 'Upgrading to DefectDojo Version 2.54.x'
33
toc_hide: true
4-
weight: -20250804
5-
description: Dropped support for DD_PARSER_EXCLUDE
4+
weight: -20251201
5+
description: Removal of django-auditlog and exclusive use of django-pghistory for audit logging & Dropped support for DD_PARSER_EXCLUDE
66
---
77

8+
## Breaking Change: Removal of django-auditlog
9+
10+
Starting with DefectDojo 2.53, `django-auditlog` support has been removed in favour of `django-pghistory`.
11+
This is designed to be a backwards compatible change, unless:
12+
- You're querying the database directly for auditlog events, or,
13+
- You've set the `DD_AUDITLOG_TYPE` environment variable (or `AUDITLOG_TYPE` settings field)
14+
15+
### Required Actions
16+
17+
If you're using `DD_AUDITLOG_TYPE`, remove it from your configuration/environment.
18+
19+
### Existing Records Preserved
20+
21+
Historical audit log entries stored in the `auditlog_logentry` table will continue to be displayed in the action history view for backward compatibility. No data migration is required.
22+
23+
### Benefits of django-pghistory
24+
25+
The switch to `django-pghistory` provides several advantages:
26+
27+
- **Better performance**: Database-level triggers reduce overhead compared to Django signal-based auditing
28+
- **More features**: Enhanced context tracking and better support for complex queries
29+
- **Better data integrity**: PostgreSQL-native implementation ensures consistency
30+
31+
### Migration Notes
32+
33+
- A one-time data migration will take place to populate the `django-pghistory` tables with the initial snapshot of the tracked models.
34+
- The migration is designed to be fail-safe: if it fails for some reason, it will continue where it left off.
35+
- The migration can also be performed up front via
36+
- `docker compose exec uwsgi bash -c "python manage.py pghistory_backfill_fast"`, or
37+
- `docker compose exec uwsgi bash -c "python manage.py pghistory_backfill_simple"`, or
38+
- `docker compose exec uwsgi bash -c "python manage.py pghistory_backfill"`
39+
40+
The backfill migration is not mandatory to succeed. If it fails for some reason, the only side effect will be that the first auditlog diff will contain all fields of an object instead just the changed fields.
41+
42+
## Dropped support for DD_PARSER_EXCLUDE
43+
844
To simplify the management of the DefectDojo application, parser exclusions are no longer controlled via the environment variable DD_PARSER_EXCLUDE or application settings. This variable is now unsupported.
945
From now on, you should use the active flag in the Test_Type model to enable or disable parsers. Only parsers associated with active Test_Type entries will be available for use.
1046

11-
There are other instructions for upgrading to 2.54.x. Check the Release Notes for the contents of the release.
47+
Check the [Release Notes](https://github.com/DefectDojo/django-DefectDojo/releases/tag/2.54.0) for the contents of the release.

dojo/apps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def ready(self):
9191
# Configure audit system after all models are loaded
9292
# This must be done in ready() to avoid "Models aren't loaded yet" errors
9393
# Note: pghistory models are registered here (no database access), but trigger
94-
# enabling is handled via management command to avoid database access warnings
94+
# enabling is handled in the entrpoint script to avoid database access warnings
95+
# during startup
9596
register_django_pghistory_models()
9697
configure_audit_system()
9798

0 commit comments

Comments
 (0)