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

[Webserver] Use operator_name instead of task_type in UI #31662

Merged
merged 5 commits into from
Jun 15, 2023

Conversation

utkarsharma2
Copy link
Contributor

@utkarsharma2 utkarsharma2 commented Jun 1, 2023

we should use operator_name when displaying operator name in UI.

Related: #28466 (not closing yet, see discussion below)

@boring-cyborg boring-cyborg bot added area:UI Related to UI/UX. For Frontend Developers. area:webserver Webserver related Issues labels Jun 1, 2023
@utkarsharma2 utkarsharma2 marked this pull request as draft June 1, 2023 08:33
@utkarsharma2 utkarsharma2 changed the title Use operator_name [Webserver] Use operator_name instead of task_type in UI Jun 1, 2023
@utkarsharma2 utkarsharma2 marked this pull request as ready for review June 1, 2023 08:36
airflow/www/views.py Outdated Show resolved Hide resolved
@utkarsharma2 utkarsharma2 requested a review from uranusjr June 1, 2023 09:00
@utkarsharma2
Copy link
Contributor Author

Found one more instance of task_type usage in UI, working on changes accordingly.

@utkarsharma2 utkarsharma2 marked this pull request as draft June 1, 2023 10:48
@utkarsharma2 utkarsharma2 requested a review from uranusjr June 2, 2023 03:54
@utkarsharma2 utkarsharma2 marked this pull request as ready for review June 2, 2023 03:55
@utkarsharma2
Copy link
Contributor Author

utkarsharma2 commented Jun 2, 2023

@uranusjr While going through the code I found there are two other tooltips where we show the operator name

tt += `Operator: ${escapeHtml(ti.operator)}<br>`;

and
tt += `Operator: ${escapeHtml(ti.operator)}<br>`;

Ideally, both of them should show values derived from custom_operator_name but only the base operator has the operator_name property and not the task instance object. In both of the instance as mentioned above, we are displaying values of ti.operator which are populated from task_type of operator.

self.operator = task.task_type

since self.operator is getting used at multiple places in code, I think we should create another property in the task instance operator similar to operator_name in the base operator and use that while displaying in UI.

However, this change can be a separate PR. WDYT?

@uranusjr
Copy link
Member

uranusjr commented Jun 2, 2023

Hmm, yeah adding a new field is probably the simplest approach. Can you find other uses of TaskInstance.operator so maybe we can analyse if this field is simply for UI (if so, we can just change it to use operator_name), or do other logic depend on it? Adding a field is relatively expensive on TaskInstance so we should avoid that if possible.

Either way, I think we should hold this PR as-is and continue looking into TaskInstance.operator in a different PR.

@@ -3084,6 +3084,7 @@ class GraphForm(DateTimeWithNumRunsWithDagRunsForm):
t.task_id: {
"dag_id": t.dag_id,
"task_type": t.task_type,
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this? If the only use case if to check SubDagOperator, we can use operator_name as well.

Copy link
Contributor Author

@utkarsharma2 utkarsharma2 Jun 8, 2023

Choose a reason for hiding this comment

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

Yes, I think we still need this since the below code compares the operator class name and it's best to keep this since the operato_name can change.

isSubDag: task.task_type === "SubDagOperator",

and based on that displaying the subdag button -
if (isSubDag) {
$("#div_btn_subdag").show();
subDagId = `${dagId}.${taskId}`;
} else {
$("#div_btn_subdag").hide();
}

Copy link
Contributor

@bbovenzi bbovenzi Jun 8, 2023

Choose a reason for hiding this comment

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

Wouldn't it be better to pass is_subdag from the webserver instead? That's what we do in the REST API

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bbovenzi Would it make sense to raise a separate PR for this change? because I think it's a separate task.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, let's do a separate PR.

@eladkal eladkal added this to the Airflow 2.6.2 milestone Jun 2, 2023
@utkarsharma2
Copy link
Contributor Author

Hmm, yeah adding a new field is probably the simplest approach. Can you find other uses of TaskInstance.operator so maybe we can analyze if this field is simply for UI (if so, we can just change it to use operator_name), or do other logic depends on it? Adding a field is relatively expensive on TaskInstance so we should avoid that if possible.

Either way, I think we should hold this PR as-is and continue looking into the TaskInstance.operator in a different PR.

@uranusjr I checked for the usage of ti.operator and found out there are a lot of places where it's been used, below are a few examples

created_counts[ti.operator] += 1

for ti in query.filter(TI.operator == ExternalTaskMarker.__name__):

TaskInstance.operator certainly has more usage than just displaying in UI.

I think adding another field to TaskInstance will be a quick solution. WDYT?

@uranusjr
Copy link
Member

uranusjr commented Jun 8, 2023

Yes that’s probably best. I think some of the use cases can technically switch to operator_name (e.g. logging), but at least the second one you mentioned should use the raw class name.

@eladkal eladkal modified the milestones: Airflow 2.6.2, Airlfow 2.6.3 Jun 8, 2023
@utkarsharma2
Copy link
Contributor Author

@uranusjr Added a new property custom_operator_name in TaskInstance class.

Also, would be nice if you can cross verify all the places that should be populating the value for custom_operator_name are covered.

@utkarsharma2
Copy link
Contributor Author

@uranusjr since there is a new field added to TaskInstance class which requires a new column to be created in TaskInstance table. I think this would be a breaking change, right? Do we have something that does database migration similar to Django migrations? if so, we can add a default value so that the database migrations can be smooth for existing TaskInstance.

@potiuk
Copy link
Member

potiuk commented Jun 11, 2023

@uranusjr since there is a new field added to TaskInstance class which requires a new column to be created in TaskInstance table. I think this would be a breaking change, right? Do we have something that does database migration similar to Django migrations? if so, we can add a default value so that the database migrations can be smooth for existing TaskInstance.

We have alembic. You can see the docs about addin new migrations (look for alembic) and you can also take a look at past prs that added migrations to airflow\migrations. Also worth looking at the airflow db command and all their subcommands and https://airflow.apache.org/docs/apache-airflow/stable/migrations-ref.html

@@ -3084,6 +3084,7 @@ class GraphForm(DateTimeWithNumRunsWithDagRunsForm):
t.task_id: {
"dag_id": t.dag_id,
"task_type": t.task_type,
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, let's do a separate PR.

@jedcunningham jedcunningham merged commit 1950efe into apache:main Jun 15, 2023
@ephraimbuddy ephraimbuddy added type:improvement Changelog: Improvements type:new-feature Changelog: New Features and removed type:improvement Changelog: Improvements labels Jul 6, 2023
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 type:new-feature Changelog: New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants