Managed Airflow DAG Troubleshooting

Managed Airflow DAG Troubleshooting

Troubleshoots failed Airflow DAG runs and task instances in Managed Airflow by fetching logs and code with gcloud and giving a grounded, deterministic diagnosis.

Skill files2 files

references/

SKILL.md346 lines
1
---
2
name: managed-airflow-dag-troubleshooting
3
description: >-
4
Provides guidance for troubleshooting Apache Airflow DAGs (failed DAG runs and task instances) in Managed Service for
5
Apache Airflow (MSAA; formerly Cloud Composer). Use when figuring out reasons for DAG run or task instance failures. Don't
6
use when looking for overall recommendations for Managed Airflow environment performance.
7
metadata:
8
version: "1.0.1"
9
category: BigDataAndAnalytics
10
---
11
12
# Managed Service for Apache Airflow (formerly Cloud Composer) DAG troubleshooting guide
13
14
This skill provides instructions for troubleshooting Managed Airflow DAGs (DAG
15
runs and task instances), utilizing `gcloud composer`, `gcloud logging` and
16
`gcloud storage` commands to fetch remote logs and code.
17
18
## Attribution
19
20
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
21
MUST read [Usage Attribution](references/attribution.md). For commands executed
22
directly in the terminal (never in generated scripts, Terraform, or user code),
23
prefix `gcloud` with
24
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:managed-airflow-dag-troubleshooting)"`
25
and append `agent-skills/1.0 (skill:managed-airflow-dag-troubleshooting)` to `User-Agent` headers.
26
27
## General rules
28
29
1. Provide suggestions on how to troubleshoot the failed jobs. Provide only the
30
steps that the user can actually take. Ground all troubleshooting advice in
31
direct findings.
32
2. When troubleshooting a failure, follow the following practices to always
33
provide a deterministic diagnosis:
34
35
* **Fetch relevant logs**: Always fetch the logs for a task under
36
investigation using `gcloud logging read`; check the logs for specific
37
error patterns: Python tracebacks, API error codes (e.g., 400, 403, 404,
38
500), or Airflow signals (e.g., `AirflowTaskTimeout`).
39
* **Fetch task metadata**: When troubleshooting a task, fetch the task
40
state and metadata (execution state, try number, timestamps, and
41
execution details) using:
42
43
```bash
44
gcloud composer environments run {env_name} \
45
--location {location} \
46
tasks states-for-dag-run -- -d {dag_id} -r {run_id}
47
```
48
49
or for an individual task instance:
50
51
```bash
52
gcloud composer environments run {env_name} \
53
--location {location} \
54
tasks state -- {dag_id} {task_id} {execution_date}
55
```
56
* **Retrieve and compare DAG source code**: Download the remote DAG source
57
code using `gcloud storage cp gs://{bucket_name}/dags/{dag_file}.py .`
58
(find the environment bucket via `gcloud composer environments describe
59
{env_name} --location {location}
60
--format="value(config.dagGcsPrefix)"`). Compare the parameters in the
61
code (e.g., table IDs, disk sizes, URI paths) against the error messages
62
found in the task logs.
63
* **Explain code mistakes and potential fixes**: Explain mistakes in the
64
code (if any are actually visible); suggest potential fixes (if they are
65
very likely to be meaningful); discuss source code availability if
66
needed - if some source code is unavailable (e.g. imported from a file
67
other than the main source code file), mention this (you can mention the
68
package name) - in such a case take into account most likely trigger
69
rules if they are unknown.
70
* **Check for environment-level errors**: Query Cloud Logging with `gcloud
71
logging read` to see if there are high-level environment issues or known
72
platform errors correlating with the failure (see **Known issues**
73
below). You MUST return ALL found issues.
74
* **Identify failing tasks in a DAG run**: When troubleshooting a failed
75
DAG run, mention the task that caused a failure (use `tasks
76
states-for-dag-run` or Cloud Logging to identify failed tasks). Provide
77
a task instance name. If many tasks failed, mention which task was
78
critical (mandatory for successful DAG run execution - look into task
79
dependencies and trigger rules) and focus on this one.
80
* **Verify service configurations in code**: If logs suggest an issue with
81
a specific service (e.g., BigQuery, Dataform, Compute Engine), use the
82
log details to verify the configuration in the DAG source code.
83
* **Correlate logs with code**: E.g., if BigQuery returns a 404, verify
84
the dataset ID or table ID in the DAG source code matches reality.
85
* **Prioritize known platform issues**: Check against **Known issues**
86
below. If Cloud Logging queries return matching platform error signals,
87
prioritize that diagnosis.
88
89
3. **Summarize with Evidence (Deterministic Response):** Your response must be
90
specific. Avoid general advice like 'check your permissions.' or 'check the
91
logs.' Instead, say 'The service account is missing X permission.'
92
93
* **Problem:** State the specific root cause and the exact task instance
94
ID. Identify if it is a code logic error, a configuration mismatch, or
95
an environment timeout.
96
* **Evidence:** **Mandatory.** Provide the verbatim text from the log
97
(`textPayload`) or the specific line of code from the DAG that caused
98
the failure. Do not summarize the evidence; show the data.
99
* **Recommendation:** Provide an actionable fix. If it is a code error,
100
provide the corrected Python snippet. If it is a resource issue, specify
101
the exact configuration change needed.
102
103
4. **DAGs Generated by Orchestration Pipelines:** Some DAGs may be generated by
104
Orchestration Pipelines. A special requirement related to those DAGs is the
105
need to explain the failure in terms of the logical actions defined in the
106
pipeline YAML.
107
108
* **Determine if a DAG is generated by Orchestration Pipelines**:
109
Orchestration Pipeline DAGs deployed by dedicated tools have
110
`bundle_name`, `version_id`, and `pipeline_name` set in their DAG Run
111
metadata (`DagRun.note` that contains JSON metadata). All of them (i.e.
112
Orchestration Pipeline DAGs deployed by dedicated tools and created
113
manually) have an `op:orchestration_pipeline` tag set (DAG properties,
114
including tags, can be verified in the DAG source code or via `gcloud
115
composer environments run {env_name} --location {location} dags list`).
116
* Orchestration Pipeline DAGs deployed by dedicated tools have
117
additionally the following tags (information in those tags should be
118
consistent with data in DAG Run attributes mentioned above):
119
* pipeline name - tag `op:pipeline`, e.g. `op:pipeline:xyz` indicates
120
a name `xyz`
121
* bundle name - tag `op:bundle`
122
* version id - tag `op:version`
123
* **Retrieve the resolved pipeline YAML definition from the environment
124
bucket**:
125
* Determine the YAML file location:
126
1. Retrieve the DAG source code from the environment bucket using
127
`gcloud storage cp gs://{bucket_name}/dags/{dag_file}.py .` (or
128
`gcloud storage cat gs://{bucket_name}/dags/{dag_file}.py`).
129
2. Inspect the source code for `generate` or `generate_dags`
130
function calls:
131
* Scenario 1: `generate` call found. The first argument is the
132
path to the YAML file - relative to the `dags` folder in
133
environment's bucket.
134
* Scenario 2: `generate_dags` call found.
135
* Extract the first argument - this is the data folder. If
136
it starts with `/home/airflow/gcs/`, remove this prefix
137
to get a path relative to the root of environment's
138
bucket.
139
* Extract `bundle_name`, `version_id`, and `pipeline_name`
140
(as explained above).
141
* Construct the path:
142
`{data_directory}/{bundle_name}/versions/{version_id}/{pipeline_name}.yml`
143
(or `.yaml`).
144
* Scenario 3: If neither call is found, default to the path:
145
`data/{bundle_name}/versions/{version_id}/{pipeline_name}.yml`
146
(or `.yaml`) in an environment's bucket.
147
3. Download the YAML file using `gcloud storage cp
148
gs://{bucket_name}/{yaml_path} .` (or `gcloud storage cat
149
gs://{bucket_name}/{yaml_path}`).
150
* Map the failed Airflow task back to the logical action name using task
151
instance metadata/notes (e.g. `op_action_name` in task `note`).
152
* If the failure involves user assets (like Python scripts), check their
153
path in the action definition. If they are in the environment bucket,
154
download and read them to debug (`gcloud storage cp
155
gs://{bucket_name}/{asset_path} .`). If they are in a custom artifact
156
bucket (see GCS URIs in logs/config), note the limitation that they
157
cannot be read directly but analyze based on available logs.
158
159
5. You can assume that environment variables set by default (they can be used
160
in DAG code, but are not visible in custom environment configuration), e.g.
161
`GCS_BUCKET`, are correct - users cannot change them.
162
163
6. "Not found" (404) errors from GCP APIs can be misleading. A "not found"
164
error might be returned when a resource actually exists, but the caller does
165
not have permissions to access or view it. If a resource is expected to
166
exist, suggest verifying proper permissions.
167
168
### Important constraints & instructions
169
170
* **Read-Only First**: Do NOT attempt to fix the code immediately. You must
171
first prove the root cause using logs and remote code.
172
* **No Speculation**: If logs are empty or code cannot be found, state this
173
clearly. Always reference error messages as the are.
174
* **Safety**: Be careful with secrets. If logs contain sensitive information
175
(e.g. passwords), redact it in your analysis.
176
177
### Applying Fixes - only if explicitly requested
178
179
When the RCA is complete and a fix is ready:
180
181
1. **Repository Check**: If the current workspace does not seem to be the
182
source of truth for the Managed Airflow environment:
183
* Ask the user to **open the correct repository**.
184
* OR ask if they want to **download the remote DAG** to the current
185
workspace to apply the fix (warning them about potential overwrites).
186
187
## Relevant gcloud commands
188
189
### Environment & DAG Discovery
190
191
* **List composer environments:**
192
193
```bash
194
gcloud composer environments list \
195
--locations=us-central1 \
196
--format="table(name,location,state)"
197
```
198
* **Describe environment (get DAGs bucket and config):**
199
200
```bash
201
gcloud composer environments describe {env_name} \
202
--location {region} \
203
--format="value(config.dagGcsPrefix)"
204
```
205
* **List composer DAGs:**
206
207
```bash
208
gcloud composer environments run {env_name} \
209
--location {region} \
210
dags list
211
```
212
* **List composer DAG Runs:**
213
214
```bash
215
gcloud composer environments run {env_name} \
216
--location {region} \
217
dags list-runs -- -d {dag_id} --no-backfill
218
```
219
* **List task instance states for a DAG run:**
220
221
```bash
222
gcloud composer environments run {env_name} \
223
--location {region} \
224
tasks states-for-dag-run -- -d {dag_id} -r {run_id}
225
```
226
* **Get state of a specific task instance:**
227
228
```bash
229
gcloud composer environments run {env_name} \
230
--location {region} \
231
tasks state -- {dag_id} {task_id} {execution_date}
232
```
233
234
### Log Retrieval
235
236
* **Fetch error logs for a DAG / Task:**
237
238
```bash
239
gcloud logging read 'resource.type="cloud_composer_environment" AND resource.labels.environment_name="{env_name}" AND labels.dag_id="{dag_id}" AND severity>=ERROR' \
240
--limit=25 \
241
--format="table(timestamp,severity,labels.task_id,textPayload)"
242
```
243
* **Fetch scheduler logs for environment failures:**
244
245
```bash
246
gcloud logging read 'resource.type="cloud_composer_environment" AND resource.labels.environment_name="{env_name}" AND log_id("airflow-scheduler") AND severity>=ERROR' \
247
--limit=25 \
248
--format="table(timestamp,severity,textPayload)"
249
```
250
251
### Code & Asset Retrieval
252
253
* **Download DAG code from GCS:**
254
255
```bash
256
gcloud storage cp gs://{bucket_name}/dags/{dag_file}.py .
257
```
258
* **Download pipeline YAML definition or script from GCS:**
259
260
```bash
261
gcloud storage cp gs://{bucket_name}/{path_to_file} .
262
```
263
264
## Known issues related to DAG runs and task instances
265
266
Use `gcloud logging read` with the queries below to identify specific known
267
platform failure modes:
268
269
### 1. DAG_RUN_TIMEOUT
270
271
* **Issue summary:** The task instance execution was interrupted because a
272
timeout for a DAG was exceeded. Unfinished tasks were marked as 'SKIPPED' or
273
failed.
274
* **Cloud Logging Query:**
275
276
```bash
277
gcloud logging read 'resource.type="cloud_composer_environment" AND resource.labels.environment_name="{env_name}" AND log_id("airflow-scheduler") AND textPayload=~"Run .* of .* has timed-out"' --limit=10
278
```
279
280
### 2. TASK_QUEUED_TIMEOUT
281
282
* **Issue summary:** Task failed because it remained queued longer than the
283
maximum allowed queue time.
284
* **Cloud Logging Query:**
285
286
```bash
287
gcloud logging read 'resource.type="cloud_composer_environment" AND resource.labels.environment_name="{env_name}" AND log_id("airflow-scheduler") AND textPayload=~"Task requeue attempts exceeded max; marking failed"' --limit=10
288
```
289
* **Remediation:** Consider increasing worker resources (CPU, memory, worker
290
count) or adjusting `[celery]worker_concurrency`.
291
292
### 3. TASK_STUCK_IN_QUEUE
293
294
* **Issue summary:** Task reached DAG run timeout because task was stuck in
295
queue for too long.
296
* **Cloud Logging Query:**
297
298
```bash
299
gcloud logging read 'resource.type="cloud_composer_environment" AND resource.labels.environment_name="{env_name}" AND log_id("airflow-scheduler") AND textPayload=~"Task stuck in queued; will try to requeue"' --limit=10
300
```
301
* **Remediation:** Consider increasing the timeout or reducing the load on the
302
environment.
303
304
### 4. BIGQUERY_JOB_FAILED
305
306
* **Issue summary:** Task failed because of a BigQuery job failure inside a
307
BigQuery operator.
308
* **Cloud Logging Query:**
309
310
```bash
311
gcloud logging read 'resource.type="cloud_composer_environment" AND resource.labels.environment_name="{env_name}" AND (log_id("airflow-worker") OR log_id("airflow-k8s-worker")) AND textPayload:"airflow/providers/google/cloud/operators/bigquery.py" AND textPayload:"Task failed with exception" AND severity=ERROR' --limit=10
312
```
313
* **Remediation:** Inspect the worker logs for the BigQuery Job ID (`Job ID:
314
...`) to diagnose the underlying query error or permissions issue.
315
316
### 5. DETECTED_ZOMBIE
317
318
* **Issue summary:** The task instance was revoked by the executor due to
319
missing heartbeats. Task instances send heartbeats periodically (every
320
`job_heartbeat_sec`, 5 seconds by default) and if heartbeats are missing for
321
`scheduler_zombie_task_threshold` (300 seconds by default), the task is
322
considered a zombie and marked as failed or up for retry.
323
* **Cloud Logging Query:**
324
325
```bash
326
gcloud logging read 'resource.type="cloud_composer_environment" AND resource.labels.environment_name="{env_name}" AND log_id("airflow-scheduler") AND (textPayload:"Detected zombie job:" OR textPayload:"Detected a task instance without a heartbeat:")' --limit=10
327
```
328
* **Remediation:** This can happen when a worker is overloaded (CPU/memory
329
starvation) and unable to send heartbeats on time, a worker was terminated
330
with unfinished tasks (OOM kill/eviction), or the metadata database is
331
overloaded. Check worker metrics and consider scaling worker CPU/memory.
332
333
### 6. WORKER_OUT_OF_POD_STORAGE
334
335
* **Issue summary:** Task instance failed because a worker is running out of
336
pod storage (ephemeral disk space reached or pod evicted due to storage
337
limits).
338
* **Cloud Logging Query:**
339
340
```bash
341
gcloud logging read 'resource.type="cloud_composer_environment" AND resource.labels.environment_name="{env_name}" AND (log_id("airflow-worker") OR log_id("airflow-k8s-worker")) AND textPayload:"Pod ephemeral local storage usage exceeds the total limit of containers"' --limit=10
342
```
343
* **Remediation:** Update the worker storage configuration according to the
344
amount of data being stored or clean up temporary files created during task
345
execution.
346

© Google LLC · Apache 2.0 · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…