You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "jason810496 (via GitHub)" <gi...@apache.org> on 2025/01/04 09:50:56 UTC

[PR] AIP-81 Add DAG Report API [airflow]

jason810496 opened a new pull request, #45393:
URL: https://github.com/apache/airflow/pull/45393

   
   closes: #45301
   
   
   
   <!-- 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-81 Add DAG Report API [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on PR #45393:
URL: https://github.com/apache/airflow/pull/45393#issuecomment-2605132473

   > Code QL seems happy 🎉
   
   Finally passed all CI! Thanks, @pierrejeambrun, for the 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-81 Add DAG Report API [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1922602444


##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,54 @@
+# 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.
+
+from __future__ import annotations
+
+from typing import cast
+
+from fastapi import HTTPException, status
+
+from airflow import settings
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
+from airflow.models.dagbag import DagBag
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReports")
+
+
+@dag_report_router.get(
+    "",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_400_BAD_REQUEST,
+        ]
+    ),
+)
+def get_dag_report(
+    subdir: str,
+):
+    """Get DAG report."""
+    if not subdir.startswith(settings.DAGS_FOLDER):
+        raise HTTPException(status.HTTP_400_BAD_REQUEST, "subdir should be subpath of DAGS_FOLDER settings")
+    dagbag = DagBag(subdir)

Review Comment:
   Code QL is not happy because it considers that we are manipulating a user defined path.
   
   We need to normalize it, maybe something like this:
   ```python
       fullpath = os.path.normpath(subdir)
       if not fullpath.startswith(....):
           raise ...
   ```
   
   Otherwise specifying something like `settings.DAGS_FOLDER/../../../etc.` could still end up outside the dagfolder I believe.



-- 
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-81 Add DAG Report API [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1923938021


##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,56 @@
+# 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.
+
+from __future__ import annotations
+
+import os
+from typing import cast
+
+from fastapi import HTTPException, status
+
+from airflow import settings
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
+from airflow.models.dagbag import DagBag
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReports")
+
+
+@dag_report_router.get(
+    "",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_400_BAD_REQUEST,
+        ]
+    ),
+)
+def get_dag_report(
+    subdir: str,
+):
+    """Get DAG report."""
+    fullpath = os.path.normpath(subdir)
+    if not fullpath.startswith(settings.DAGS_FOLDER):
+        raise HTTPException(status.HTTP_400_BAD_REQUEST, "subdir should be subpath of DAGS_FOLDER settings")
+    dagbag = DagBag(subdir)

Review Comment:
   You should be using the `fullpath` param from now on.
   
   I think that's why the CI is still not happy.



