feat(docker): add minute-level log retention support to clean-logs.sh#61853
feat(docker): add minute-level log retention support to clean-logs.sh#61853shreeharshshinde wants to merge 4 commits intoapache:mainfrom
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
scripts/docker/clean-logs.sh
Outdated
| if [[ -n "${RETENTION_MINUTES}" ]]; then | ||
| echo "Trimming airflow logs older than ${RETENTION_MINUTES} minutes." | ||
| find "${DIRECTORY}"/logs \ | ||
| -type d -name 'lost+found' -prune -o \ | ||
| -type f -mmin +"${RETENTION_MINUTES}" -name '*.log' -print0 | \ | ||
| xargs -0 rm -f || true | ||
| else | ||
| echo "Trimming airflow logs older than ${RETENTION_DAYS} days." | ||
| find "${DIRECTORY}"/logs \ | ||
| -type d -name 'lost+found' -prune -o \ | ||
| -type f -mtime +"${RETENTION_DAYS}" -name '*.log' -print0 | \ | ||
| xargs -0 rm -f || true | ||
| fi |
There was a problem hiding this comment.
I don't know if it is good practice to just ignore the AIRFLOW__LOG_RETENTION_DAYS env when AIRFLOW__LOG_RETENTION_MINUTES is set. This behavior might confuse users.
Hmm, how about combine AIRFLOW__LOG_RETENTION_DAYS and AIRFLOW__LOG_RETENTION_MINUTES? What I mean with that is this:
AIRFLOW__LOG_RETENTION_DAYS * 24 * 60 + AIRFLOW__LOG_RETENTION_MINUTES?
With that, it would not be necessary to do an if-else statement, it would be enough to just use -mmin instead in general.
There was a problem hiding this comment.
that makes sense, combining both values into a single minute-based retention avoids silent overrides and simplifies the logic.
scripts/docker/clean-logs.sh
Outdated
| readonly DIRECTORY="${AIRFLOW_HOME:-/usr/local/airflow}" | ||
| readonly RETENTION="${AIRFLOW__LOG_RETENTION_DAYS:-15}" | ||
| readonly RETENTION_DAYS="${AIRFLOW__LOG_RETENTION_DAYS:-15}" | ||
| readonly RETENTION_MINUTES="${AIRFLOW__LOG_RETENTION_MINUTES:-}" |
There was a problem hiding this comment.
The addition of a new environment variable needs to be documented somewhere? Can somebody help with where this needs to be documented?
There was a problem hiding this comment.
Since I’m still getting familiar with the Airflow docs structure, could you please point me to the preferred location for documenting Docker image environment variables?
There was a problem hiding this comment.
Since I’m still getting familiar with the Airflow docs structure, could you please point me to the preferred location for documenting Docker image environment variables?
I'm afraid to disappoint you there, I don't know it either currently. I am not really familiar with the Airflow docs as well
There was a problem hiding this comment.
Since I’m still getting familiar with the Airflow docs structure, could you please point me to the preferred location for documenting Docker image environment variables?
A quick code search for "log_retention_days" in the repo gave me this: https://github.com/search?q=repo%3Aapache%2Fairflow+log_retention_days&type=code
|
I have updated the logic of retention period and added about retention_minutes where retention_days were added, hope it is right place to add about new environment variable |
There was a problem hiding this comment.
Additions in this file also need additions in https://github.com/shreeharshshinde/airflow/blob/main/chart/values.schema.json
…erfile and schema)
|
Along with schema I have added same logic in dockerfile also |
There was a problem hiding this comment.
I thought that the Dockerfile is getting autogenerated with scripts?
https://github.com/apache/airflow/blob/main/Dockerfile#L1634
There was a problem hiding this comment.
so should I remove that ?
There was a problem hiding this comment.
so should I remove that ?
I don't know, here we need more experienced person to give us the information
chart/values.schema.json
Outdated
| } | ||
| } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
missing new line with EOF
Updated the description for retentionMinutes to clarify its relation to retentionDays.
| }, | ||
| "retentionMinutes": { | ||
| "description": "Number of minutes to retain the logs when running the Airflow log groomer sidecar.", | ||
| "description": "Total retention time is retentionDays + retentionMinutes.", |
There was a problem hiding this comment.
Was there a mishap with this commit? ^^ you replaced the description instead of adding :)
|
There are lots of issues here. If you want to add minute retetion, you should likely change the extisting values - not to add more parameters. |
What about backwards compatibility? |
|
Hi! I have the fixes ready so we can merge this. What should be the approach? Can I commit to this PR? Maybe creating a new PR coauthoring @shreeharshshinde ? |
@Wastelander777 Since this is a PR from a fork of @shreeharshshinde, you will not be able to commit to this PR unless he is adding you to his fork repo. |
| # Number of minutes to retain logs. | ||
| # This can be used for finer granularity than days. | ||
| # Total retention is retentionDays + retentionMinutes. | ||
| retentionMinutes: 0 |
There was a problem hiding this comment.
Have you considered instead of adding another parameter (plus all the complexity with this) to support fractions, e.g. retentionDays: 15.5 to make it every 15 days plus 12h? Or 0.0139 to have it every 20 minutes.
There was a problem hiding this comment.
I have thought on that - and scraped the idea immediately :) Usability is too bad imo
There was a problem hiding this comment.
I agree with @n-badtke-cg, I think at the user level is harder to define the retention that way.
There was a problem hiding this comment.
Also: we need to calculate minutes anyway because the -mtime only takes integers, so we cannot use fractional days with -mtime, we need to use -mmin anyway. Then, we need to catch weird calculations, because -mmin also takes integers only.
There was a problem hiding this comment.
also an example: 10 minutes.
fractional days = 10min / (24hours * 60min) = 0,00694444444444444444444444444444...
|
@shreeharshshinde This PR has been converted to draft because it does not yet meet our Pull Request quality criteria. Issues found:
What to do next:
Converting a PR to draft is not a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. If you have questions, feel free to ask on the Airflow Slack. |
|
This PR fell behind PR #61855 |
|
This PR is obsolete now since PR #61855 got merged |
What does this PR support ?
Adds support for configuring Docker log cleanup retention in minutes via a new environment variable:
When this variable is set, the log groomer uses
find -mminto delete.logfiles older than the specified number of minutes. If it is not set, the existing behavior based onAIRFLOW__LOG_RETENTION_DAYSremains unchanged.Why
Day-level retention granularity can be too coarse for large-scale deployments generating high log volumes. This can result in excessive local log file accumulation, which negatively impacts log exporters such as the OpenTelemetry Collector FileLogReceiver that perform poorly when handling large file counts.
This change enables more precise log cleanup scheduling without breaking existing configurations.
How
Introduced
AIRFLOW__LOG_RETENTION_MINUTESAdded conditional logic in
scripts/docker/clean-logs.sh:-mminwhen minutes retention is provided-mtimelogic otherwisePreserved existing pruning, filtering, and empty directory cleanup behavior
Backward Compatibility
No breaking changes:
AIRFLOW__LOG_RETENTION_DAYScontinues to workTesting
Fixes #61814