Skip to content

Commit 7869fd4

Browse files
author
goingforstudying-ctrl
committed
fix(google): address review feedback on stackdriver label extraction
- Rename _labels_from_path to _extract_labels_from_path - Use path labels as fallback instead of overriding event-derived labels - Actually store run_id instead of no-op pass branch
1 parent 61608fe commit 7869fd4

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

providers/google/src/airflow/providers/google/cloud/log/stackdriver_task_handler.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,12 @@ def proc(
184184
if map_index := event.get("map_index"):
185185
labels["map_index"] = str(map_index)
186186
# In AF3 supervisor context record.task_instance is not set.
187-
# Parse labels from the structured log path as additional fallback.
188-
path_labels = _labels_from_path(str(relative))
189-
labels.update(path_labels)
187+
# Parse labels from the structured log path as fallback only for
188+
# keys that are still missing after the event-derived labels.
189+
path_labels = _extract_labels_from_path(str(relative))
190+
for key, value in path_labels.items():
191+
if key not in labels:
192+
labels[key] = value
190193
_transport.send(record, str(msg.get("event", "")), resource=self.resource, labels=labels)
191194
return event
192195

@@ -282,14 +285,14 @@ def _read_single_logs_page(self, log_filter: str, page_token: str | None = None)
282285
return "\n".join(messages), page.next_page_token
283286

284287

285-
def _labels_from_path(relative_path: str) -> dict[str, str]:
288+
def _extract_labels_from_path(relative_path: str) -> dict[str, str]:
286289
"""Parse AF3 log path into Stackdriver labels.
287290
288291
AF3's log path template is::
289292
290293
dag_id=<x>/run_id=<x>/task_id=<x>/attempt=<N>.log
291294
292-
All four label fields are extracted with zero DB access. When the path
295+
All label fields are extracted with zero DB access. When the path
293296
does not match the expected format the function returns an empty dict
294297
so callers can fall back to other label sources.
295298
"""
@@ -308,10 +311,7 @@ def _labels_from_path(relative_path: str) -> dict[str, str]:
308311
elif key == "attempt":
309312
labels[LABEL_TRY_NUMBER] = value
310313
elif key == "run_id":
311-
# run_id is NOT a standard Stackdriver label yet, but it is used
312-
# on the write side via the log path template. Store it so the
313-
# read path can filter on it (Bug 2 will wire this up).
314-
pass
314+
labels["run_id"] = value
315315
return labels
316316

317317

0 commit comments

Comments
 (0)