Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#16692 show schedule_interval/timetable description in UI #16931

Merged

Conversation

pateash
Copy link
Contributor

@pateash pateash commented Jul 11, 2021

Closes #16692 ,

As the schedule_interval could be of type datetime.timedelta or
dateutil.relativedelta.relativedelta or str, only showing description whenever the type is string ( cron or predefined presets ).
User can also choose to use Timetable API and this works as well.

image

Description implemented for Once and Null Timetable and we can easily extend it to support others going forward.

image

image

Predefined Presets are also evaluated

image

@boring-cyborg boring-cyborg bot added area:UI Related to UI/UX. For Frontend Developers. area:webserver Webserver related Issues labels Jul 11, 2021
@pateash pateash changed the title #16692 show cron schedule description in UI #16692 show cron description in UI Jul 12, 2021
@pateash pateash closed this Jul 13, 2021
@pateash pateash reopened this Jul 13, 2021
Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

LGTM. I know others have some opinions on which description is good so If you want to chime in - feel free before I merge it.

@github-actions
Copy link

The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Jul 13, 2021
@ryanahamilton
Copy link
Contributor

Since some of these can be lengthy, I'm wondering if the Runs: prefix is superfluous? Maybe the At too?

@pateash
Copy link
Contributor Author

pateash commented Jul 13, 2021

Since some of these can be lengthy, I'm wondering if the Runs: prefix is superfluous? Maybe the At too?

At is part of library output, So I would not recommend stripping it manually.
From a Length perspective, I think most of the time the length should be manageable even with the Runs:,
let me know your thoughts.

Copy link
Contributor

@ryanahamilton ryanahamilton left a comment

Choose a reason for hiding this comment

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

I'd be in favor of at least removing the "Runs: ". Additionally, the adjacent column heading is "Runs", so using the same term in two different columns with slightly different meanings is probably best to avoid.

@pateash
Copy link
Contributor Author

pateash commented Jul 13, 2021

I'd be in favor of at least removing the "Runs: ". Additionally, the adjacent column heading is "Runs", so using the same term in two different columns with slightly different meanings is probably best to avoid.

Sure, make sense.

airflow/www/views.py Outdated Show resolved Hide resolved
airflow/timetables/interval.py Outdated Show resolved Hide resolved
airflow/timetables/base.py Outdated Show resolved Hide resolved
airflow/models/dag.py Outdated Show resolved Hide resolved
airflow/timetables/base.py Outdated Show resolved Hide resolved
@pateash pateash requested a review from uranusjr July 16, 2021 04:51
@uranusjr
Copy link
Member

we can create a base class like DagBase which will have the common properties, but I think it's a overkill but a better approach so applying this.

The problem is, we are planning to make timetable directly customisable by the user like this:

class MyCustomTimetable(Timetable):
    ...

dag = DAG(
    ...,
    timetable=MyCustomTimetable(),
)

and this can be any rich Python object. So while the BaseDag approach works right now, it will not work once the timetable instance is not calculated directly from schedule_interval. So we need to access the original DAG.timetable property instead.

This is actually not difficult at all. All the DAG objects are in current_app.dag_bag, so you can add this to the template’s context:

'dag_timetable': current_app.dag_bag.get_dag(dag.dag_id).timetable

But it is pretty cumbersome to add this for all views that render dag.html (because this is a base template inherited by many), and even more difficult to do for dags.html. So I’m thinking we probably need to expose current_app.dag_bag in the template instead, maybe by poplating dag_bag into the global Jinja environment (with e.g. current_app.jinja_env.add_template_global()), or something else. I’m unfortuantely not familiar with Flask enough to know the best practice.

@pateash
Copy link
Contributor Author

pateash commented Jul 20, 2021

@ashb @potiuk @kaxil @uranusjr @ryanahamilton
Please correct me If I am wrong here,

As far as I know we use DagModel object to render dag information in UI,
so for timeline even if we use something like an Enriched Python Object in the future, we will still need to store that information in Database/DagModel.

