astro-provider-anyscale
This repository provides a set of tools for integrating Anyscale with Apache Airflow, enabling the orchestration of Anyscale jobs and services within Airflow workflows. It includes a custom hook, two operators, and two triggers specifically designed for managing and monitoring Anyscale jobs and services.
Components
Hook
- AnyscaleHook: Facilitates communication between Airflow and Anyscale. It uses the Anyscale API to interact with the Anyscale platform, providing methods to submit jobs, query their status, and manage services.
Operators
- SubmitAnyscaleJob: This operator submits a job to Anyscale. It takes configuration parameters for the job, such as the entrypoint, image URI, and compute configuration. The operator uses
AnyscaleHookto handle the submission process. - RolloutAnyscaleService: Similar to the job submission operator, this operator is designed to manage services on Anyscale. It can be used to deploy new services or update existing ones, leveraging
AnyscaleHookfor all interactions with the Anyscale API.
Triggers
- AnyscaleJobTrigger: Monitors the status of asynchronous jobs submitted via the
SubmitAnyscaleJoboperator. It ensures that the Airflow task waits until the job is completed before moving forward in the DAG. - AnyscaleServiceTrigger: Works in a similar fashion to the
AnyscaleJobTriggerbut is focused on service rollout processes. It checks the status of the service being deployed or updated and returns control to Airflow upon completion.
Configuration Details for Anyscale Integration
To integrate Airflow with Anyscale, you will need to provide several configuration details:
-
Anyscale API Token: Obtain your API token either by using the anyscale cli or through the Anyscale console.
-
Compute Config (optional): If you want to constrain autoscaling, you can specify the compute cluster that will execute your Ray script by either:
- Dynamically providing this via the
compute_configinput parameter, or - Creating a compute configuration in Anyscale and using the resulting ID in the
compute_config_idparameter.
- Dynamically providing this via the
-
Image URI: Specify the docker image you would like your operator to use. Make sure your image is accessible within your Anyscale account. Note, you can alternatively specify a containerfile that can be used to dynamically build the image
Usage
Install the Anyscale provider using the command below:
pip install astro-provider-anyscale
Airflow Connection Configuration
To integrate Airflow with Anyscale, configure an Airflow connection with a unique name and set the password as the API token gathered through the Anyscale console.
-
Access Airflow Web UI:
- Open the Airflow web interface and log in using your Airflow credentials.
-
Create a New Connection in Airflow:
- Go to the "Admin" tab and select "Connections" from the dropdown menu.
- Click the "Add a new record" button to create a new connection.
-
Configure the Connection:
- Conn Id: Enter a unique identifier for the connection, e.g.,
anyscale_conn. - Conn Type: Select
Anyscale - Password: Paste the API token you copied from the Anyscale console.
- Conn Id: Enter a unique identifier for the connection, e.g.,
-
Save the Connection:
- After filling in the required details, click the "Save" button at the bottom of the form to save the new connection.
Code samples
The below script is an example of how to configure and use the SubmitAnyscaleJob operator within an Airflow DAG:
from pathlib import Path
from datetime import datetime, timedelta
from airflow import DAG
from anyscale_provider.operators.anyscale import SubmitAnyscaleJob
default_args = {
"owner": "airflow",
"depends_on_past": False,
"start_date": datetime(2024, 4, 2),
"email_on_failure": False,
"email_on_retry": False,
"retries": 1,
"retry_delay": timedelta(minutes=5),
}
# Define the Anyscale connection
ANYSCALE_CONN_ID = "anyscale_conn"
# Constants
FOLDER_PATH = Path(__file__).parent / "example_dags/ray_scripts"
dag = DAG(
"sample_anyscale_job_workflow",
default_args=default_args,
description="A DAG to interact with Anyscale triggered manually",
schedule=None, # This DAG is not scheduled, only triggered manually
catchup=False,
)
submit_anyscale_job = SubmitAnyscaleJob(
task_id="submit_anyscale_job",
conn_id=ANYSCALE_CONN_ID,
name="AstroJob",
image_uri="anyscale/image/airflow-integration-testing:1",
compute_config="airflow-integration-testing:1",
working_dir=str(FOLDER_PATH),
entrypoint="python ray-job.py",
requirements=["requests", "pandas", "numpy", "torch"],
max_retries=1,
job_timeout_seconds=3000,
poll_interval=30,
dag=dag,
)
# Defining the task sequence
submit_anyscale_job
The below script uses the RolloutAnyscaleService operator to deploy a service on Anyscale:
import uuid
from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow.utils.trigger_rule import TriggerRule
from anyscale_provider.hooks.anyscale import AnyscaleHook
from anyscale_provider.operators.anyscale import RolloutAnyscaleService
default_args = {
"owner": "airflow",
"depends_on_past": False,
"start_date": datetime(2024, 4, 2),
"email_on_failure": False,
"email_on_retry": False,
"retries": 1,
"retry_delay": timedelta(minutes=5),
}
# Define the Anyscale connection
ANYSCALE_CONN_ID = "anyscale_conn"
SERVICE_NAME = f"AstroService-CICD-{uuid.uuid4()}"
dag = DAG(
"sample_anyscale_service_workflow",
default_args=default_args,
description="A DAG to interact with Anyscale triggered manually",
schedule=None, # This DAG is not scheduled, only triggered manually
catchup=False,
)
deploy_anyscale_service = RolloutAnyscaleService(
task_id="rollout_anyscale_service",
conn_id=ANYSCALE_CONN_ID,
name=SERVICE_NAME,
image_uri="anyscale/image/airflow-integration-testing:1",
compute_config="airflow-integration-testing:1",
working_dir="https://github.com/anyscale/docs_examples/archive/refs/heads/main.zip",
applications=[{"import_path": "sentiment_analysis.app:model"}],
requirements=["transformers", "requests", "pandas", "numpy", "torch"],
in_place=False,
canary_percent=None,
service_rollout_timeout_seconds=600,
poll_interval=30,
dag=dag,
)
def terminate_service():
hook = AnyscaleHook(conn_id=ANYSCALE_CONN_ID)
result = hook.terminate_service(service_name=SERVICE_NAME, time_delay=5)
print(result)
terminate_anyscale_service = PythonOperator(
task_id="initialize_anyscale_hook",
python_callable=terminate_service,
trigger_rule=TriggerRule.ALL_DONE,
dag=dag,
)
# Defining the task sequence
deploy_anyscale_service >> terminate_anyscale_service
Telemetry
This provider collects telemetry data by default.
What data is collected?
More specifically, it adds a header to every request made to the Anyscale API with the following metadata: {"X-Anyscale-Source" = "airflow"}. The telemetry does not and will not collecting any personal data or sensitive information.
How is this data used?
This data will be used by the Anyscale engineering team to better understand how the provider is being used and help guide future development.
How to opt-out of telemetry collection?
To disable usage stats collection, set the configuration anyscale.telemetry_enabled to False in your airflow.cfg file.
Changelog
We follow Semantic Versioning for releases. Check CHANGELOG.rst for the latest changes.
Contributing Guide
All contributions, bug reports, bug fixes, documentation improvements, enhancements are welcome.
A detailed overview an how to contribute can be found in the Contributing Guide
Metadata
Release files for astro-provider-anyscale 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| astro_provider_anyscale-1.3.0.tar.gz | 16.9 kB | Without provenance | Details for astro_provider_anyscale-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| astro_provider_anyscale-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for astro_provider_anyscale-1.3.0-py3-none-any.whl |
Total release size: 36.1 kB
Release files / astro_provider_anyscale-1.3.0.tar.gz
| Download URL | astro_provider_anyscale-1.3.0.tar.gz |
|---|---|
| Size | 16.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
93fa98099156a067ddd94e7abcb3bebaa6c4b3baf3346c7cc9710e1b986be923
|
|
BLAKE2b-256 checksum How to use checksums |
e4b1a79cef7ca24b65ed334e918d47500e914ac3729d4c302750eb255ca39f96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / astro_provider_anyscale-1.3.0-py3-none-any.whl
| Download URL | astro_provider_anyscale-1.3.0-py3-none-any.whl |
|---|---|
| Size | 19.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
630f851ebce1dfbda512fffa44b33229ad998f5bf34b016ed9155abcd4ea132f
|
|
BLAKE2b-256 checksum How to use checksums |
c890b7905a2eb3e3ead4e661ff61593ea1c8d635f866fa0ed70dfc54f9d62f70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for astro-provider-anyscale 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.