Skip to content

Conversation

@vincbeck
Copy link
Contributor

@vincbeck vincbeck commented Dec 20, 2022

Migrate DagFileProcessor.manage_slas to Internal API

Closes: #28268

@boring-cyborg boring-cyborg bot added the area:Scheduler including HA (high availability) scheduler label Dec 20, 2022
@vincbeck
Copy link
Contributor Author

cc @potiuk, @mhenc

@Taragolis
Copy link
Contributor

@vincbeck need resolve conflicts

@vincbeck vincbeck force-pushed the vincbeck/manage_slas branch from ddf8033 to 3831d1b Compare January 3, 2023 14:21
@vincbeck
Copy link
Contributor Author

vincbeck commented Jan 3, 2023

Done

@internal_api_call
@provide_session
def manage_slas(self, dag: DAG, session: Session = None) -> None:
def manage_slas(dag_folder, dag_id: str, log: logging.Logger, session: Session = NEW_SESSION) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Passing in a logger object feels very wrong to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, it feels also very wrong to me but maybe with some context it will help understanding it :).

All methods decorated with @internal_api_call are meant to be called either directly (like today) or through a new component: internal API (see PR here). This decision is based on the the flag database_access_isolation. What we want to achieve here is when the methods are called directly, the behavior should be the same as today, hence the logger should be the same. However, when these methods are called through the internal API, we want the logs to be separated from the current execution. Then, in that case we want a different logger. This new logger is created by the internal API itself, see PR here.

I hope it helps to understand and feel free to give me your thoughts given this context

Copy link
Member

Choose a reason for hiding this comment

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

I understand the technical aspects, but it would simply indicate either the decorator should be improved to remove this restriction, or we need a new mechanism (perhaps built upon @internal_api_call that can be used on an instance method, not only static methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mhenc what do you think? Meanwhile I'll try to find a in-between solution

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we could make it work for non-static methods - passing the whole state of the object would be tricky (we want to avoid pickling) and would affect the performance even more.

If the only problem is passing the logger, then I can see few options:

  1. Instead of passing the logger, just send the logger name and create the logger inside the method
  2. Make logger static (as Vinc suggested in the first place) - we can wrap it into some method to keep self.log available for other methods.
  3. I think internal_api_call should also work for class methods, so we could do something like this:
    https://stackoverflow.com/a/8438818

cc: @potiuk

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I'll update this PR accordingly

Copy link
Member

Choose a reason for hiding this comment

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

Not nice bot.. Closed my PR :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hahaha, yeah! It is a bossy and rude bot xD

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR updated

@potiuk
Copy link
Member

potiuk commented Jan 20, 2023

(Pending tests passing :) )

@vincbeck vincbeck force-pushed the vincbeck/manage_slas branch from 0e3a07b to 63c1f8c Compare January 20, 2023 19:39
@potiuk potiuk merged commit 0359a42 into apache:main Jan 23, 2023
@vincbeck vincbeck deleted the vincbeck/manage_slas branch January 26, 2023 15:11
@pierrejeambrun pierrejeambrun added the AIP-44 Airflow Internal API label Feb 27, 2023
@pierrejeambrun pierrejeambrun added the changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) label Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-44 Airflow Internal API area:Scheduler including HA (high availability) scheduler changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AIP-44 Migrate DagFileProcessor.manage_slas to Internal API

6 participants