bbovenzi commented on code in PR #35863: URL: https://github.com/apache/airflow/pull/35863#discussion_r1406334623
########## airflow/www/static/js/dag/details/taskDuration/index.tsx: ########## @@ -0,0 +1,143 @@ +/*! + * 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 React from "react"; +import { Box } from "@chakra-ui/react"; + +import useSelection from "src/dag/useSelection"; +import { useGridData } from "src/api"; +import { getDuration, formatDateTime } from "src/datetime_utils"; +import ReactECharts, { ReactEChartsProps } from "src/components/ReactECharts"; + +const TaskDuration = () => { + const { + selected: { taskId }, + onSelect, + } = useSelection(); + + const { + data: { groups }, + } = useGridData(); + var maxDuration = 0; + var unit = "seconds"; + var factor = 1; + + const taskInstances = groups.children.filter( + (instance) => instance.id === taskId + )[0].instances; + taskInstances.forEach((instance) => { + const runDuration = + instance?.startDate && instance?.endDate + ? getDuration(instance?.startDate, instance?.endDate) / 1000 + : 0; + const queuedDuration = + instance?.queuedDttm && instance?.startDate > instance.queuedDttm + ? getDuration(instance?.queuedDttm, instance?.startDate) / 1000 + : 0; + + if (runDuration > maxDuration) { + maxDuration = runDuration; + } + + instance.runDuration = runDuration; + instance.queuedDuration = queuedDuration; + }); + + if (maxDuration <= 60 * 2) { + factor = 1; + unit = "seconds"; + } else if (maxDuration <= 60 * 60 * 2) { + factor = 60; + unit = "minutes"; + } else if (maxDuration <= 24 * 60 * 60 * 2) { + factor = 60 * 60 * 24; + unit = "days"; + } + + taskInstances.forEach((instance) => { + instance.runDuration = instance.runDuration / factor; + instance.queuedDuration = instance.queuedDuration / factor; + }); + + function tooltipCallback(args) { + const { data } = args[0]; + const { runId } = data; + const { taskId } = data; Review Comment: ```suggestion const { runId, taskId } = data; ``` We can declare these in the same line ########## airflow/www/static/js/dag/details/taskDuration/index.tsx: ########## @@ -0,0 +1,143 @@ +/*! + * 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 React from "react"; +import { Box } from "@chakra-ui/react"; + +import useSelection from "src/dag/useSelection"; +import { useGridData } from "src/api"; +import { getDuration, formatDateTime } from "src/datetime_utils"; +import ReactECharts, { ReactEChartsProps } from "src/components/ReactECharts"; + +const TaskDuration = () => { + const { + selected: { taskId }, + onSelect, + } = useSelection(); + + const { + data: { groups }, + } = useGridData(); + var maxDuration = 0; + var unit = "seconds"; + var factor = 1; + + const taskInstances = groups.children.filter( + (instance) => instance.id === taskId + )[0].instances; + taskInstances.forEach((instance) => { + const runDuration = + instance?.startDate && instance?.endDate + ? getDuration(instance?.startDate, instance?.endDate) / 1000 + : 0; + const queuedDuration = + instance?.queuedDttm && instance?.startDate > instance.queuedDttm + ? getDuration(instance?.queuedDttm, instance?.startDate) / 1000 + : 0; + + if (runDuration > maxDuration) { + maxDuration = runDuration; + } + + instance.runDuration = runDuration; + instance.queuedDuration = queuedDuration; + }); + + if (maxDuration <= 60 * 2) { + factor = 1; + unit = "seconds"; + } else if (maxDuration <= 60 * 60 * 2) { + factor = 60; + unit = "minutes"; + } else if (maxDuration <= 24 * 60 * 60 * 2) { + factor = 60 * 60 * 24; + unit = "days"; + } + + taskInstances.forEach((instance) => { + instance.runDuration = instance.runDuration / factor; + instance.queuedDuration = instance.queuedDuration / factor; + }); + + function tooltipCallback(args) { + const { data } = args[0]; + const { runId } = data; + const { taskId } = data; + onSelect({ taskId, runId }); + + return ` +Run ID : ${data.runId} <br> +Queued : ${formatDateTime(data.queuedDttm)} <br> +Started : ${formatDateTime(data.startDate)} <br> +Ended : ${formatDateTime(data.endDate)} <br> +Queued Duration : ${data.queuedDuration.toFixed(2)} ${unit}<br> +Run Duration : ${data.runDuration.toFixed(2)} ${unit}<br> +Total : ${(data.queuedDuration + data.runDuration).toFixed(2)} ${unit}<br> +`; + } + + const option: ReactEChartsProps["option"] = { + series: [ + { + type: "bar", + barMinHeight: 1, + itemStyle: { + color: (params) => stateColors["queued"], + }, + stack: "x", + }, + { + type: "bar", + barMinHeight: 1, + itemStyle: { + color: (params) => stateColors[params.data.state], + }, + stack: "x", + }, + ], + dataset: { + dimensions: ["runId", "queuedDuration", "runDuration"], + source: taskInstances, + }, + tooltip: { + trigger: "axis", + formatter: tooltipCallback, + axisPointer: { + type: "shadow", + }, + }, + xAxis: { + type: "category", + show: false, + }, + yAxis: { + type: "value", + name: `duration (${unit})`, + }, + }; + + const events = { + click: (params) => console.log(params), + }; + + var chart = <ReactECharts option={option} events={events} />; Review Comment: Let's just render the chart inside of `<Box>`. I don't see a need for this to be declared as a variable first. ########## airflow/www/static/js/dag/details/taskDuration/index.tsx: ########## @@ -0,0 +1,143 @@ +/*! + * 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 React from "react"; +import { Box } from "@chakra-ui/react"; + +import useSelection from "src/dag/useSelection"; +import { useGridData } from "src/api"; +import { getDuration, formatDateTime } from "src/datetime_utils"; +import ReactECharts, { ReactEChartsProps } from "src/components/ReactECharts"; + +const TaskDuration = () => { + const { + selected: { taskId }, + onSelect, + } = useSelection(); + + const { + data: { groups }, + } = useGridData(); + var maxDuration = 0; + var unit = "seconds"; + var factor = 1; + + const taskInstances = groups.children.filter( + (instance) => instance.id === taskId + )[0].instances; + taskInstances.forEach((instance) => { + const runDuration = + instance?.startDate && instance?.endDate + ? getDuration(instance?.startDate, instance?.endDate) / 1000 + : 0; + const queuedDuration = + instance?.queuedDttm && instance?.startDate > instance.queuedDttm + ? getDuration(instance?.queuedDttm, instance?.startDate) / 1000 + : 0; + + if (runDuration > maxDuration) { + maxDuration = runDuration; + } + + instance.runDuration = runDuration; + instance.queuedDuration = queuedDuration; + }); + + if (maxDuration <= 60 * 2) { Review Comment: Can we not just use existing moment or dayjs utils to convert duration? ########## airflow/www/static/js/dag/details/taskDuration/index.tsx: ########## @@ -0,0 +1,143 @@ +/*! + * 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 React from "react"; +import { Box } from "@chakra-ui/react"; + +import useSelection from "src/dag/useSelection"; +import { useGridData } from "src/api"; +import { getDuration, formatDateTime } from "src/datetime_utils"; +import ReactECharts, { ReactEChartsProps } from "src/components/ReactECharts"; + +const TaskDuration = () => { + const { + selected: { taskId }, + onSelect, + } = useSelection(); + + const { + data: { groups }, + } = useGridData(); + var maxDuration = 0; + var unit = "seconds"; + var factor = 1; + + const taskInstances = groups.children.filter( + (instance) => instance.id === taskId + )[0].instances; + taskInstances.forEach((instance) => { + const runDuration = + instance?.startDate && instance?.endDate + ? getDuration(instance?.startDate, instance?.endDate) / 1000 + : 0; + const queuedDuration = + instance?.queuedDttm && instance?.startDate > instance.queuedDttm + ? getDuration(instance?.queuedDttm, instance?.startDate) / 1000 + : 0; + + if (runDuration > maxDuration) { + maxDuration = runDuration; + } + + instance.runDuration = runDuration; + instance.queuedDuration = queuedDuration; + }); + + if (maxDuration <= 60 * 2) { + factor = 1; + unit = "seconds"; + } else if (maxDuration <= 60 * 60 * 2) { + factor = 60; + unit = "minutes"; + } else if (maxDuration <= 24 * 60 * 60 * 2) { + factor = 60 * 60 * 24; + unit = "days"; + } + + taskInstances.forEach((instance) => { + instance.runDuration = instance.runDuration / factor; + instance.queuedDuration = instance.queuedDuration / factor; + }); + + function tooltipCallback(args) { Review Comment: Can we have more descriptive names? `formatTooltip()` ########## airflow/www/static/js/dag/details/taskDuration/index.tsx: ########## @@ -0,0 +1,143 @@ +/*! + * 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 React from "react"; +import { Box } from "@chakra-ui/react"; + +import useSelection from "src/dag/useSelection"; +import { useGridData } from "src/api"; +import { getDuration, formatDateTime } from "src/datetime_utils"; +import ReactECharts, { ReactEChartsProps } from "src/components/ReactECharts"; + +const TaskDuration = () => { + const { + selected: { taskId }, + onSelect, + } = useSelection(); + + const { + data: { groups }, + } = useGridData(); + var maxDuration = 0; + var unit = "seconds"; + var factor = 1; + + const taskInstances = groups.children.filter( + (instance) => instance.id === taskId + )[0].instances; + taskInstances.forEach((instance) => { + const runDuration = + instance?.startDate && instance?.endDate + ? getDuration(instance?.startDate, instance?.endDate) / 1000 + : 0; + const queuedDuration = + instance?.queuedDttm && instance?.startDate > instance.queuedDttm + ? getDuration(instance?.queuedDttm, instance?.startDate) / 1000 + : 0; + + if (runDuration > maxDuration) { + maxDuration = runDuration; + } + + instance.runDuration = runDuration; + instance.queuedDuration = queuedDuration; + }); + + if (maxDuration <= 60 * 2) { + factor = 1; + unit = "seconds"; + } else if (maxDuration <= 60 * 60 * 2) { + factor = 60; + unit = "minutes"; + } else if (maxDuration <= 24 * 60 * 60 * 2) { + factor = 60 * 60 * 24; + unit = "days"; + } + + taskInstances.forEach((instance) => { + instance.runDuration = instance.runDuration / factor; + instance.queuedDuration = instance.queuedDuration / factor; + }); + + function tooltipCallback(args) { + const { data } = args[0]; + const { runId } = data; + const { taskId } = data; Review Comment: And even spread out all the variables we use below: runId, queuedDttm, startDate, etc ########## airflow/www/static/js/dag/details/taskDuration/index.tsx: ########## @@ -0,0 +1,143 @@ +/*! + * 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 React from "react"; +import { Box } from "@chakra-ui/react"; + +import useSelection from "src/dag/useSelection"; +import { useGridData } from "src/api"; +import { getDuration, formatDateTime } from "src/datetime_utils"; +import ReactECharts, { ReactEChartsProps } from "src/components/ReactECharts"; + +const TaskDuration = () => { + const { + selected: { taskId }, + onSelect, + } = useSelection(); + + const { + data: { groups }, + } = useGridData(); + var maxDuration = 0; + var unit = "seconds"; Review Comment: use `let` instead of `var` for mutable variables -- 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]
