You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "amoghrajesh (via GitHub)" <gi...@apache.org> on 2025/01/24 17:32:50 UTC
[PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
amoghrajesh opened a new pull request, #46020:
URL: https://github.com/apache/airflow/pull/46020
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1930703697
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -442,6 +444,48 @@ def get_previous_successful_dagrun(
return PrevSuccessfulDagRunResponse.model_validate(dag_run)
+@router.post(
+ "/{task_instance_id}/runtime-checks",
+ status_code=status.HTTP_200_OK,
+ # TODO: Add description to the operation
+ # TODO: Add Operation ID to control the function name in the OpenAPI spec
+ # TODO: Do we need to use create_openapi_http_exception_doc here?
+ responses={
+ status.HTTP_400_BAD_REQUEST: {
+ "description": "Task Instance doesn't pass the required runtime checks"
+ },
+ status.HTTP_204_NO_CONTENT: {
+ "description": "Task Instance is not in a running state, cannot perform runtime checks."
+ },
+ status.HTTP_422_UNPROCESSABLE_ENTITY: {
+ "description": "Invalid payload for requested runtime checks on the Task Instance."
+ },
+ },
+)
+def ti_runtime_checks(
+ task_instance_id: UUID,
+ payload: TIRuntimeCheckPayload,
+ session: SessionDep,
+):
+ ti_id_str = str(task_instance_id)
+ task_instance = session.scalar(select(TI).where(TI.id == ti_id_str))
+ if task_instance.state != State.RUNNING:
+ return Response(status_code=status.HTTP_204_NO_CONTENT)
Review Comment:
I don't think it matters/is avoidable, but previously the asset checks were done before the task was put in to the running state right?
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -442,6 +444,48 @@ def get_previous_successful_dagrun(
return PrevSuccessfulDagRunResponse.model_validate(dag_run)
+@router.post(
+ "/{task_instance_id}/runtime-checks",
+ status_code=status.HTTP_200_OK,
+ # TODO: Add description to the operation
+ # TODO: Add Operation ID to control the function name in the OpenAPI spec
+ # TODO: Do we need to use create_openapi_http_exception_doc here?
+ responses={
+ status.HTTP_400_BAD_REQUEST: {
+ "description": "Task Instance doesn't pass the required runtime checks"
+ },
+ status.HTTP_204_NO_CONTENT: {
+ "description": "Task Instance is not in a running state, cannot perform runtime checks."
Review Comment:
Message is wrong :)
##########
task_sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -767,6 +768,14 @@ def _handle_request(self, msg: ToSupervisor, log: FilteringBoundLogger):
if isinstance(msg, TaskState):
self._terminal_state = msg.state
self._task_end_time_monotonic = time.monotonic()
+ elif isinstance(msg, RuntimeCheckOnTask):
+ runtime_check_resp = self.client.task_instances.runtime_checks(id=self.id, msg=msg)
+ resp = runtime_check_resp.model_dump_json().encode()
+ if not runtime_check_resp.ok:
+ log.debug("Runtime checks failed on task %s, marking task as failed..", self.id)
+ self.client.task_instances.finish(
+ id=self.id, state=TerminalTIState.FAILED, when=datetime.now(tz=timezone.utc)
+ )
Review Comment:
I'm not sure we should directly mark the task as failed here -- or at the least I think the task subprocess should be told about it so that it can run on_failure callbacks etc.
##########
airflow/api_fastapi/execution_api/datamodels/taskinstance.py:
##########
@@ -249,3 +249,10 @@ class PrevSuccessfulDagRunResponse(BaseModel):
data_interval_end: UtcDateTime | None = None
start_date: UtcDateTime | None = None
end_date: UtcDateTime | None = None
+
+
+class TIRuntimeCheckPayload(BaseModel):
+ """Payload for performing Runtime checks on the TaskInstance model as requested by the SDK."""
+
+ inlet: list[AssetProfile] | None = None
+ outlet: list[AssetProfile] | None = None
Review Comment:
Nit:
```suggestion
inlets: list[AssetProfile] | None = None
outlets: list[AssetProfile] | None = None
```
##########
task_sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -501,6 +503,22 @@ def run(ti: RuntimeTaskInstance, log: Logger):
# TODO: Get a real context object
ti.hostname = get_hostname()
ti.task = ti.task.prepare_for_execution()
+ if ti.task.inlets or ti.task.outlets:
Review Comment:
Nice
##########
task_sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -501,6 +503,22 @@ def run(ti: RuntimeTaskInstance, log: Logger):
# TODO: Get a real context object
ti.hostname = get_hostname()
ti.task = ti.task.prepare_for_execution()
+ if ti.task.inlets or ti.task.outlets:
+ inlets = [
+ AssetProfile(name=x.name or None, uri=x.uri or None, asset_type=Asset.__name__)
+ for x in ti.task.inlets
+ if isinstance(x, Asset)
+ ]
+ outlets = [
+ AssetProfile(name=x.name or None, uri=x.uri or None, asset_type=Asset.__name__)
+ for x in ti.task.outlets
+ if isinstance(x, Asset)
+ ]
+ SUPERVISOR_COMMS.send_request(msg=RuntimeCheckOnTask(inlet=inlets, outlet=outlets), log=log) # type: ignore
+ msg = SUPERVISOR_COMMS.get_message() # type: ignore
+ if isinstance(msg, OKResponse) and not msg.ok:
+ log.info("Runtime checks failed for task, marking task as failed..")
+ return
Review Comment:
I don't see you sending the OKResponse message anywhere...
##########
task_sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -501,6 +503,22 @@ def run(ti: RuntimeTaskInstance, log: Logger):
# TODO: Get a real context object
ti.hostname = get_hostname()
ti.task = ti.task.prepare_for_execution()
+ if ti.task.inlets or ti.task.outlets:
+ inlets = [
+ AssetProfile(name=x.name or None, uri=x.uri or None, asset_type=Asset.__name__)
+ for x in ti.task.inlets
+ if isinstance(x, Asset)
Review Comment:
Is this worth adding an `asprofile` or something method on Asset so we can do
```suggestion
asset.asprofile() for asset in ti.task.inlets if isinstance(asset, Asset)
```
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -442,6 +444,48 @@ def get_previous_successful_dagrun(
return PrevSuccessfulDagRunResponse.model_validate(dag_run)
+@router.post(
+ "/{task_instance_id}/runtime-checks",
+ status_code=status.HTTP_200_OK,
+ # TODO: Add description to the operation
+ # TODO: Add Operation ID to control the function name in the OpenAPI spec
+ # TODO: Do we need to use create_openapi_http_exception_doc here?
+ responses={
+ status.HTTP_400_BAD_REQUEST: {
+ "description": "Task Instance doesn't pass the required runtime checks"
+ },
+ status.HTTP_204_NO_CONTENT: {
+ "description": "Task Instance is not in a running state, cannot perform runtime checks."
+ },
+ status.HTTP_422_UNPROCESSABLE_ENTITY: {
+ "description": "Invalid payload for requested runtime checks on the Task Instance."
+ },
+ },
+)
+def ti_runtime_checks(
+ task_instance_id: UUID,
+ payload: TIRuntimeCheckPayload,
+ session: SessionDep,
+):
+ ti_id_str = str(task_instance_id)
+ task_instance = session.scalar(select(TI).where(TI.id == ti_id_str))
+ if task_instance.state != State.RUNNING:
+ return Response(status_code=status.HTTP_204_NO_CONTENT)
Review Comment:
Returning a 204 if the task isn't in the right state doesn't feel right. This feels more like it should be a HTTP 409 or a 400, and 204 No Content should be for the success path
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931972719
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -442,6 +444,46 @@ def get_previous_successful_dagrun(
return PrevSuccessfulDagRunResponse.model_validate(dag_run)
+@router.post(
+ "/{task_instance_id}/runtime-checks",
+ status_code=status.HTTP_204_NO_CONTENT,
+ # TODO: Add description to the operation
+ # TODO: Add Operation ID to control the function name in the OpenAPI spec
+ # TODO: Do we need to use create_openapi_http_exception_doc here?
+ responses={
+ status.HTTP_400_BAD_REQUEST: {"description": "Task Instance failed the runtime checks."},
+ status.HTTP_409_CONFLICT: {
+ "description": "Task Instance isn't in a running state. Cannot perform runtime checks."
+ },
+ status.HTTP_422_UNPROCESSABLE_ENTITY: {
+ "description": "Invalid payload for requested runtime checks on the Task Instance."
+ },
+ },
+)
+def ti_runtime_checks(
+ task_instance_id: UUID,
+ payload: TIRuntimeCheckPayload,
+ session: SessionDep,
+):
+ ti_id_str = str(task_instance_id)
+ task_instance = session.scalar(select(TI).where(TI.id == ti_id_str))
+ if task_instance.state != State.RUNNING:
+ raise HTTPException(status_code=status.HTTP_409_CONFLICT)
+
+ try:
+ TI.validate_inlet_outlet_assets_activeness(payload.inlets, payload.outlets, session) # type: ignore
Review Comment:
What's the type ignore for here? The Session argument?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931769607
##########
task_sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -767,6 +768,14 @@ def _handle_request(self, msg: ToSupervisor, log: FilteringBoundLogger):
if isinstance(msg, TaskState):
self._terminal_state = msg.state
self._task_end_time_monotonic = time.monotonic()
+ elif isinstance(msg, RuntimeCheckOnTask):
+ runtime_check_resp = self.client.task_instances.runtime_checks(id=self.id, msg=msg)
+ resp = runtime_check_resp.model_dump_json().encode()
+ if not runtime_check_resp.ok:
+ log.debug("Runtime checks failed on task %s, marking task as failed..", self.id)
+ self.client.task_instances.finish(
+ id=self.id, state=TerminalTIState.FAILED, when=datetime.now(tz=timezone.utc)
+ )
Review Comment:
Handled in last batch of commits
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931595038
##########
task_sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -501,6 +503,22 @@ def run(ti: RuntimeTaskInstance, log: Logger):
# TODO: Get a real context object
ti.hostname = get_hostname()
ti.task = ti.task.prepare_for_execution()
+ if ti.task.inlets or ti.task.outlets:
+ inlets = [
+ AssetProfile(name=x.name or None, uri=x.uri or None, asset_type=Asset.__name__)
+ for x in ti.task.inlets
+ if isinstance(x, Asset)
+ ]
+ outlets = [
+ AssetProfile(name=x.name or None, uri=x.uri or None, asset_type=Asset.__name__)
+ for x in ti.task.outlets
+ if isinstance(x, Asset)
+ ]
+ SUPERVISOR_COMMS.send_request(msg=RuntimeCheckOnTask(inlet=inlets, outlet=outlets), log=log) # type: ignore
+ msg = SUPERVISOR_COMMS.get_message() # type: ignore
+ if isinstance(msg, OKResponse) and not msg.ok:
+ log.info("Runtime checks failed for task, marking task as failed..")
+ return
Review Comment:
The message isn't send. It comes from the supervisor from line 518. And if its a "not ok", the task runner logs and doesn't perform rest of the code.
The logic behind OKResponse is like this:
1. Task runner sends a `RuntimeCheckOnTask` call to supervisor
2. Supervisor uses http client to make a REST api call to `runtime_checks` endpoint in the execution API.
3. Supervisor gets `OKResponse` from client
4. Supervisor sends it down to task runner.
5. On line 519, task runner checks if everything is OK, if not, it exits and doesn't execute rest of the code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #46020:
URL: https://github.com/apache/airflow/pull/46020#issuecomment-2618757361
@ashb handled your comments, let me know if the approval still stands :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #46020:
URL: https://github.com/apache/airflow/pull/46020#issuecomment-2623631408
After a hard battle with the CI, we have won! Merging this one
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1930216911
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -442,6 +444,49 @@ def get_previous_successful_dagrun(
return PrevSuccessfulDagRunResponse.model_validate(dag_run)
+@router.post(
+ "/{task_instance_id}/runtime-checks",
+ status_code=status.HTTP_200_OK,
+ # TODO: Add description to the operation
+ # TODO: Add Operation ID to control the function name in the OpenAPI spec
+ # TODO: Do we need to use create_openapi_http_exception_doc here?
+ responses={
+ status.HTTP_400_BAD_REQUEST: {
+ "description": "Task Instance doesn't pass the required runtime checks"
+ },
+ status.HTTP_204_NO_CONTENT: {
+ "description": "Task Instance is not in a running state, cannot perform runtime checks."
+ },
+ status.HTTP_422_UNPROCESSABLE_ENTITY: {
+ "description": "Invalid payload for requested runtime checks on the Task Instance."
+ },
+ },
+)
+def ti_runtime_checks(
+ task_instance_id: UUID,
+ payload: TIRuntimeCheckPayload,
+ session: SessionDep,
+):
+ ti_id_str = str(task_instance_id)
+ task_instance = session.scalar(select(TI).where(TI.id == ti_id_str))
+ if task_instance.state != State.RUNNING:
+ return Response(status_code=status.HTTP_204_NO_CONTENT)
+ else:
Review Comment:
Yeah, that makes sense. Removing it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1932011420
##########
tests/api_fastapi/execution_api/routes/test_task_instances.py:
##########
@@ -655,6 +655,40 @@ def test_ti_update_state_to_failed_without_retry_table_check(self, client, sessi
assert ti.next_kwargs is None
assert ti.duration == 3600.00
+ @pytest.mark.parametrize(
+ ("state", "expected_status_code"),
+ [
+ (State.RUNNING, 204),
+ (State.SUCCESS, 409),
+ (State.QUEUED, 409),
+ (State.FAILED, 409),
Review Comment:
Added in last commit
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on PR #46020:
URL: https://github.com/apache/airflow/pull/46020#issuecomment-2618923925
Yup, still stands. When the changes requested are small enough I often "pre-approve" it to save an extra cycle, and then it's up to you as the PR author to decide it can be merged once the changes are made, or if you need to get a re-review.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931976775
##########
tests/api_fastapi/execution_api/routes/test_task_instances.py:
##########
@@ -655,6 +655,40 @@ def test_ti_update_state_to_failed_without_retry_table_check(self, client, sessi
assert ti.next_kwargs is None
assert ti.duration == 3600.00
+ @pytest.mark.parametrize(
+ ("state", "expected_status_code"),
+ [
+ (State.RUNNING, 204),
+ (State.SUCCESS, 409),
+ (State.QUEUED, 409),
+ (State.FAILED, 409),
Review Comment:
Is it possible to test the 400 error case as well?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #46020:
URL: https://github.com/apache/airflow/pull/46020#issuecomment-2620723310
The CI had some issues lately, just working on a green one so that this can be merged
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh merged PR #46020:
URL: https://github.com/apache/airflow/pull/46020
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1929037322
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -442,6 +444,49 @@ def get_previous_successful_dagrun(
return PrevSuccessfulDagRunResponse.model_validate(dag_run)
+@router.post(
+ "/{task_instance_id}/runtime-checks",
+ status_code=status.HTTP_200_OK,
+ # TODO: Add description to the operation
+ # TODO: Add Operation ID to control the function name in the OpenAPI spec
+ # TODO: Do we need to use create_openapi_http_exception_doc here?
+ responses={
+ status.HTTP_400_BAD_REQUEST: {
+ "description": "Task Instance doesn't pass the required runtime checks"
+ },
+ status.HTTP_204_NO_CONTENT: {
+ "description": "Task Instance is not in a running state, cannot perform runtime checks."
+ },
+ status.HTTP_422_UNPROCESSABLE_ENTITY: {
+ "description": "Invalid payload for requested runtime checks on the Task Instance."
+ },
+ },
+)
+def ti_runtime_checks(
+ task_instance_id: UUID,
+ payload: TIRuntimeCheckPayload,
+ session: SessionDep,
+):
+ ti_id_str = str(task_instance_id)
+ task_instance = session.scalar(select(TI).where(TI.id == ti_id_str))
+ if task_instance.state != State.RUNNING:
+ return Response(status_code=status.HTTP_204_NO_CONTENT)
+ else:
Review Comment:
Nit: Since the if block returns there is no need for the else.
As a general rule if you can have something less indented it is better. (Or to put it another way, the deeper nested the code is, the more complex it is.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1930217931
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -442,6 +444,49 @@ def get_previous_successful_dagrun(
return PrevSuccessfulDagRunResponse.model_validate(dag_run)
+@router.post(
+ "/{task_instance_id}/runtime-checks",
+ status_code=status.HTTP_200_OK,
+ # TODO: Add description to the operation
+ # TODO: Add Operation ID to control the function name in the OpenAPI spec
+ # TODO: Do we need to use create_openapi_http_exception_doc here?
+ responses={
+ status.HTTP_400_BAD_REQUEST: {
+ "description": "Task Instance doesn't pass the required runtime checks"
+ },
+ status.HTTP_204_NO_CONTENT: {
+ "description": "Task Instance is not in a running state, cannot perform runtime checks."
+ },
+ status.HTTP_422_UNPROCESSABLE_ENTITY: {
+ "description": "Invalid payload for requested runtime checks on the Task Instance."
+ },
+ },
+)
+def ti_runtime_checks(
+ task_instance_id: UUID,
+ payload: TIRuntimeCheckPayload,
+ session: SessionDep,
+):
+ ti_id_str = str(task_instance_id)
+ task_instance = session.scalar(select(TI).where(TI.id == ti_id_str))
+ if task_instance.state != State.RUNNING:
+ return Response(status_code=status.HTTP_204_NO_CONTENT)
+ else:
Review Comment:
Fixed in 3781f5c3adbe64eb4227315f8383d4b487f2af2a
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh closed pull request #46020: AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK
URL: https://github.com/apache/airflow/pull/46020
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931971636
##########
task_sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -501,26 +503,39 @@ def run(ti: RuntimeTaskInstance, log: Logger):
# TODO: Get a real context object
ti.hostname = get_hostname()
ti.task = ti.task.prepare_for_execution()
- context = ti.get_template_context()
- with set_current_context(context):
- jinja_env = ti.task.dag.get_template_env()
- ti.task = ti.render_templates(context=context, jinja_env=jinja_env)
- result = _execute_task(context, ti.task)
-
- _push_xcom_if_needed(result, ti)
-
- task_outlets, outlet_events = _process_outlets(context, ti.task.outlets)
-
- # TODO: Get things from _execute_task_with_callbacks
- # - Clearing XCom
- # - Update RTIF
- # - Pre Execute
- # etc
- msg = SucceedTask(
- end_date=datetime.now(tz=timezone.utc),
- task_outlets=task_outlets,
- outlet_events=outlet_events,
- )
+ if ti.task.inlets or ti.task.outlets:
+ inlets = [asset.asprofile() for asset in ti.task.inlets if isinstance(asset, Asset)]
+ outlets = [asset.asprofile() for asset in ti.task.outlets if isinstance(asset, Asset)]
+ SUPERVISOR_COMMS.send_request(msg=RuntimeCheckOnTask(inlets=inlets, outlets=outlets), log=log) # type: ignore
+ msg = SUPERVISOR_COMMS.get_message() # type: ignore
+
+ if isinstance(msg, OKResponse) and not msg.ok:
+ log.info("Runtime checks failed for task, marking task as failed..")
+ msg = TaskState(
+ state=TerminalTIState.FAILED,
+ end_date=datetime.now(tz=timezone.utc),
+ )
+ else:
+ context = ti.get_template_context()
+ with set_current_context(context):
+ jinja_env = ti.task.dag.get_template_env()
+ ti.task = ti.render_templates(context=context, jinja_env=jinja_env)
+ result = _execute_task(context, ti.task)
+
+ _push_xcom_if_needed(result, ti)
+
+ task_outlets, outlet_events = _process_outlets(context, ti.task.outlets)
+
+ # TODO: Get things from _execute_task_with_callbacks
+ # - Clearing XCom
+ # - Update RTIF
+ # - Pre Execute
+ # etc
Review Comment:
This comment is out of place, it should be on L523 I think.
Also I thought you'd already done RTIF?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931994485
##########
task_sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -501,26 +503,39 @@ def run(ti: RuntimeTaskInstance, log: Logger):
# TODO: Get a real context object
ti.hostname = get_hostname()
ti.task = ti.task.prepare_for_execution()
- context = ti.get_template_context()
- with set_current_context(context):
- jinja_env = ti.task.dag.get_template_env()
- ti.task = ti.render_templates(context=context, jinja_env=jinja_env)
- result = _execute_task(context, ti.task)
-
- _push_xcom_if_needed(result, ti)
-
- task_outlets, outlet_events = _process_outlets(context, ti.task.outlets)
-
- # TODO: Get things from _execute_task_with_callbacks
- # - Clearing XCom
- # - Update RTIF
- # - Pre Execute
- # etc
- msg = SucceedTask(
- end_date=datetime.now(tz=timezone.utc),
- task_outlets=task_outlets,
- outlet_events=outlet_events,
- )
+ if ti.task.inlets or ti.task.outlets:
+ inlets = [asset.asprofile() for asset in ti.task.inlets if isinstance(asset, Asset)]
+ outlets = [asset.asprofile() for asset in ti.task.outlets if isinstance(asset, Asset)]
+ SUPERVISOR_COMMS.send_request(msg=RuntimeCheckOnTask(inlets=inlets, outlets=outlets), log=log) # type: ignore
+ msg = SUPERVISOR_COMMS.get_message() # type: ignore
+
+ if isinstance(msg, OKResponse) and not msg.ok:
+ log.info("Runtime checks failed for task, marking task as failed..")
+ msg = TaskState(
+ state=TerminalTIState.FAILED,
+ end_date=datetime.now(tz=timezone.utc),
+ )
+ else:
+ context = ti.get_template_context()
+ with set_current_context(context):
+ jinja_env = ti.task.dag.get_template_env()
+ ti.task = ti.render_templates(context=context, jinja_env=jinja_env)
+ result = _execute_task(context, ti.task)
+
+ _push_xcom_if_needed(result, ti)
+
+ task_outlets, outlet_events = _process_outlets(context, ti.task.outlets)
+
+ # TODO: Get things from _execute_task_with_callbacks
+ # - Clearing XCom
+ # - Update RTIF
+ # - Pre Execute
+ # etc
Review Comment:
Yeah, copy paste error. Clearing xcom is also done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931999849
##########
task_sdk/src/airflow/sdk/definitions/asset/__init__.py:
##########
@@ -428,6 +429,10 @@ def iter_dag_dependencies(self, *, source: str, target: str) -> Iterator[DagDepe
dependency_id=self.name,
)
+ def asprofile(self) -> AssetProfile:
+ """Profiles Asset to AssetProfile."""
Review Comment:
Ah yes. Made the change!
##########
tests/api_fastapi/execution_api/routes/test_task_instances.py:
##########
@@ -655,6 +655,40 @@ def test_ti_update_state_to_failed_without_retry_table_check(self, client, sessi
assert ti.next_kwargs is None
assert ti.duration == 3600.00
+ @pytest.mark.parametrize(
+ ("state", "expected_status_code"),
+ [
+ (State.RUNNING, 204),
+ (State.SUCCESS, 409),
+ (State.QUEUED, 409),
+ (State.FAILED, 409),
Review Comment:
Yeah, can do.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931586895
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -442,6 +444,48 @@ def get_previous_successful_dagrun(
return PrevSuccessfulDagRunResponse.model_validate(dag_run)
+@router.post(
+ "/{task_instance_id}/runtime-checks",
+ status_code=status.HTTP_200_OK,
+ # TODO: Add description to the operation
+ # TODO: Add Operation ID to control the function name in the OpenAPI spec
+ # TODO: Do we need to use create_openapi_http_exception_doc here?
+ responses={
+ status.HTTP_400_BAD_REQUEST: {
+ "description": "Task Instance doesn't pass the required runtime checks"
+ },
+ status.HTTP_204_NO_CONTENT: {
+ "description": "Task Instance is not in a running state, cannot perform runtime checks."
+ },
+ status.HTTP_422_UNPROCESSABLE_ENTITY: {
+ "description": "Invalid payload for requested runtime checks on the Task Instance."
+ },
+ },
+)
+def ti_runtime_checks(
+ task_instance_id: UUID,
+ payload: TIRuntimeCheckPayload,
+ session: SessionDep,
+):
+ ti_id_str = str(task_instance_id)
+ task_instance = session.scalar(select(TI).where(TI.id == ti_id_str))
+ if task_instance.state != State.RUNNING:
+ return Response(status_code=status.HTTP_204_NO_CONTENT)
Review Comment:
> I don't think it matters/is avoidable, but previously the asset checks were done before the task was put in to the running state right?
Yeah that is right, but with the current design we have that won't be possible as we won't be able to handle this portion in `/run` endpoint for now. Its mentioned in the PR desc
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931695847
##########
airflow/api_fastapi/execution_api/datamodels/taskinstance.py:
##########
@@ -249,3 +249,10 @@ class PrevSuccessfulDagRunResponse(BaseModel):
data_interval_end: UtcDateTime | None = None
start_date: UtcDateTime | None = None
end_date: UtcDateTime | None = None
+
+
+class TIRuntimeCheckPayload(BaseModel):
+ """Payload for performing Runtime checks on the TaskInstance model as requested by the SDK."""
+
+ inlet: list[AssetProfile] | None = None
+ outlet: list[AssetProfile] | None = None
Review Comment:
Handled
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #46020:
URL: https://github.com/apache/airflow/pull/46020#issuecomment-2618372894
Yeah, with the latest changes, the DAG passes:

And the error handling is better:

CC: @ashb
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931998857
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -442,6 +444,46 @@ def get_previous_successful_dagrun(
return PrevSuccessfulDagRunResponse.model_validate(dag_run)
+@router.post(
+ "/{task_instance_id}/runtime-checks",
+ status_code=status.HTTP_204_NO_CONTENT,
+ # TODO: Add description to the operation
+ # TODO: Add Operation ID to control the function name in the OpenAPI spec
+ # TODO: Do we need to use create_openapi_http_exception_doc here?
+ responses={
+ status.HTTP_400_BAD_REQUEST: {"description": "Task Instance failed the runtime checks."},
+ status.HTTP_409_CONFLICT: {
+ "description": "Task Instance isn't in a running state. Cannot perform runtime checks."
+ },
+ status.HTTP_422_UNPROCESSABLE_ENTITY: {
+ "description": "Invalid payload for requested runtime checks on the Task Instance."
+ },
+ },
+)
+def ti_runtime_checks(
+ task_instance_id: UUID,
+ payload: TIRuntimeCheckPayload,
+ session: SessionDep,
+):
+ ti_id_str = str(task_instance_id)
+ task_instance = session.scalar(select(TI).where(TI.id == ti_id_str))
+ if task_instance.state != State.RUNNING:
+ raise HTTPException(status_code=status.HTTP_409_CONFLICT)
+
+ try:
+ TI.validate_inlet_outlet_assets_activeness(payload.inlets, payload.outlets, session) # type: ignore
Review Comment:
Its for `AssetProfile` which can be from datamodels or from _generated
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1932001302
##########
tests/api_fastapi/execution_api/routes/test_task_instances.py:
##########
@@ -655,6 +655,40 @@ def test_ti_update_state_to_failed_without_retry_table_check(self, client, sessi
assert ti.next_kwargs is None
assert ti.duration == 3600.00
+ @pytest.mark.parametrize(
+ ("state", "expected_status_code"),
+ [
+ (State.RUNNING, 204),
+ (State.SUCCESS, 409),
+ (State.QUEUED, 409),
+ (State.FAILED, 409),
Review Comment:
Oh I was meant to do it, hence the name of the test is `test_ti_runtime_checks_success`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #46020:
URL: https://github.com/apache/airflow/pull/46020#issuecomment-2613055460
Need to work on few things:
1. Fix the task runner tests
2. Add tests for supervisor
3. Revisit the `# type: ignore` checks -> added some cos it felt easier.
4. Add PR description with plenty of details.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1935076241
##########
task_sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -501,6 +503,22 @@ def run(ti: RuntimeTaskInstance, log: Logger):
# TODO: Get a real context object
ti.hostname = get_hostname()
ti.task = ti.task.prepare_for_execution()
+ if ti.task.inlets or ti.task.outlets:
+ inlets = [
+ AssetProfile(name=x.name or None, uri=x.uri or None, asset_type=Asset.__name__)
+ for x in ti.task.inlets
+ if isinstance(x, Asset)
+ ]
+ outlets = [
+ AssetProfile(name=x.name or None, uri=x.uri or None, asset_type=Asset.__name__)
+ for x in ti.task.outlets
+ if isinstance(x, Asset)
+ ]
+ SUPERVISOR_COMMS.send_request(msg=RuntimeCheckOnTask(inlet=inlets, outlet=outlets), log=log) # type: ignore
+ msg = SUPERVISOR_COMMS.get_message() # type: ignore
+ if isinstance(msg, OKResponse) and not msg.ok:
+ log.info("Runtime checks failed for task, marking task as failed..")
+ return
Review Comment:
Resolving with above explanation, let me know if its not clear, can reopen.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931588016
##########
task_sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -767,6 +768,14 @@ def _handle_request(self, msg: ToSupervisor, log: FilteringBoundLogger):
if isinstance(msg, TaskState):
self._terminal_state = msg.state
self._task_end_time_monotonic = time.monotonic()
+ elif isinstance(msg, RuntimeCheckOnTask):
+ runtime_check_resp = self.client.task_instances.runtime_checks(id=self.id, msg=msg)
+ resp = runtime_check_resp.model_dump_json().encode()
+ if not runtime_check_resp.ok:
+ log.debug("Runtime checks failed on task %s, marking task as failed..", self.id)
+ self.client.task_instances.finish(
+ id=self.id, state=TerminalTIState.FAILED, when=datetime.now(tz=timezone.utc)
+ )
Review Comment:
Excellent point, we should send a message to the task runner to handle this portion, you are right.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931770624
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -442,6 +444,48 @@ def get_previous_successful_dagrun(
return PrevSuccessfulDagRunResponse.model_validate(dag_run)
+@router.post(
+ "/{task_instance_id}/runtime-checks",
+ status_code=status.HTTP_200_OK,
+ # TODO: Add description to the operation
+ # TODO: Add Operation ID to control the function name in the OpenAPI spec
+ # TODO: Do we need to use create_openapi_http_exception_doc here?
+ responses={
+ status.HTTP_400_BAD_REQUEST: {
+ "description": "Task Instance doesn't pass the required runtime checks"
+ },
+ status.HTTP_204_NO_CONTENT: {
+ "description": "Task Instance is not in a running state, cannot perform runtime checks."
Review Comment:
Not relevant anymore, handled in last batch of commits better
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #46020:
URL: https://github.com/apache/airflow/pull/46020#issuecomment-2618383757
Well OK, turns out the test has to be updated now!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1935076008
##########
task_sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -501,6 +503,22 @@ def run(ti: RuntimeTaskInstance, log: Logger):
# TODO: Get a real context object
ti.hostname = get_hostname()
ti.task = ti.task.prepare_for_execution()
+ if ti.task.inlets or ti.task.outlets:
+ inlets = [
+ AssetProfile(name=x.name or None, uri=x.uri or None, asset_type=Asset.__name__)
+ for x in ti.task.inlets
+ if isinstance(x, Asset)
Review Comment:
This is done!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931640484
##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -442,6 +444,48 @@ def get_previous_successful_dagrun(
return PrevSuccessfulDagRunResponse.model_validate(dag_run)
+@router.post(
+ "/{task_instance_id}/runtime-checks",
+ status_code=status.HTTP_200_OK,
+ # TODO: Add description to the operation
+ # TODO: Add Operation ID to control the function name in the OpenAPI spec
+ # TODO: Do we need to use create_openapi_http_exception_doc here?
+ responses={
+ status.HTTP_400_BAD_REQUEST: {
+ "description": "Task Instance doesn't pass the required runtime checks"
+ },
+ status.HTTP_204_NO_CONTENT: {
+ "description": "Task Instance is not in a running state, cannot perform runtime checks."
+ },
+ status.HTTP_422_UNPROCESSABLE_ENTITY: {
+ "description": "Invalid payload for requested runtime checks on the Task Instance."
+ },
+ },
+)
+def ti_runtime_checks(
+ task_instance_id: UUID,
+ payload: TIRuntimeCheckPayload,
+ session: SessionDep,
+):
+ ti_id_str = str(task_instance_id)
+ task_instance = session.scalar(select(TI).where(TI.id == ti_id_str))
+ if task_instance.state != State.RUNNING:
+ return Response(status_code=status.HTTP_204_NO_CONTENT)
Review Comment:
> Returning a 204 if the task isn't in the right state doesn't feel right. This feels more like it should be a HTTP 409 or a 400, and 204 No Content should be for the success path
Yeah, that sounds better once you said it.
204: If the check passes
409: when the TI isn't in the right state
400: when the check fails
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931691664
##########
task_sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -501,6 +503,22 @@ def run(ti: RuntimeTaskInstance, log: Logger):
# TODO: Get a real context object
ti.hostname = get_hostname()
ti.task = ti.task.prepare_for_execution()
+ if ti.task.inlets or ti.task.outlets:
Review Comment:
Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931770042
##########
task_sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -501,6 +503,22 @@ def run(ti: RuntimeTaskInstance, log: Logger):
# TODO: Get a real context object
ti.hostname = get_hostname()
ti.task = ti.task.prepare_for_execution()
+ if ti.task.inlets or ti.task.outlets:
+ inlets = [
+ AssetProfile(name=x.name or None, uri=x.uri or None, asset_type=Asset.__name__)
+ for x in ti.task.inlets
+ if isinstance(x, Asset)
Review Comment:
Yeah, seems its worth it.
Added in the last batch of commits
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh closed pull request #46020: AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK
URL: https://github.com/apache/airflow/pull/46020
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931974383
##########
task_sdk/src/airflow/sdk/definitions/asset/__init__.py:
##########
@@ -428,6 +429,10 @@ def iter_dag_dependencies(self, *, source: str, target: str) -> Iterator[DagDepe
dependency_id=self.name,
)
+ def asprofile(self) -> AssetProfile:
+ """Profiles Asset to AssetProfile."""
Review Comment:
```suggestion
"""
Profiles Asset to AssetProfile.
:meta private:
"""
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AIP-72: Port _validate_inlet_outlet_assets_activeness into Task SDK [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931996169
##########
task_sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -501,26 +503,39 @@ def run(ti: RuntimeTaskInstance, log: Logger):
# TODO: Get a real context object
ti.hostname = get_hostname()
ti.task = ti.task.prepare_for_execution()
- context = ti.get_template_context()
- with set_current_context(context):
- jinja_env = ti.task.dag.get_template_env()
- ti.task = ti.render_templates(context=context, jinja_env=jinja_env)
- result = _execute_task(context, ti.task)
-
- _push_xcom_if_needed(result, ti)
-
- task_outlets, outlet_events = _process_outlets(context, ti.task.outlets)
-
- # TODO: Get things from _execute_task_with_callbacks
- # - Clearing XCom
- # - Update RTIF
- # - Pre Execute
- # etc
- msg = SucceedTask(
- end_date=datetime.now(tz=timezone.utc),
- task_outlets=task_outlets,
- outlet_events=outlet_events,
- )
+ if ti.task.inlets or ti.task.outlets:
+ inlets = [asset.asprofile() for asset in ti.task.inlets if isinstance(asset, Asset)]
+ outlets = [asset.asprofile() for asset in ti.task.outlets if isinstance(asset, Asset)]
+ SUPERVISOR_COMMS.send_request(msg=RuntimeCheckOnTask(inlets=inlets, outlets=outlets), log=log) # type: ignore
+ msg = SUPERVISOR_COMMS.get_message() # type: ignore
+
+ if isinstance(msg, OKResponse) and not msg.ok:
+ log.info("Runtime checks failed for task, marking task as failed..")
+ msg = TaskState(
+ state=TerminalTIState.FAILED,
+ end_date=datetime.now(tz=timezone.utc),
+ )
+ else:
+ context = ti.get_template_context()
+ with set_current_context(context):
+ jinja_env = ti.task.dag.get_template_env()
+ ti.task = ti.render_templates(context=context, jinja_env=jinja_env)
+ result = _execute_task(context, ti.task)
+
+ _push_xcom_if_needed(result, ti)
+
+ task_outlets, outlet_events = _process_outlets(context, ti.task.outlets)
+
+ # TODO: Get things from _execute_task_with_callbacks
+ # - Clearing XCom
+ # - Update RTIF
+ # - Pre Execute
+ # etc
Review Comment:
Moved it above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org