canonical / paas-app-charmer

2 stars 2 forks source link

Add log rotation for Gunicorn access and error logs #3

Closed weiiwang01 closed 7 months ago

weiiwang01 commented 7 months ago

The original plan for log rotation was to use the RotatingFileHandler logging handler. However, the RotatingFileHandler doesn't work in multiprocessing mode, as noted in https://bugs.python.org/issue43107. So instead, in this pull request, using a small Python script to perform the log rotation.

github-actions[bot] commented 7 months ago

Test coverage for e716c55f0433429f3082860b9f75e674422539fa

Name                                           Stmts   Miss Branch BrPart  Cover   Missing
------------------------------------------------------------------------------------------
paas_app_charmer/__init__.py                       1      0      0      0   100%
paas_app_charmer/_gunicorn/__init__.py             0      0      0      0   100%
paas_app_charmer/_gunicorn/charm.py              116     29     18      6    72%   60-62, 147-148, 150-151, 171->exit, 181-185, 190, 196-201, 205-206, 210, 214, 218, 222, 226, 230, 234, 238, 242, 246
paas_app_charmer/_gunicorn/charm_state.py         63      1      6      1    97%   194
paas_app_charmer/_gunicorn/logrotate.py           35     14     10      1    58%   46-63
paas_app_charmer/_gunicorn/observability.py       25      0      2      0   100%
paas_app_charmer/_gunicorn/secret_storage.py      14      1      0      0    93%   39
paas_app_charmer/_gunicorn/webserver.py           76      5     16      2    92%   19, 155, 167-173
paas_app_charmer/_gunicorn/wsgi_app.py            60      1     22      1    98%   80
paas_app_charmer/database_migration.py            34      0      2      0   100%
paas_app_charmer/databases.py                     38      3     13      2    90%   82, 97-98
paas_app_charmer/django/__init__.py                2      0      0      0   100%
paas_app_charmer/django/charm.py                  45     13     10      0    65%   72-77, 89, 97-114
paas_app_charmer/exceptions.py                     5      0      0      0   100%
paas_app_charmer/flask/__init__.py                 2      0      0      0   100%
paas_app_charmer/flask/charm.py                   37      0      6      0   100%
paas_app_charmer/helpers.py                        9      0      2      1    91%   18->20
paas_app_charmer/secret_storage.py                40      6     16      4    79%   50, 54->53, 55->57, 85, 103-108
------------------------------------------------------------------------------------------
TOTAL                                            602     73    123     18    86%

Static code analysis report

Run started:2024-04-03 10:31:51.740433

Test results:
    No issues identified.

Code scanned:
    Total lines of code: 1290
    Total lines skipped (#nosec): 0
    Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 2

Run metrics:
    Total issues (by severity):
        Undefined: 0
        Low: 0
        Medium: 0
        High: 0
    Total issues (by confidence):
        Undefined: 0
        Low: 0
        Medium: 0
        High: 0
Files skipped (0):