class MyCustomTimetable(Timetable):
    ...

dag = DAG(
    ...,
    timetable=MyCustomTimetable(),
)

So, while rendering in UI, we will need that information in DagModel and we can't use DAG.timetable.

I think, whenever we do a change in DAG Api for allowing timetable as an argument, we can modify our model to accommodate that change and show the description according to the requirements needed at that point in time.

@uranusjr
Copy link
Member

uranusjr commented Jul 20, 2021

The problem is we can’t store the timetable object in db (at least not easily; it’s technically doable but should be avoided). Maybe we can pre-render the description and store that (it’d be just a string) on DagModel instead? Call it timetable_description or something. Again, I’m not sure how best to do this.

@pateash
Copy link
Contributor Author

pateash commented Jul 21, 2021

The problem is we can’t store the timetable object in db (at least not easily; it’s technically doable but should be avoided). Maybe we can pre-render the description and store that (it’d be just a string) on DagModel instead? Call it timetable_description or something. Again, I’m not sure how best to do this.

Honestly, I am not sure what you are trying to suggest here.
@uranusjr, If you are trying to suggest some specific changes we should do, let me know.

currently, timetable.description has same logic for DAG and DagModel which might change in future as you pointed out.

We can modify that behaviour later whenever we do that change.

@uranusjr
Copy link
Member

uranusjr commented Jul 28, 2021

I think we need to delay this a bit until we find a way to properly serialise DAG.timetable to DagModel (and SerializedDagModel, but that’s another matter). I will work on that in the coming weeks, and once that’s figured out, this should be much more straightforward to implement. The timetable thing is scheduled to be released on 2.2, so this should also make it into that release as well.

@pateash
Copy link
Contributor Author

pateash commented Jul 28, 2021

I agree @uranusjr,
let's wait for your change.
Could you please mention your PR/Issue here, so we can track it.

@uranusjr
Copy link
Member

I think it's better to show a message that says "descritpion can not be evaluated for non standard cron" or something of a sort

That works for me. My main concern is only to not show the wrong explaination.

@pateash
Copy link
Contributor Author

pateash commented Oct 20, 2021

image

The info icons next to the badges are unnecessary. I'd look at how the Next Run badge next to it works.

the reason I have added Icon, as we will not be able to provide the description in all the cases,
for example in case of deltatimetable we are not providing any description, in this case it will be easier for the user to know if there is any Description available or not.

@pateash
Copy link
Contributor Author

pateash commented Oct 20, 2021

I think it's better to show a message that says "descritpion can not be evaluated for non standard cron" or something of a sort

That works for me. My main concern is only to not show the wrong explanation.

Agree, but I think we should not provide any description if not available ( as we are doing in other cases like datetimedeltaTimeTable and other types)
let me know your thoughts.

@pateash pateash closed this Oct 20, 2021
@pateash pateash reopened this Oct 20, 2021
@uranusjr
Copy link
Member

