Repository navigation
Conversation
Introduces a new configuration option. When set to or , it fixes the effective value for every pool (including pre-existing pools) and prevents users from setting a conflicting per-pool value via the UI, API, or CLI. The default remains unset, preserving the existing per-pool behavior. Updates the pool model, local/FastAPI API serializers, UI config endpoint and pool form, CLI pool commands, default pool creation, and adds corresponding tests.
|
cc @ramitkataria is working on a proposal to enchance the pool mechanisem. Ramit when will the AIP published? We need to make sure pool related features are alligned with the plan |
| Note that if tasks are not given a pool, they are assigned to a default pool ``default_pool``, which is | ||
| initialized with 128 slots and can be modified through the UI or CLI (but cannot be removed). | ||
|
|
||
| Whether deferred tasks occupy pool slots is normally decided per pool via its ``include_deferred`` flag. |
There was a problem hiding this comment.
[Discussion] Instead of this should the behavior be: Deployment manager is allowed to set the default value (True/False) for all the pools created under a team or globally and let individual pool owners override this ?
There was a problem hiding this comment.
Nop, we do not want users to override it, and the decision whether to count deferrable slots like normal slots needs to remain with the cluster admins only.
| return str(self.pool) | ||
|
|
||
| @staticmethod | ||
| def get_include_deferred_override() -> bool | None: |
There was a problem hiding this comment.
What happens if the deployment manager unsets this value ? Pool table will have include_deffered=True (which was populated due to global setting).
Now if admin makes it false, the original config set by the end user will not be honored
There was a problem hiding this comment.
Again, the control lies with the admin only
I see 3 main approaches here:
- We let the users provide the value of their choice, store in the DB as well, but don't honor it if global config is set to True or False. This also creates an issue of accepting the payload but not honoring it.
- We don't allow users to pass any value if global config is set (true or false), but if the admin unsets the global conf, all pools will have a None value, which is equivalent to false only, again not ideal.
- We don't allow users to pass any value if global config is set, and set the value of global config in DB against the pool. When admin changes the conf to empty, those values will be honored.
The third approach looks better and less confusing than 1 & 2.
There was a problem hiding this comment.
Can you elaborate more on option (3).
Suppose the global config was not set, and some users have configured values as true or false.
Now admin sets the value, values set by users are overriden by the admin value and scheduling decisions are made on that.
Admin unset the values to null --> user value should get honoured now.
By your change, will this behavior be enforced ? Or are you suggesting something alternate ?
There was a problem hiding this comment.
Is this extensible to team based config ? For example, I want to enable the config for team A, but disable it for team B and keep it unset for team C ?
There was a problem hiding this comment.
Making it team wise would be another big change and doing all this in a single PR won't be good. I believe if there are some companies who wanted to use Team level config, they can extend it and contribute.
| return None | ||
|
|
||
| @property | ||
| def effective_include_deferred(self) -> bool: |
There was a problem hiding this comment.
Should we use this only for scheduling decisions ? Let the original value get stored in DB (whatever the end user provided) and take AND of both the values when making a task scheduling decision.
There was a problem hiding this comment.
This is option 1 in my comment above, but I think option 3 is better and less confusing for users
There was a problem hiding this comment.
We can use a slight variation of option 1 where we accept values until the global config is not set. Once set, the UI option is disabled and shows the global value. Now later on, if admin decides to unset the value, the existing/old values given by the users start honoring again and new users get option to choose/update their value. WDYT ?
There was a problem hiding this comment.
yeah, but it means we've to keep option open in UI, API, and CLI, accepting the values but not honoring it eventually. It's better to not accept it and model their usage around the value set by the admin only. Also, there won't be any right or wrong behaviour is possible, ideally I don't expect admins to play around with this setting, for e.g. it'll always be set to true in our usecase.
|
|
||
| include_deferred_override = Pool.get_include_deferred_override() | ||
| if include_deferred_override is not None: | ||
| include_deferred = include_deferred_override |
There was a problem hiding this comment.
This will permanently override the global config to pool configs right, making the rollback not possible ?
There was a problem hiding this comment.
This is what option 3 in my previous comment
| name="include_deferred" | ||
| render={({ field }) => ( | ||
| <Field.Root mb={4} mt={4}> | ||
| <Field.Root disabled={includeDeferredOverride !== undefined} mb={4} mt={4}> |
There was a problem hiding this comment.
If the global config is set, should we just skip showing the option to users to configure whether to include deferred slots or not
There was a problem hiding this comment.
the option is diabled
| :raises ValueError: if the flag is fixed cluster-wide but present in the request body. | ||
| """ | ||
| override = Pool.get_include_deferred_override() | ||
| if override is not None and "include_deferred" in provided_fields: |
There was a problem hiding this comment.
With the config set, this 422s every pool write from airflowctl, not just the ones where the user asked for a value. airflowctl's generated PoolBody defaults include_deferred to False, its generated boolean flags default to False as well, and pools.create dumps with exclude_none=True, so the key is always sent. pools.update and pools.bulk dump without exclude_unset, so an update sends "include_deferred": null (the parametrized None case in test_patch_pool_rejects_include_deferred_when_fixed_by_config pins that as a 422), and pools import passes include_deferred=pool_config.get(..., False) even when the file has no such key. The released airflowctl 1.0.0b1 does the same. Since airflow pools set/import/export are deprecated_for_airflowctl, the recommended CLI can't create, update or import pools on a cluster with this set, which also contradicts the "whether via the API or the CLI" line in pools.rst.
Could this treat null as not provided (and possibly accept a value equal to the override), with airflowctl changed to only send fields the user passed? That would also let a GET-then-PATCH round trip through, since GET now returns the override value. Whichever contract you pick, an airflowctl test with the option set would pin it.
| def enforce_include_deferred_override(self) -> PoolBody: | ||
| override = _reject_user_provided_include_deferred(self.model_fields_set) | ||
| if override is not None: | ||
| self.include_deferred = override |
There was a problem hiding this comment.
Assigning here adds include_deferred to model_fields_set (pydantic v2 __setattr__ does that without validate_assignment), so the server-injected value then looks user-provided to everything downstream. With the option set, a bulk update of default_pool fails on its own: PATCH /pools with {"actions":[{"action":"update","update_mask":["slots"],"entities":[{"name":"default_pool","slots":64}]}]} hits update_orm_from_pydantic, which dumps include={"slots","include_deferred"}, exclude_unset=True, gets include_deferred back, and re-validates it through PoolPatchBody, which rejects it. That's a RequestValidationError, not an HTTPException, so handle_bulk_update doesn't catch it and the whole bulk request returns 422, other actions included. Single-pool PATCH /pools/default_pool is fine, since PoolPatchBody never assigns.
Could the value be set without marking it as provided? A Field(default_factory=lambda: Pool.get_include_deferred_override() or False) with only the reject check left in the validator does that, as does applying it where the ORM row is built. The same leak is why bulk overwrite and mask-less bulk update write the override into existing pools' column while single PATCH doesn't; whichever way option 3 lands, it'd be good for those paths to agree. There's no bulk-update test under the option today, only bulk create, so one for default_pool with update_mask=["slots"] would catch this.
|
|
||
| def _apply_include_deferred_override(value: bool) -> bool: | ||
| override = Pool.get_include_deferred_override() | ||
| return value if override is None else override |
There was a problem hiding this comment.
This is the same value if override is None else override as Pool.effective_include_deferred, which this PR adds as the single place for it (and it's repeated again in slots_stats and create_or_update_pool). Since PoolResponse is built from the ORM object, include_deferred: bool = Field(validation_alias=AliasChoices("effective_include_deferred", "include_deferred")) would reuse the property and drop this helper, without changing the OpenAPI schema.
| from airflow.utils.providers_configuration_loader import providers_configuration_loaded | ||
|
|
||
|
|
||
| def get_include_deferred_rejection() -> str | None: |
There was a problem hiding this comment.
This message is also built in _reject_user_provided_include_deferred in datamodels/pools.py, and the two copies have already drifted (the API one adds "Please contact your administrator."). A single helper next to Pool.get_include_deferred_override returning the message, with the API raising ValueError and the CLI SystemExit, keeps them in step. Nothing outside this module uses it, so _get_include_deferred_rejection would match _show_pools and friends.
| """Help export all the pools to the json file.""" | ||
| api_client = get_current_api_client() | ||
| # Omit the field when it is fixed cluster-wide, otherwise the exported file cannot be imported back | ||
| export_include_deferred = Pool.get_include_deferred_override() is None |
There was a problem hiding this comment.
Leaving the key out keeps a same-cluster round trip working, but the export still prints "Exported N pools" with no hint that include_deferred was dropped. Importing that file on a cluster without the option then creates every pool with include_deferred=False through the v.get("include_deferred", False) default, where before this PR the value travelled with the file. Worth printing a line when it's omitted, and a sentence in pools.rst saying exports carry no include_deferred while the option is set?
|
|
||
| Whether deferred tasks occupy pool slots is normally decided per pool via its ``include_deferred`` flag. | ||
| A Deployment Manager can instead fix this behavior for the whole cluster with | ||
| :ref:`config:core__pool_include_deferred`. When that option is set to ``True`` or ``False``, the configured |
There was a problem hiding this comment.
Should this say which components need the option? The scheduler applies it in slots_stats and open_slots, while the UI checkbox and PoolResponse reflect the API server's config. If it's set only on the API server, the UI shows every pool as fixed to the configured value while the scheduler keeps counting from the stored column.
| When ``[core] pool_include_deferred`` is set, its value applies to every pool and takes | ||
| precedence over the per-pool ``include_deferred`` column. Returns None when unset. | ||
| """ | ||
| from airflow.configuration import conf |
There was a problem hiding this comment.
There's no cycle to avoid here: pool.py already imports airflow.models.base, which imports conf at module level, and configuration.py doesn't import airflow.models at the top. Could this move to the top of the file? The existing one in create_or_update_pool can go with it.
| assert (TaskInstanceState.DEFERRED in pool.get_occupied_states()) is deferred_is_occupied | ||
|
|
||
| @conf_vars({("core", "pool_include_deferred"): "True"}) | ||
| def test_slots_stats_use_override(self, dag_maker): |
There was a problem hiding this comment.
This covers stored False with the option True only (same for test_create_or_update_pool_stores_override with input False), so a regression to stored or override would still pass while stored True under False counts deferred tasks. Could both be parametrized over (False, "True") and (True, "False") the way test_get_occupied_states_uses_override is? test_create_or_update_pool_stores_override also takes session without using it; asserting the stored row through it would check what the name says.
| assert self.session.scalar(select(Pool).where(Pool.pool == "locked_pool")) is None | ||
|
|
||
| def test_pool_set_without_include_deferred_stores_config_value(self): | ||
| try: |
There was a problem hiding this comment.
TestCliPools.tearDown is the unittest name, which pytest never calls on a plain class, and that's why these tests wrap themselves in try/finally: self._cleanup(). Renaming it to teardown_method would let the three new wrappers go, and it would also clean up after the two new rejection tests, which have no cleanup if a regression lets locked_pool get created.
|
|
||
| const onSubmit = (data: PoolBody) => { | ||
| manageMutate(data); | ||
| manageMutate(includeDeferredOverride === undefined ? data : { ...data, include_deferred: undefined }); |
There was a problem hiding this comment.
Nothing tests this branch or the matching update_mask guard in useEditPool.ts. If a later change sends include_deferred: null or passes data through unchanged, every UI create and edit starts returning 422 with the option set. A PoolForm.test.tsx mocking useConfig (as useRerunWithLatestVersion.test.tsx does) that checks the checkbox is disabled and manageMutate gets include_deferred: undefined would pin it.
|
@msumit any progress here? Do you need help addressing comments? |
Value prop: As a centralised platform team, we don't want end users to give control of this field, especially when they are totally unaware of what
deferredreally means here. For them, pool slots are used to control the load on the downstream systems like Spark and Presto, and it doesn't matter whether that task is deferred or not. So with a cluster level config we'll take control of the behaviour.Changes: Introduced a new configuration option
core.pool_include_deferred. When set toTrueorFalse, it fixes the effective value for every pool (including pre-existing pools) and prevents users from setting a conflicting per-pool value via the UI, API, or CLI.The default remains unset (empty string
""), preserving the existing per-pool behavior.Updated the pool model, local/FastAPI API serializers, UI config endpoint and pool form, CLI pool commands, default pool creation, and added corresponding tests.
TrueFalseWas generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.