Skip to content

Fix Task Duration Calculation & Display#23173

Closed
aschoe21 wants to merge 2 commits intoapache:mainfrom
aschoe21:task_duration_display_fix
Closed

Fix Task Duration Calculation & Display#23173
aschoe21 wants to merge 2 commits intoapache:mainfrom
aschoe21:task_duration_display_fix

Conversation

@aschoe21
Copy link

closes: #23169
Prevent moment from truncating the result of diff to zero decimal places

As moment.diff has the default behavior of truncating the decimal places of diff results (i.e. rounding down to the nearest integer), when the duration of a task run is less than a full second moment rounds the duration down to 0. This behavior results in the task duration rendering as empty/null rather than as the correct task run duration.

Moment's diff function accepts a third, optional boolean argument that dictates its result truncation behavior. By default this value is false which leads to the unwanted behavior described above. Setting this argument to true when calling diff will allow the result to exist as a decimal, fixing the situation where task run duration is rounded down to 0 seconds.

@boring-cyborg boring-cyborg bot added area:UI Related to UI/UX. For Frontend Developers. area:webserver Webserver related Issues labels Apr 22, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 22, 2022

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@frankcash
Copy link
Contributor

hi @aschoe21 could you include a screenshot of the functionality working as well?

@aschoe21
Copy link
Author

hi @aschoe21 could you include a screenshot of the functionality working as well?

Sure, here's a screenshot of the tooltip showing a task completing in 0.105Sec

image

@aschoe21 aschoe21 force-pushed the task_duration_display_fix branch 3 times, most recently from 319f921 to 9e16b0c Compare April 24, 2022 07:32
@aschoe21 aschoe21 force-pushed the task_duration_display_fix branch from 9e16b0c to da586f6 Compare April 25, 2022 01:05
@uranusjr
Copy link
Member

Would the decimal places always show, even when the duration is long? Ideally I’d only want them when the duration is <1 and not if it’s e.g. 105.378 seconds.

@bbovenzi
Copy link
Contributor

bbovenzi commented Apr 25, 2022

Would the decimal places always show, even when the duration is long? Ideally I’d only want them when the duration is <1 and not if it’s e.g. 105.378 seconds.

Yes, and this also breaks down when duration is better shown as minutes, hours or even days. Overall, how we display durations in the UI is inconsistent and we should consolidate down to one format. I was playing around with that here: https://github.com/apache/airflow/pull/22996/files

What do you think of choosing the most important unit and then limiting to just 1-2 decimal places:
Screen Shot 2022-04-25 at 8 59 59 AM
Screen Shot 2022-04-25 at 8 59 55 AM

@ashb
Copy link
Member

ashb commented Apr 25, 2022

I think if it's in to minutes or hours then 1h58m is better 1.98h

Copy link
Contributor

@bbovenzi bbovenzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update convertSecondsToHumanReadable in main.js:

  • Only show decimal if seconds is less than 1
  • If decimal is also 0, then lets return <1ms
  • Switch Hours -> h, Min -> m, Sec -> s

I think with those changes this should be good to merge. Then we can update the rest of the UI and webserver to make sure duration is always displayed consistently.

@eladkal
Copy link
Contributor

eladkal commented May 27, 2022

@aschoe21 are you still working on this PR?

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Jul 12, 2022
@github-actions github-actions bot closed this Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:UI Related to UI/UX. For Frontend Developers. area:webserver Webserver related Issues stale Stale PRs per the .github/workflows/stale.yml policy file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task Duration shows as "empty" when it was really less than 1 second

6 participants