Again, I have no strong opinions here (as long as we don't provide incorrect description), so feel free to do what you think is best.

@pateash
Copy link
Contributor Author

pateash commented Oct 20, 2021

Again, I have no strong opinions here (as long as we don't provide incorrect description), so feel free to do what you think is best.

Sure, I am pretty much done with the changes from my end.
please let me know if you have any other suggestion.

Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

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

We should also add something to the documentation for this in docs/apache-airflow/howto/timetable.rst

airflow/models/dag.py Outdated Show resolved Hide resolved
airflow/timetables/base.py Outdated Show resolved Hide resolved
airflow/timetables/interval.py Outdated Show resolved Hide resolved
airflow/timetables/simple.py Outdated Show resolved Hide resolved
@pateash pateash requested a review from uranusjr October 24, 2021 17:30
@uranusjr
Copy link
Member

Generally looks good to me now! One thing I'm wondering is how None and "" differ semantically. From the current implementation in HTML, they seem to be equal? How could a difference be introduced in the future? If there are no differences in semantics for our current use cases, IMO it'd be a good idea to forbid None (NULL in database) for now to save it for potential use cases that may come up.

@pateash
Copy link
Contributor Author

pateash commented Oct 25, 2021

Generally looks good to me now! One thing I'm wondering is how None and "" differ semantically. From the current implementation in HTML, they seem to be equal? How could a difference be introduced in the future? If there are no differences in semantics for our current use cases, IMO it'd be a good idea to forbid None (NULL in database) for now to save it for potential use cases that may come up.

That's a really good point from future perspective,
We should really use empty string for keeping options open.
Doing the changes.

@uranusjr uranusjr added this to the Airflow 2.3.0 milestone Oct 26, 2021
@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 Dec 11, 2021
@pateash pateash force-pushed the #16692-show-cron-schedule-description-in-ui branch 3 times, most recently from f7c4fbc to bce3dbf Compare December 11, 2021 22:57
pateash and others added 3 commits December 12, 2021 15:23
* Create ap_codeql-analysis.yml

* 16692 - deleted file

* 16692 - changes done

* 16692 - test added

* 16692 - pre-commits fixed

* 16692 - pre-commits fixed

* 16692 - pre-commits fixed

* 16692 - Runs removed from description

* Update airflow/www/templates/airflow/dags.html

Co-authored-by: Ryan Hamilton <[email protected]>

* 16692 - pre-commits fixed

* 16692 - using timetable for showing description

* 16692 - pre-commits fixed

* Update airflow/timetables/base.py

Co-authored-by: Tzu-ping Chung <[email protected]>

* 16692 - fixed types

* 16692 - used Base class for storing common properties

* 16692 - using cached_property for description

* 16692 - using cached_property for description

* 16692 - merge fix

* 16692 - removed dagbase

* 16692 - removed unnecessary changes

* 16692 - test name fixed

* 16692 - timetable_description column added to dag table.

* 16692 - None timetable description updated

* 16692 - tests added

* 16692 - review comments.

* 16692 - precommit fixes

* 16692 - precommit fixes

* 16692 - fixed test checks

* 16692 - ignoring description computation for 6th param in Cron expression

* 16692 - pre-commit fixed

* Update airflow/timetables/base.py

Co-authored-by: Tzu-ping Chung <[email protected]>

* 16692 - documentation added for timetable description

* 16692 - resolving PR comments

* 16692 - precommit fixes

* 16692 - documentation fix

* 16692 - using empty string as a default description

* 16692 - test fixed

* [apache#16692] - migration file updated

Signed-off-by: Ashish Patel <[email protected]>

Co-authored-by: Ryan Hamilton <[email protected]>
Co-authored-by: Tzu-ping Chung <[email protected]>
Signed-off-by: Ashish Patel <[email protected]>
@pateash pateash force-pushed the #16692-show-cron-schedule-description-in-ui branch from 76a9e14 to f3e907c Compare December 12, 2021 15:24
@uranusjr uranusjr merged commit 7c81df6 into apache:main Dec 13, 2021
@pateash
Copy link
Contributor Author

pateash commented Dec 13, 2021

@uranusjr there were some CI failures due to kerberos authentication.
I hope they are sorted already.

@uranusjr
Copy link
Member

Yeah those were just timing out, probably temporary networking error. This has nothing to do with them, and all other CI jobs pass without issues, so the possibility there is a genuine breakage is extremely low.

@pateash pateash deleted the #16692-show-cron-schedule-description-in-ui branch December 13, 2021 14:49
@pateash pateash restored the #16692-show-cron-schedule-description-in-ui branch February 15, 2022 13:46
@pateash pateash deleted the #16692-show-cron-schedule-description-in-ui branch February 15, 2022 13:49
@jedcunningham jedcunningham added the type:improvement Changelog: Improvements label Mar 4, 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 full tests needed We need to run full set of tests for this PR to merge stale Stale PRs per the .github/workflows/stale.yml policy file type:improvement Changelog: Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show schedule_interval/timetable description for schedule cron expression in Airflow UI
10 participants