Make OpenSearch log handler respect the per-run log ID template#69897
Draft
jason810496 wants to merge 5 commits into
Draft
Make OpenSearch log handler respect the per-run log ID template#69897jason810496 wants to merge 5 commits into
jason810496 wants to merge 5 commits into
Conversation
The LogTemplate model pins the log_id template to each Dag run so task logs written before a config change stay readable, but the Airflow 3 paths of the Elasticsearch and OpenSearch handlers rendered log_id from the current conf value on both the write (worker) and read (API server) sides, so changing [elasticsearch/opensearch] log_id_template orphaned all previously written logs. Workers cannot query the metadata DB, so the pinned template is delivered to the supervisor through a new optional TIRunContext field populated by the ti_run Execution API endpoint (with a version migration for older clients); the API-server read paths restore the per-run lookup directly. Handlers that do not opt into the new ti_context keyword keep their existing upload signature and behavior.
…r-side TIs Worker-side RuntimeTIs have no get_dagrun and cannot reach the metadata DB; the pinned template reaches them through TIRunContext instead. Opening a session just to fail also trips the DB-access guard (AirflowInternalRuntimeError is a BaseException, so the fallback except clause cannot catch it) in non-DB test runs.
…n supervisor tests The remote-logging supervisor tests drop airflow.sdk.log (and the logging-config modules) from sys.modules to force a fresh import, but the re-import rebinds the attribute on the parent package and monkeypatch only restores the sys.modules entry. On Python < 3.12 mock.patch resolves dotted targets through getattr on the parent package, so later tests on the same worker patched the stale module object while the code under test imported the restored one, failing test_upload_logs_forwards_ti_context and TestUploadToRemoteTIContext::test_no_ti_context_keeps_handler_default in CI.
Keep this branch scoped to the core plumbing (Execution API and Task SDK) that delivers the per-run log ID template to workers. The Elasticsearch and OpenSearch handler changes re-land in per-provider PRs stacked on this branch, so each provider change can be reviewed and released on its own cadence.
The LogTemplate model pins the log_id template to each Dag run so task logs written before a config change stay readable, but the Airflow 3 paths of the OpenSearch handler rendered log_id from the current conf value on both the write (worker) and read (API server) sides, so changing [opensearch] log_id_template orphaned all previously written logs. The write side now uses the pinned template that the supervisor receives through TIRunContext (added by the core change this branch is stacked on), and the API-server read paths restore the per-run DB lookup with a conf fallback.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
providers/opensearch) is new; the base commits are the core plumbing that delivers the pinned template to workers and will disappear from the diff once Deliver the per-run log ID template to workers via TIRunContext #69688 merges.Why
The
LogTemplatemodel pins the log ID template to each Dag run so task logs written before a config change stay readable, but the Airflow 3 paths of the OpenSearch handler renderlog_idfrom the current conf value on both the write (worker) and read (API server) sides — so changing[opensearch] log_id_templateorphans every previously written log document.What
RemoteLogIO.uploadopts into theti_contextkeyword and renders the log ID from the Dag-run-pinned template delivered viaTIRunContext.log_id_template(Deliver the per-run log ID template to workers via TIRunContext #69688)._read,get_external_log_url,RemoteLogIO.read): restore the per-runLogTemplatelookup with a conf fallback when the DB is unreachable or the row is missing — the same pattern the legacyOsTaskHandleralready used; worker-sideRuntimeTIs skip the DB lookup entirely._render_log_idnow always supplies the full placeholder set (logical_date,execution_date,data_interval_start/end) because templates pinned by older rows use them andstr.formatraisesKeyErroron missing names.Was generative AI tooling used to co-author this PR?