Skip to content

Commit

Permalink
Merge branch 'main' into feature/common-sql-dialects
Browse files Browse the repository at this point in the history
  • Loading branch information
dabla authored Oct 18, 2024
2 parents f371bc6 + 0de5587 commit 3a34dd4
Show file tree
Hide file tree
Showing 94 changed files with 2,244 additions and 883 deletions.
1 change: 1 addition & 0 deletions .asf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ github:
- vatsrahul1001
- cmarteepants
- gopidesupavan
- bugraoz93

notifications:
jobs: jobs@airflow.apache.org
18 changes: 13 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ARG AIRFLOW_VERSION="2.10.2"
ARG PYTHON_BASE_IMAGE="python:3.9-slim-bookworm"

ARG AIRFLOW_PIP_VERSION=24.2
ARG AIRFLOW_UV_VERSION=0.4.23
ARG AIRFLOW_UV_VERSION=0.4.24
ARG AIRFLOW_USE_UV="false"
ARG UV_HTTP_TIMEOUT="300"
ARG AIRFLOW_IMAGE_REPOSITORY="https://github.com/apache/airflow"
Expand Down Expand Up @@ -515,8 +515,6 @@ function common::get_colors() {
}

function common::get_packaging_tool() {
: "${AIRFLOW_PIP_VERSION:?Should be set}"
: "${AIRFLOW_UV_VERSION:?Should be set}"
: "${AIRFLOW_USE_UV:?Should be set}"

## IMPORTANT: IF YOU MODIFY THIS FUNCTION YOU SHOULD ALSO MODIFY CORRESPONDING FUNCTION IN
Expand Down Expand Up @@ -612,7 +610,12 @@ function common::install_packaging_tools() {
echo "${COLOR_BLUE}Checking packaging tools for system Python installation: $(which python)${COLOR_RESET}"
echo
fi
if [[ ! ${AIRFLOW_PIP_VERSION} =~ [0-9.]* ]]; then
if [[ ${AIRFLOW_PIP_VERSION=} == "" ]]; then
echo
echo "${COLOR_BLUE}Installing latest pip version${COLOR_RESET}"
echo
pip install --root-user-action ignore --disable-pip-version-check --upgrade pip
elif [[ ! ${AIRFLOW_PIP_VERSION} =~ [0-9.]* ]]; then
echo
echo "${COLOR_BLUE}Installing pip version from spec ${AIRFLOW_PIP_VERSION}${COLOR_RESET}"
echo
Expand All @@ -629,7 +632,12 @@ function common::install_packaging_tools() {
pip install --root-user-action ignore --disable-pip-version-check "pip==${AIRFLOW_PIP_VERSION}"
fi
fi
if [[ ! ${AIRFLOW_UV_VERSION} =~ [0-9.]* ]]; then
if [[ ${AIRFLOW_UV_VERSION=} == "" ]]; then
echo
echo "${COLOR_BLUE}Installing latest uv version${COLOR_RESET}"
echo
pip install --root-user-action ignore --disable-pip-version-check --upgrade uv
elif [[ ! ${AIRFLOW_UV_VERSION} =~ [0-9.]* ]]; then
echo
echo "${COLOR_BLUE}Installing uv version from spec ${AIRFLOW_UV_VERSION}${COLOR_RESET}"
echo
Expand Down
39 changes: 28 additions & 11 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ function common::get_colors() {
}

function common::get_packaging_tool() {
: "${AIRFLOW_PIP_VERSION:?Should be set}"
: "${AIRFLOW_UV_VERSION:?Should be set}"
: "${AIRFLOW_USE_UV:?Should be set}"

## IMPORTANT: IF YOU MODIFY THIS FUNCTION YOU SHOULD ALSO MODIFY CORRESPONDING FUNCTION IN
Expand Down Expand Up @@ -558,7 +556,12 @@ function common::install_packaging_tools() {
echo "${COLOR_BLUE}Checking packaging tools for system Python installation: $(which python)${COLOR_RESET}"
echo
fi
if [[ ! ${AIRFLOW_PIP_VERSION} =~ [0-9.]* ]]; then
if [[ ${AIRFLOW_PIP_VERSION=} == "" ]]; then
echo
echo "${COLOR_BLUE}Installing latest pip version${COLOR_RESET}"
echo
pip install --root-user-action ignore --disable-pip-version-check --upgrade pip
elif [[ ! ${AIRFLOW_PIP_VERSION} =~ [0-9.]* ]]; then
echo
echo "${COLOR_BLUE}Installing pip version from spec ${AIRFLOW_PIP_VERSION}${COLOR_RESET}"
echo
Expand All @@ -575,7 +578,12 @@ function common::install_packaging_tools() {
pip install --root-user-action ignore --disable-pip-version-check "pip==${AIRFLOW_PIP_VERSION}"
fi
fi
if [[ ! ${AIRFLOW_UV_VERSION} =~ [0-9.]* ]]; then
if [[ ${AIRFLOW_UV_VERSION=} == "" ]]; then
echo
echo "${COLOR_BLUE}Installing latest uv version${COLOR_RESET}"
echo
pip install --root-user-action ignore --disable-pip-version-check --upgrade uv
elif [[ ! ${AIRFLOW_UV_VERSION} =~ [0-9.]* ]]; then
echo
echo "${COLOR_BLUE}Installing uv version from spec ${AIRFLOW_UV_VERSION}${COLOR_RESET}"
echo
Expand Down Expand Up @@ -1277,9 +1285,6 @@ ARG DEFAULT_CONSTRAINTS_BRANCH="constraints-main"
# It can also be overwritten manually by setting the AIRFLOW_CI_BUILD_EPOCH environment variable.
ARG AIRFLOW_CI_BUILD_EPOCH="10"
ARG AIRFLOW_PRE_CACHED_PIP_PACKAGES="true"
ARG AIRFLOW_PIP_VERSION=24.2
ARG AIRFLOW_UV_VERSION=0.4.23
ARG AIRFLOW_USE_UV="true"
# Setup PIP
# By default PIP install run without cache to make image smaller
ARG PIP_NO_CACHE_DIR="true"
Expand All @@ -1301,8 +1306,6 @@ ARG AIRFLOW_VERSION=""
# Additional PIP flags passed to all pip install commands except reinstalling pip itself
ARG ADDITIONAL_PIP_INSTALL_FLAGS=""

ARG AIRFLOW_PIP_VERSION=24.2
ARG AIRFLOW_UV_VERSION=0.4.23
ARG AIRFLOW_USE_UV="true"

ENV AIRFLOW_REPO=${AIRFLOW_REPO}\
Expand Down Expand Up @@ -1348,19 +1351,33 @@ COPY --from=scripts install_packaging_tools.sh install_airflow_dependencies_from
# The Airflow and providers are uninstalled, only dependencies remain.
# the cache is only used when "upgrade to newer dependencies" is not set to automatically
# account for removed dependencies (we do not install them in the first place)
#
# We are installing from branch tip without fixing UV or PIP version - in order to avoid rebuilding the
# base cache layer every time the UV or PIP version changes.
RUN bash /scripts/docker/install_packaging_tools.sh; \
if [[ ${AIRFLOW_PRE_CACHED_PIP_PACKAGES} == "true" ]]; then \
bash /scripts/docker/install_airflow_dependencies_from_branch_tip.sh; \
fi


# Here we fix the versions so all subsequent commands will use the versions
# from the sources
ARG AIRFLOW_PIP_VERSION=24.2
ARG AIRFLOW_UV_VERSION=0.4.24

ENV AIRFLOW_PIP_VERSION=${AIRFLOW_PIP_VERSION} \
AIRFLOW_UV_VERSION=${AIRFLOW_UV_VERSION}

# The PATH is needed for PIPX to find the tools installed
ENV PATH="/root/.local/bin:${PATH}"

COPY --from=scripts install_pipx_tools.sh /scripts/docker/

# Install useful command line tools in their own virtualenv so that they do not clash with
# dependencies installed in Airflow
RUN bash /scripts/docker/install_pipx_tools.sh
# dependencies installed in Airflow also reinstall PIP and UV to make sure they are installed
# in the version specified above
RUN bash /scripts/docker/install_packaging_tools.sh; \
bash /scripts/docker/install_pipx_tools.sh

# Airflow sources change frequently but dependency configuration won't change that often
# We copy pyproject.toml and other files needed to perform setup of dependencies
Expand Down
22 changes: 18 additions & 4 deletions airflow/dag_processing/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,24 @@ class _RunInfo(NamedTuple):

@classmethod
def calculate(cls, dags: dict[str, DAG], *, session: Session) -> Self:
"""
Query the the run counts from the db.
:param dags: dict of dags to query
"""
# Skip these queries entirely if no DAGs can be scheduled to save time.
if not any(dag.timetable.can_be_scheduled for dag in dags.values()):
return cls({}, {})
return cls(
{run.dag_id: run for run in session.scalars(_get_latest_runs_stmt(dag_ids=dags))},
DagRun.active_runs_of_dags(dag_ids=dags, session=session),

latest_runs = {run.dag_id: run for run in session.scalars(_get_latest_runs_stmt(dag_ids=dags.keys()))}
active_run_counts = DagRun.active_runs_of_dags(
dag_ids=dags.keys(),
exclude_backfill=True,
session=session,
)

return cls(latest_runs, active_run_counts)


def _update_dag_tags(tag_names: set[str], dm: DagModel, *, session: Session) -> None:
orm_tags = {t.name: t for t in dm.tags}
Expand Down Expand Up @@ -188,7 +198,11 @@ def update_dags(
processor_subdir: str | None = None,
session: Session,
) -> None:
run_info = _RunInfo.calculate(self.dags, session=session)
# we exclude backfill from active run counts since their concurrency is separate
run_info = _RunInfo.calculate(
dags=self.dags,
session=session,
)

for dag_id, dm in sorted(orm_dags.items()):
dag = self.dags[dag_id]
Expand Down
Loading

0 comments on commit 3a34dd4

Please sign in to comment.