Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -1249,10 +1249,11 @@ set -euo pipefail

readonly DIRECTORY="${AIRFLOW_HOME:-/usr/local/airflow}"
readonly RETENTION="${AIRFLOW__LOG_RETENTION_DAYS:-15}"
readonly FREQUENCY="${AIRFLOW__LOG_CLEANUP_FREQUENCY_MINUTES:-15}"

trap "exit" INT TERM

readonly EVERY=$((15*60))
readonly EVERY=$((FREQUENCY*60))

echo "Cleaning logs every $EVERY seconds"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,15 @@ spec:
{{- if .Values.dagProcessor.logGroomerSidecar.args }}
args: {{- tpl (toYaml .Values.dagProcessor.logGroomerSidecar.args) . | nindent 12 }}
{{- end }}
{{- if .Values.dagProcessor.logGroomerSidecar.retentionDays }}
env:
{{- if .Values.dagProcessor.logGroomerSidecar.retentionDays }}
- name: AIRFLOW__LOG_RETENTION_DAYS
value: "{{ .Values.dagProcessor.logGroomerSidecar.retentionDays }}"
{{- end }}
{{- if .Values.dagProcessor.logGroomerSidecar.frequencyMinutes }}
- name: AIRFLOW__LOG_CLEANUP_FREQUENCY_MINUTES
value: "{{ .Values.dagProcessor.logGroomerSidecar.frequencyMinutes }}"
{{- end }}
- name: AIRFLOW_HOME
value: "{{ .Values.airflowHome }}"
{{- end }}
Expand Down
7 changes: 6 additions & 1 deletion chart/templates/scheduler/scheduler-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,15 @@ spec:
{{- if .Values.scheduler.logGroomerSidecar.args }}
args: {{- tpl (toYaml .Values.scheduler.logGroomerSidecar.args) . | nindent 12 }}
{{- end }}
{{- if .Values.scheduler.logGroomerSidecar.retentionDays }}
env:
{{- if .Values.scheduler.logGroomerSidecar.retentionDays }}
- name: AIRFLOW__LOG_RETENTION_DAYS
value: "{{ .Values.scheduler.logGroomerSidecar.retentionDays }}"
{{- end }}
{{- if .Values.scheduler.logGroomerSidecar.frequencyMinutes }}
- name: AIRFLOW__LOG_CLEANUP_FREQUENCY_MINUTES
value: "{{ .Values.scheduler.logGroomerSidecar.frequencyMinutes }}"
{{- end }}
- name: AIRFLOW_HOME
value: "{{ .Values.airflowHome }}"
{{- end }}
Expand Down
7 changes: 6 additions & 1 deletion chart/templates/triggerer/triggerer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,15 @@ spec:
{{- if .Values.triggerer.logGroomerSidecar.args }}
args: {{- tpl (toYaml .Values.triggerer.logGroomerSidecar.args) . | nindent 12 }}
{{- end }}
{{- if .Values.triggerer.logGroomerSidecar.retentionDays }}
env:
{{- if .Values.triggerer.logGroomerSidecar.retentionDays }}
- name: AIRFLOW__LOG_RETENTION_DAYS
value: "{{ .Values.triggerer.logGroomerSidecar.retentionDays }}"
{{- end }}
{{- if .Values.triggerer.logGroomerSidecar.frequencyMinutes }}
- name: AIRFLOW__LOG_CLEANUP_FREQUENCY_MINUTES
value: "{{ .Values.triggerer.logGroomerSidecar.frequencyMinutes }}"
{{- end }}
- name: AIRFLOW_HOME
value: "{{ .Values.airflowHome }}"
{{- end }}
Expand Down
7 changes: 6 additions & 1 deletion chart/templates/workers/worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,15 @@ spec:
{{- if .Values.workers.logGroomerSidecar.args }}
args: {{ tpl (toYaml .Values.workers.logGroomerSidecar.args) . | nindent 12 }}
{{- end }}
{{- if .Values.workers.logGroomerSidecar.retentionDays }}
env:
{{- if .Values.workers.logGroomerSidecar.retentionDays }}
- name: AIRFLOW__LOG_RETENTION_DAYS
value: "{{ .Values.workers.logGroomerSidecar.retentionDays }}"
{{- end }}
{{- if .Values.workers.logGroomerSidecar.frequencyMinutes }}
- name: AIRFLOW__LOG_CLEANUP_FREQUENCY_MINUTES
value: "{{ .Values.workers.logGroomerSidecar.frequencyMinutes }}"
{{- end }}
- name: AIRFLOW_HOME
value: "{{ .Values.airflowHome }}"
{{- end }}
Expand Down
5 changes: 5 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11804,6 +11804,11 @@
"type": "integer",
"default": 15
},
"frequencyMinutes": {
"description": "Number of minutes between attempts to groom the Airflow logs in log groomer sidecar.",
"type": "integer",
"default": 15
},
"resources": {
"description": "Resources for Airflow log groomer sidecar.",
"type": "object",
Expand Down
8 changes: 8 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,8 @@ workers:
args: ["bash", "/clean-logs"]
# Number of days to retain logs
retentionDays: 15
# frequency to attempt to groom logs, in minutes
frequencyMinutes: 15
resources: {}
# limits:
# cpu: 100m
Expand Down Expand Up @@ -953,6 +955,8 @@ scheduler:
args: ["bash", "/clean-logs"]
# Number of days to retain logs
retentionDays: 15
# frequency to attempt to groom logs, in minutes
frequencyMinutes: 15
resources: {}
# limits:
# cpu: 100m
Expand Down Expand Up @@ -1636,6 +1640,8 @@ triggerer:
args: ["bash", "/clean-logs"]
# Number of days to retain logs
retentionDays: 15
# frequency to attempt to groom logs, in minutes
frequencyMinutes: 15
resources: {}
# limits:
# cpu: 100m
Expand Down Expand Up @@ -1820,6 +1826,8 @@ dagProcessor:
args: ["bash", "/clean-logs"]
# Number of days to retain logs
retentionDays: 15
# frequency to attempt to groom logs, in minutes
frequencyMinutes: 15
resources: {}
# limits:
# cpu: 100m
Expand Down
3 changes: 2 additions & 1 deletion scripts/docker/clean-logs.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ set -euo pipefail

readonly DIRECTORY="${AIRFLOW_HOME:-/usr/local/airflow}"
readonly RETENTION="${AIRFLOW__LOG_RETENTION_DAYS:-15}"
readonly FREQUENCY="${AIRFLOW__LOG_CLEANUP_FREQUENCY_MINUTES:-15}"

trap "exit" INT TERM

readonly EVERY=$((15*60))
readonly EVERY=$((FREQUENCY*60))

echo "Cleaning logs every $EVERY seconds"

Expand Down
35 changes: 33 additions & 2 deletions tests/charts/log_groomer.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,35 @@ def test_log_groomer_retention_days_overrides(self, retention_days, retention_re
"spec.template.spec.containers[1].env[0].value", docs[0]
)
else:
assert jmespath.search("spec.template.spec.containers[1].env", docs[0]) is None
assert len(jmespath.search("spec.template.spec.containers[1].env", docs[0])) == 2

@pytest.mark.parametrize("frequency_minutes, frequency_result", [(None, None), (20, "20")])
def test_log_groomer_frequency_minutes_overrides(self, frequency_minutes, frequency_result):
if self.obj_name == "dag-processor":
values = {
"dagProcessor": {
"enabled": True,
"logGroomerSidecar": {"frequencyMinutes": frequency_minutes},
}
}
else:
values = {f"{self.folder}": {"logGroomerSidecar": {"frequencyMinutes": frequency_minutes}}}

docs = render_chart(
values=values,
show_only=[f"templates/{self.folder}/{self.obj_name}-deployment.yaml"],
)

if frequency_result:
assert (
jmespath.search(
"spec.template.spec.containers[1].env[?name=='AIRFLOW__LOG_CLEANUP_FREQUENCY_MINUTES'].value | [0]",
docs[0],
)
== frequency_result
)
else:
assert len(jmespath.search("spec.template.spec.containers[1].env", docs[0])) == 2

def test_log_groomer_resources(self):
if self.obj_name == "dag-processor":
Expand Down Expand Up @@ -214,4 +242,7 @@ def test_log_groomer_has_airflow_home(self):
values=values, show_only=[f"templates/{self.folder}/{self.obj_name}-deployment.yaml"]
)

assert "AIRFLOW_HOME" == jmespath.search("spec.template.spec.containers[1].env[1].name", docs[0])
assert (
jmespath.search("spec.template.spec.containers[1].env[?name=='AIRFLOW_HOME'].name | [0]", docs[0])
== "AIRFLOW_HOME"
)
Loading