Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Log cleanup DAG #139

Merged
merged 6 commits into from
Aug 21, 2021
Merged

Log cleanup DAG #139

merged 6 commits into from
Aug 21, 2021

Conversation

zackkrida
Copy link
Member

Fixes

Fixes WordPress/openverse#1751 by @mathemancer

Description

This PR creates a simple DAG to delete log files from the local airflow filesystem. The DAG runs daily. It checks the date of files in the airflow base log directory (in our case /usr/local/airflow/logs) and deletes everything created X days ago.

This, paired with our new remote logging (#136), eliminates the need to manually delete airflow logs and worry about the scary-sounding work outlined here. We can delete that document after merging (or simply mark it deprecated/private).

Improvements are welcomed, encouraged, and needed! All I really did was copy/paste and test, I don't currently have the bandwidth to improve this further. It'd be great for the code style to be cleaned and altered to match the rest of the repository.

Technical details

This DAG was copied from https://github.com/teamclairvoyant/airflow-maintenance-dags/blob/master/log-cleanup/airflow-log-cleanup.py, the only edits made were to the default parameters.

Tests

If you'd like to test, you can do so locally by creating some random files in the log directory, and doing a manual DAG run with the configuration {"maxLogAgeInDays":-1}.

Screenshots

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main or master).
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

zackkrida and others added 4 commits August 19, 2021 10:40
…eaner DAG (#142)

* Set DAG id; remove deprecated calls

Setting base log folder and operator import were using deprecated Airflow functions

Signed-off-by: Olga Bulat <obulat@gmail.com>

* Try fixing the tests Permission error

Signed-off-by: Olga Bulat <obulat@gmail.com>

* Add option to override default max age and enable delete

Signed-off-by: Olga Bulat <obulat@gmail.com>

* Move log_cleanup DAG files to openverse_catalog/dags

Signed-off-by: Olga Bulat <obulat@gmail.com>

* Fix import and set schedule to weekly

Signed-off-by: Olga Bulat <obulat@gmail.com>

* Remove bash log cleanup workflow

Signed-off-by: Olga Bulat <obulat@gmail.com>

* Remove outdated comments

Signed-off-by: Olga Bulat <obulat@gmail.com>

* Fix import path in tests

Signed-off-by: Olga Bulat <obulat@gmail.com>

* Add sample log files as test resources

Signed-off-by: Olga Bulat <obulat@gmail.com>

* Fix tests


Signed-off-by: Olga Bulat <obulat@gmail.com>

* Fix .gitignore exceptions

Instead of removing logs from gitignore, set the specific /logs/ directory to be 'unignored'

Signed-off-by: Olga Bulat <obulat@gmail.com>

* Add doc comments

Signed-off-by: Olga Bulat <obulat@gmail.com>

Co-authored-by: Zack Krida <zackkrida@pm.me>
.github/workflows/push_pull_request_test.yml Outdated Show resolved Hide resolved
@obulat obulat merged commit 4f9e734 into main Aug 21, 2021
@obulat obulat deleted the log-cleanup-dag branch August 21, 2021 03:56
@zackkrida zackkrida mentioned this pull request Aug 23, 2021
7 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configure airflow to use remote logging capability (original #215)
2 participants