pierrejeambrun commented on code in PR #49475:
URL: https://github.com/apache/airflow/pull/49475#discussion_r2053663537


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/log.py:
##########
@@ -151,3 +151,38 @@ def get_log(
             "Airflow-Continuation-Token": 
URLSafeSerializer(request.app.state.secret_key).dumps(metadata)
         }
     return Response(media_type="application/x-ndjson", content=logs, 
headers=headers)
+
+
+@task_instances_log_router.get(
+    "/{task_id}/externalLogUrl/{try_number}",
+    responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
+    dependencies=[Depends(requires_access_dag("GET", 
DagAccessEntity.TASK_INSTANCE))],

Review Comment:
   Should this be `DagAccessEntity.TASK_INSTANCE` or 
`DagAccessEntity.TASK_LOGS` ?



##########
airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/Logs.tsx:
##########
@@ -94,6 +99,13 @@ export const Logs = () => {
         tryNumber={tryNumber}
         wrap={wrap}
       />
+      {Boolean(showExternalLogRedirect) && Boolean(externalLogName) ? (
+        <ExternalLogLink
+          externalLogName={externalLogName}
+          taskInstance={taskInstance as TaskInstanceResponse}
+          tryNumber={tryNumber as number}

Review Comment:
   We souldn't have to do this. `taskInstance` is already a correct compatible 
type.
   
   `tryNumber` we need to handle other undefined/null cases explicitely.



##########
airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/ExternalLogLink.tsx:
##########
@@ -0,0 +1,64 @@
+/*!
+ * 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.
+ */
+import { Button } from "@chakra-ui/react";
+import { useParams } from "react-router-dom";
+
+import { useTaskInstanceServiceGetExternalLogUrl } from "openapi/queries";
+import type { TaskInstanceResponse } from "openapi/requests/types.gen";
+
+type Props = {
+  readonly externalLogName: string;
+  readonly taskInstance: TaskInstanceResponse;
+  readonly tryNumber: number;
+};
+
+export const ExternalLogLink = ({ externalLogName, taskInstance, tryNumber }: 
Props) => {
+  const { dagId = "", mapIndex = "-1", runId = "", taskId = "" } = useParams();
+
+  const {
+    data: externalLogData,
+    error,
+    isLoading,
+  } = useTaskInstanceServiceGetExternalLogUrl(
+    {
+      dagId,
+      dagRunId: runId,
+      mapIndex: parseInt(mapIndex, 10),
+      taskId,
+      tryNumber,
+    },
+    undefined,
+    {
+      enabled: Boolean(taskInstance) && Boolean(tryNumber),
+      retry: false,
+    },
+  );
+
+  if (Boolean(error) || isLoading || externalLogData?.url === undefined) {
+    return undefined;
+  }
+
+  return (
+    <Button asChild colorScheme="blue" variant="outline">
+      <a href={externalLogData.url} rel="noreferrer" target="_blank">

Review Comment:
   I see we are missing one on `ExtraLinks.tsx` I don't know if there is a 
particular reason, I think we should update it there too if you thinks work 
with it.



##########
airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/ExternalLogLink.tsx:
##########
@@ -0,0 +1,64 @@
+/*!
+ * 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.
+ */
+import { Button } from "@chakra-ui/react";
+import { useParams } from "react-router-dom";
+
+import { useTaskInstanceServiceGetExternalLogUrl } from "openapi/queries";
+import type { TaskInstanceResponse } from "openapi/requests/types.gen";
+
+type Props = {
+  readonly externalLogName: string;
+  readonly taskInstance: TaskInstanceResponse;
+  readonly tryNumber: number;
+};
+
+export const ExternalLogLink = ({ externalLogName, taskInstance, tryNumber }: 
Props) => {
+  const { dagId = "", mapIndex = "-1", runId = "", taskId = "" } = useParams();
+
+  const {
+    data: externalLogData,
+    error,
+    isLoading,
+  } = useTaskInstanceServiceGetExternalLogUrl(
+    {
+      dagId,
+      dagRunId: runId,
+      mapIndex: parseInt(mapIndex, 10),
+      taskId,
+      tryNumber,
+    },
+    undefined,
+    {
+      enabled: Boolean(taskInstance) && Boolean(tryNumber),
+      retry: false,
+    },
+  );
+
+  if (Boolean(error) || isLoading || externalLogData?.url === undefined) {
+    return undefined;
+  }
+
+  return (
+    <Button asChild colorScheme="blue" variant="outline">
+      <a href={externalLogData.url} rel="noreferrer" target="_blank">

Review Comment:
   ```suggestion
         <a href={externalLogData.url} rel="noopener noreferrer" 
target="_blank">
   ```



##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/log.py:
##########
@@ -151,3 +151,38 @@ def get_log(
             "Airflow-Continuation-Token": 
URLSafeSerializer(request.app.state.secret_key).dumps(metadata)
         }
     return Response(media_type="application/x-ndjson", content=logs, 
headers=headers)
+
+
+@task_instances_log_router.get(
+    "/{task_id}/externalLogUrl/{try_number}",
+    responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),

Review Comment:
   we are missing the `400` response documentation



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to