-- 
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-81 Add DAG Report API [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1905499165


##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,49 @@
+# 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.
+
+from __future__ import annotations
+
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.models.dagbag import DagBag
+from airflow.utils.cli import process_subdir
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReport")
+
+
+@dag_report_router.get(
+    "",
+)
+def get_dag_report(
+    subdir: str,

Review Comment:
   Do we need the `subdir` granularity ?
   
   Otherwise in the fastapi application we already have access to the DagBag that is built based on  `DAGS_FOLDER` coming from the configuration file. (`request.app.state.dag_bag`) Also that feels sensitive, because we will be manipulating a user provided path on the server... (for instance provide a path to a really big folder, or something with a lot of zipped archives, such as logs, and the server will spend a lot of time doing unnecessary work => DOS) 



##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,49 @@
+# 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.
+
+from __future__ import annotations
+
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.models.dagbag import DagBag
+from airflow.utils.cli import process_subdir
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReport")

Review Comment:
   ```suggestion
   dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReports")
   ```



##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,49 @@
+# 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.
+
+from __future__ import annotations
+
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.models.dagbag import DagBag
+from airflow.utils.cli import process_subdir
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReport")
+
+
+@dag_report_router.get(
+    "",
+)
+def get_dag_report(
+    subdir: str,
+):
+    """Get DAG report."""
+    # though the `subdir` will be validated on CLI side, we still need to validate again here or the CodeQL will report a security issue
+    dagbag = DagBag(process_subdir(subdir))

Review Comment:
   I think we can remove the comment. From the API point of view this is just another public endpoint. And some roles / permissions will be applied, but we do not code this assuming that only a specific role will have access. (Also at the moment everybody has access), so validating again on the API side is always required.



##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,49 @@
+# 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.
+
+from __future__ import annotations
+
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.models.dagbag import DagBag
+from airflow.utils.cli import process_subdir
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReport")
+
+
+@dag_report_router.get(
+    "",
+)
+def get_dag_report(
+    subdir: str,

Review Comment:
   Or at least we need to check that the provided path is a subpath of `DAGS_FOLDER`



-- 
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-81 Add DAG Report API [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1907395002


##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,49 @@
+# 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.
+
+from __future__ import annotations
+
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.models.dagbag import DagBag
+from airflow.utils.cli import process_subdir
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReport")
+
+
+@dag_report_router.get(
+    "",
+)
+def get_dag_report(
+    subdir: str,

Review Comment:
   If we need dags from the filesystem to get that extra information then I don't mind re-creating it. Mayba a small comment there could help.
   
   Also you need the `subdir` param so you cannot really re-use the existing dag bag.
   
   > Or at least we need to check that the provided path is a subpath of DAGS_FOLDER
   
   This should be enough in that case.



-- 
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-81 Add DAG Report API [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1923951444


##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,56 @@
+# 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.
+
+from __future__ import annotations
+
+import os
+from typing import cast
+
+from fastapi import HTTPException, status
+
+from airflow import settings
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
+from airflow.models.dagbag import DagBag
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReports")
+
+
+@dag_report_router.get(
+    "",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_400_BAD_REQUEST,
+        ]
+    ),
+)
+def get_dag_report(
+    subdir: str,
+):
+    """Get DAG report."""
+    fullpath = os.path.normpath(subdir)
+    if not fullpath.startswith(settings.DAGS_FOLDER):
+        raise HTTPException(status.HTTP_400_BAD_REQUEST, "subdir should be subpath of DAGS_FOLDER settings")
+    dagbag = DagBag(subdir)

Review Comment:
   Thanks, @pierrejeambrun! I overlooked this typo and couldn't figure out why the CI was still failing this morning!  



-- 
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-81 Add DAG Report API [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1907232563


##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,49 @@
+# 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.
+
+from __future__ import annotations
+
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.models.dagbag import DagBag
+from airflow.utils.cli import process_subdir
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReport")
+
+
+@dag_report_router.get(
+    "",
+)
+def get_dag_report(
+    subdir: str,

Review Comment:
   Hi @pierrejeambrun ,
   I agree with reusing `request.app.state.dag_bag` instead of creating a new `DagBag` instance at the router each time. I just tried retrieving `dagbag_stats` from `request.app.state.dag_bag` and found that the `DagBag` for the REST API is constructed with `read_dags_from_db=True`.
   https://github.com/apache/airflow/blob/main/airflow/www/extensions/init_dagbag.py#L29
    This means the only way to get a list of DAGs is by calling `collect_dags_from_db`.
    https://github.com/apache/airflow/blob/main/airflow/models/dagbag.py#L596-L605
    
    Additionally, for the `dagbag_stats` information required by this API — such as `file_parse_duration`, `dag_num`, `task_num`, and `warning_num`— these details aren't available in `SerializedDagModel`.  
   
   It seems this would require more effort to sync these additional `dagbag_stats` details from the filesystem to the database. This would involve adding more fields to `SerializedDagModel` and implementing the corresponding sync logic in `DagBag`. 
   
   Is there an alternative solution to retrieve these `dagbag_stats` from the database instead of the filesystem ? Or would implementing this logic for the feature be considered acceptable ?  
   



-- 
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-81 Add DAG Report API [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on PR #45393:
URL: https://github.com/apache/airflow/pull/45393#issuecomment-2582772022

   All comments have been resolved. Thanks, @pierrejeambrun, for the code 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-81 Add DAG Report API [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on PR #45393:
URL: https://github.com/apache/airflow/pull/45393#issuecomment-2594062457

   Rebase to latest main.


-- 
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-81 Add DAG Report API [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1907395002


##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,49 @@
+# 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.
+
+from __future__ import annotations
+
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.models.dagbag import DagBag
+from airflow.utils.cli import process_subdir
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReport")
+
+
+@dag_report_router.get(
+    "",
+)
+def get_dag_report(
+    subdir: str,

Review Comment:
   If we need dags from the filesystem to get that extra information then I don't mind re-creating it. Mayba a small comment there could help. I don't know a better way of achieving that. 
   
   Also you need the `subdir` param so you cannot really re-use the existing dag bag.
   
   > Or at least we need to check that the provided path is a subpath of DAGS_FOLDER
   
   This should be enough in that case.



-- 
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-81 Add DAG Report API [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1905517751


##########
tests/api_fastapi/core_api/routes/public/test_dag_report.py:
##########
@@ -0,0 +1,83 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+import pytest
+import re2 as re
+
+from tests_common.test_utils.config import conf_vars
+from tests_common.test_utils.db import clear_db_dags
+
+pytestmark = pytest.mark.db_test
+
+
+class TestDagReportEndpoint:
+    @pytest.fixture(autouse=True)
+    def setup(self) -> None:
+        self.clear_db()
+
+    def teardown_method(self) -> None:
+        self.clear_db()
+
+    def clear_db(self):
+        clear_db_dags()
+
+    @pytest.mark.parametrize(
+        "subdir,include_example,expected_total_entries",
+        [
+            pytest.param("/root/airflow/dags", True, 58, id="dag_path_with_example"),
+            pytest.param("/root/airflow/dags", False, 0, id="dag_path_without_example"),
+        ],
+    )
+    def test_should_response_200(self, test_client, subdir, include_example, expected_total_entries):
+        with conf_vars({("core", "load_examples"): str(include_example)}):
+            params = {"subdir": subdir} if subdir else {}

Review Comment:
   `subdir` is always defined.
   ```suggestion
               params = {"subdir": subdir}
   ```



##########
tests/api_fastapi/core_api/routes/public/test_dag_report.py:
##########
@@ -0,0 +1,83 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+import pytest
+import re2 as re
+
+from tests_common.test_utils.config import conf_vars
+from tests_common.test_utils.db import clear_db_dags
+
+pytestmark = pytest.mark.db_test
+
+
+class TestDagReportEndpoint:
+    @pytest.fixture(autouse=True)
+    def setup(self) -> None:
+        self.clear_db()
+
+    def teardown_method(self) -> None:
+        self.clear_db()
+
+    def clear_db(self):
+        clear_db_dags()
+
+    @pytest.mark.parametrize(
+        "subdir,include_example,expected_total_entries",
+        [
+            pytest.param("/root/airflow/dags", True, 58, id="dag_path_with_example"),
+            pytest.param("/root/airflow/dags", False, 0, id="dag_path_without_example"),
+        ],
+    )
+    def test_should_response_200(self, test_client, subdir, include_example, expected_total_entries):
+        with conf_vars({("core", "load_examples"): str(include_example)}):
+            params = {"subdir": subdir} if subdir else {}
+            response = test_client.get("/public/dagReport", params=params)
+            assert response.status_code == 200
+            response_json = response.json()
+            expected_keys = {"dag_num", "dags", "file", "task_num", "warning_num"}
+            assert response_json["total_entries"] == expected_total_entries
+            for dag_report in response_json["dag_reports"]:
+                assert all(key in dag_report for key in expected_keys)
+                # assert duration is in ISO8601 format ( PTnS or PTn.nS )
+                assert re.match(r"^PT\d+(\.\d+)?S$", dag_report["duration"])

Review Comment:
   These chekcs can be omitted. This is enforced by fastapi + pydantic native validation.



-- 
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-81 Add DAG Report API [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1907395002


##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,49 @@
+# 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.
+
+from __future__ import annotations
+
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.models.dagbag import DagBag
+from airflow.utils.cli import process_subdir
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReport")
+
+
+@dag_report_router.get(
+    "",
+)
+def get_dag_report(
+    subdir: str,

Review Comment:
   If we need dags from the filesystem to get that extra information then I don't mind re-creating it. Mayba a small comment there could help. I don't know a better way of achieving that. 
   
   Also you need the `subdir` param so you cannot really re-use the existing dag bag.
   
   > Or at least we need to check that the provided path is a subpath of DAGS_FOLDER
   
   This should be enough in that case I think from a security point of view to not allow arbitrary file system exploration and processing.



-- 
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-81 Add DAG Report API [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1910536240


##########
tests/api_fastapi/core_api/routes/public/test_dag_report.py:
##########
@@ -0,0 +1,124 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+import pytest
+
+from airflow.utils.file import list_py_file_paths
+
+from tests_common.test_utils.config import conf_vars
+from tests_common.test_utils.db import clear_db_dags
+
+pytestmark = pytest.mark.db_test
+
+TEST_DAG_FOLDER = "/opt/airflow/tests/dags"
+TEST_DAG_FOLDER_WITH_SUBDIR = "/opt/airflow/tests/dags/subdir2"
+TEST_DAG_FOLDER_INVALID = "/invalid/path"
+TEST_DAG_FOLDER_INVALID_2 = "/root/airflow/tests/dags/"
+
+
+def get_corresponding_dag_file_count(dir: str, include_examples: bool = True) -> int:
+    return len(list_py_file_paths(directory=dir, include_examples=include_examples))
+
+
+class TestDagReportEndpoint:
+    @pytest.fixture(autouse=True)
+    def setup(self) -> None:
+        self.clear_db()
+
+    def teardown_method(self) -> None:
+        self.clear_db()
+
+    def clear_db(self):
+        clear_db_dags()
+
+    @pytest.mark.parametrize(
+        "subdir,include_example,expected_total_entries",
+        [
+            pytest.param(
+                TEST_DAG_FOLDER,
+                True,
+                get_corresponding_dag_file_count(TEST_DAG_FOLDER),
+                id="dag_path_with_example",
+            ),
+            pytest.param(
+                TEST_DAG_FOLDER,
+                False,
+                get_corresponding_dag_file_count(TEST_DAG_FOLDER, False),
+                id="dag_path_without_example",
+            ),
+            pytest.param(
+                TEST_DAG_FOLDER_WITH_SUBDIR,
+                True,
+                get_corresponding_dag_file_count(TEST_DAG_FOLDER_WITH_SUBDIR),
+                id="dag_path_subdir_with_example",
+            ),
+            pytest.param(
+                TEST_DAG_FOLDER_WITH_SUBDIR,
+                False,
+                get_corresponding_dag_file_count(TEST_DAG_FOLDER_WITH_SUBDIR, False),
+                id="dag_path_subdir_without_example",
+            ),
+        ],
+    )
+    def test_should_response_200(self, test_client, subdir, include_example, expected_total_entries):
+        with conf_vars({("core", "load_examples"): str(include_example)}):
+            response = test_client.get("/public/dagReport", params={"subdir": subdir})
+            assert response.status_code == 200
+            response_json = response.json()
+            expected_keys = {"dag_num", "dags", "duration", "file", "task_num", "warning_num"}
+            assert response_json["total_entries"] == expected_total_entries
+            for dag_report in response_json["dag_reports"]:
+                assert all(key in dag_report for key in expected_keys)

Review Comment:
   Keys check can be removed. Enforce by pydantic validation.



##########
tests/api_fastapi/core_api/routes/public/test_dag_report.py:
##########
@@ -0,0 +1,124 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+import pytest
+
+from airflow.utils.file import list_py_file_paths
+
+from tests_common.test_utils.config import conf_vars
+from tests_common.test_utils.db import clear_db_dags
+
+pytestmark = pytest.mark.db_test
+
+TEST_DAG_FOLDER = "/opt/airflow/tests/dags"

Review Comment:
   To not hardcode it manually in case it changes later.
   ```suggestion
   TEST_DAG_FOLDER = os.environ["AIRFLOW__CORE__DAGS_FOLDER"]
   ```
   



-- 
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-81 Add DAG Report API [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on PR #45393:
URL: https://github.com/apache/airflow/pull/45393#issuecomment-2601423048

   Hi @pierrejeambrun , I just fixed the broken test due to breaking change on `list_py_file__paths`.
   The CI failure is caused by `CodeQL`.


-- 
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-81 Add DAG Report API [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1907232563


##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,49 @@
+# 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.
+
+from __future__ import annotations
+
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.models.dagbag import DagBag
+from airflow.utils.cli import process_subdir
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReport")
+
+
+@dag_report_router.get(
+    "",
+)
+def get_dag_report(
+    subdir: str,

Review Comment:
   I agree with reusing `request.app.state.dag_bag` instead of creating a new `DagBag` instance at the router each time.  
   
   I just tried retrieving `dagbag_stats` from `request.app.state.dag_bag` and found that the `DagBag` for the REST API is constructed with `read_dags_from_db=True`.
   https://github.com/apache/airflow/blob/main/airflow/www/extensions/init_dagbag.py#L29
    This means the only way to get a list of DAGs is by calling `collect_dags_from_db`.
    https://github.com/apache/airflow/blob/main/airflow/models/dagbag.py#L596-L605
    
    Additionally, for the `dagbag_stats` information required by this API — such as `file_parse_duration`, `dag_num`, `task_num`, and `warning_num`— these details aren't available in `SerializedDagModel`.  
   
   It seems this would require more effort to sync these additional `dagbag_stats` details from the filesystem to the database. This would involve adding more fields to `SerializedDagModel` and implementing the corresponding sync logic in `DagBag`. 
   
   Is there an alternative solution to retrieve these `dagbag_stats` from the database instead of the filesystem ? Or would implementing this logic for the feature be considered acceptable ?  
   



-- 
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-81 Add DAG Report API [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1907395002


##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,49 @@
+# 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.
+
+from __future__ import annotations
+
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.models.dagbag import DagBag
+from airflow.utils.cli import process_subdir
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReport")
+
+
+@dag_report_router.get(
+    "",
+)
+def get_dag_report(
+    subdir: str,

Review Comment:
   If we need dags from the filesystem to get that extra information then I don't mind re-creating it. Mayba a small comment there could help. I don't know a better way of achieving that. 
   
   Also you need the `subdir` param so you cannot really re-use the existing dag bag.
   
   > Or at least we need to check that the provided path is a subpath of DAGS_FOLDER
   
   This should be enough in that case from a security point of view to not allow arbitrary file system exploration and processing.



-- 
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-81 Add DAG Report API [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #45393:
URL: https://github.com/apache/airflow/pull/45393#issuecomment-2605089886

   Code QL seems happy 🎉 


-- 
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-81 Add DAG Report API [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun merged PR #45393:
URL: https://github.com/apache/airflow/pull/45393


-- 
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-81 Add DAG Report API [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1922602444


##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,54 @@
+# 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.
+
+from __future__ import annotations
+
+from typing import cast
+
+from fastapi import HTTPException, status
+
+from airflow import settings
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
+from airflow.models.dagbag import DagBag
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReports")
+
+
+@dag_report_router.get(
+    "",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_400_BAD_REQUEST,
+        ]
+    ),
+)
+def get_dag_report(
+    subdir: str,
+):
+    """Get DAG report."""
+    if not subdir.startswith(settings.DAGS_FOLDER):
+        raise HTTPException(status.HTTP_400_BAD_REQUEST, "subdir should be subpath of DAGS_FOLDER settings")
+    dagbag = DagBag(subdir)

Review Comment:
   Code QL is not happy because it considers that we are manipulating a user defined path.
   
   I think we need to normalize it, maybe something like:
   ```python
       fullpath = os.path.normpath(subdir)
       if not fullpath.startswith(....):
           raise ...
   ```



-- 
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-81 Add DAG Report API [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #45393:
URL: https://github.com/apache/airflow/pull/45393#discussion_r1922648270


##########
airflow/api_fastapi/core_api/routes/public/dag_report.py:
##########
@@ -0,0 +1,54 @@
+# 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.
+
+from __future__ import annotations
+
+from typing import cast
+
+from fastapi import HTTPException, status
+
+from airflow import settings
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_report import (
+    DagReportCollectionResponse,
+    DagReportResponse,
+)
+from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
+from airflow.models.dagbag import DagBag
+
+dag_report_router = AirflowRouter(tags=["DagReport"], prefix="/dagReports")
+
+
+@dag_report_router.get(
+    "",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_400_BAD_REQUEST,
+        ]
+    ),
+)
+def get_dag_report(
+    subdir: str,
+):
+    """Get DAG report."""
+    if not subdir.startswith(settings.DAGS_FOLDER):
+        raise HTTPException(status.HTTP_400_BAD_REQUEST, "subdir should be subpath of DAGS_FOLDER settings")
+    dagbag = DagBag(subdir)

Review Comment:
   Thanks! Great solution — hope this passes CodeQL checks.  



-- 
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