-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update docs structure and add getting started guides (#374)
## Description <!-- Add a brief but complete description of the change. --> This PR updates the docs site with a better structure. It also adds getting started guides for each of the popular ways of running Airflow. ## Related Issue(s) Closes: #219 Closes: #316 Closes: #307 ## Breaking Change? <!-- If this introduces a breaking change, specify that here. --> ## Checklist - [ ] I have made corresponding changes to the documentation (if required) - [ ] I have added tests that prove my fix is effective or that my feature works --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Harel Shein <[email protected]>
- Loading branch information
Showing
42 changed files
with
1,094 additions
and
902 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.. _compiled-sql: | ||
|
||
Compiled SQL | ||
==================== | ||
|
||
When using the local execution mode, Cosmos will store the compiled SQL for each model in the ``compiled_sql`` field of the task's ``template_fields``. This allows you to view the compiled SQL in the Airflow UI. | ||
|
||
If you'd like to disable this feature, you can set ``should_store_compiled_sql=False`` on the local operator (or via the ``operator_args`` parameter on the DAG/Task Group). For example: | ||
|
||
.. code-block:: python | ||
from cosmos import DbtDag | ||
DbtDag( | ||
operator_args={"should_store_compiled_sql": False}, | ||
# ..., | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Execution Config | ||
================== | ||
|
||
Cosmos supports multiple ways of executing your dbt models. | ||
For more information, see the `execution modes <../getting_started/execution-modes.html>`_ page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.. _configuration: | ||
|
||
Configuration | ||
============= | ||
|
||
Cosmos offers a number of configuration options to customize its behavior. For more info, check out the links on the left or the table of contents below. | ||
|
||
.. toctree:: | ||
:caption: Contents: | ||
|
||
Project Config <project-config> | ||
Profile Config <profile-config> | ||
Execution Config <execution-config> | ||
Render Config <render-config> | ||
|
||
Parsing Methods <parsing-methods> | ||
Configuring Lineage <lineage> | ||
Generating Docs <generating-docs> | ||
Scheduling <scheduling> | ||
Testing Behavior <testing-behavior> | ||
Selecting & Excluding <selecting-excluding> | ||
Compiled SQL <compiled-sql> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
.. _lineage: | ||
|
||
Configuring Lineage | ||
=================== | ||
|
||
Cosmos uses the `dbt-ol <https://openlineage.io/blog/dbt-with-marquez/>`_ wrapper to emit lineage events to OpenLineage. Follow the instructions below to ensure Cosmos is configured properly to do this. | ||
|
||
With a Virtual Environment | ||
-------------------------- | ||
|
||
1. Add steps in your ``Dockerfile`` for the venv and wrapping the dbt executable | ||
|
||
.. code-block:: Docker | ||
FROM quay.io/astronomer/astro-runtime:7.2.0 | ||
# install python virtualenv to run dbt | ||
WORKDIR /usr/local/airflow | ||
COPY dbt-requirements.txt ./ | ||
RUN python -m venv dbt_venv && source dbt_venv/bin/activate && \ | ||
pip install --no-cache-dir -r dbt-requirements.txt && deactivate | ||
# wrap the executable from the venv so that dbt-ol can access it | ||
RUN echo -e '#!/bin/bash' > /usr/bin/dbt && \ | ||
echo -e 'source /usr/local/airflow/dbt_venv/bin/activate && dbt "$@"' >> /usr/bin/dbt | ||
# ensure all users have access to the executable | ||
RUN chmod -R 777 /usr/bin/dbt | ||
2. Create a ``dbt-requirements.txt`` file with the following contents. If you're using a different | ||
data warehouse than Redshift, then replace with the one that you're using (i.e. ``dbt-bigquery``, | ||
``dbt-snowflake``, etc.) | ||
|
||
.. code-block:: text | ||
dbt-redshift | ||
openlineage-dbt | ||
3. Add the following to your ``requirements.txt`` file | ||
|
||
.. code-block:: text | ||
astronomer-cosmos | ||
4. When instantiating a Cosmos object be sure to use the ``dbt_executable_path`` parameter for the dbt-ol | ||
installed | ||
|
||
.. code-block:: python | ||
jaffle_shop = DbtTaskGroup( | ||
..., | ||
ExecutionConfig( | ||
dbt_executable_path="/usr/local/airflow/dbt_venv/bin/dbt-ol", | ||
), | ||
) | ||
With the Base Cosmos Python Package | ||
----------------------------------- | ||
|
||
If you're using the base Cosmos Python package, then you'll need to install the dbt-ol wrapper | ||
using the ``[dbt-openlineage]`` extra. | ||
|
||
1. Add the following to your ``requirements.txt`` file | ||
|
||
.. code-block:: text | ||
astronomer-cosmos[dbt-openlineage] | ||
2. When instantiating a Cosmos object be sure to use the ``dbt_executable_path`` parameter for the dbt-ol | ||
installed | ||
|
||
.. code-block:: python | ||
jaffle_shop = DbtTaskGroup( | ||
..., | ||
ExecutionConfig( | ||
dbt_executable_path="/usr/local/airflow/dbt_venv/bin/dbt-ol", | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
.. _parsing-methods: | ||
|
||
Parsing Methods | ||
=============== | ||
|
||
Cosmos offers several options to parse your dbt project: | ||
|
||
- ``automatic``. Tries to find a user-supplied ``manifest.json`` file. If it can't find one, it will run ``dbt ls`` to generate one. If that fails, it will use Cosmos' dbt parser. | ||
- ``dbt_manifest``. Parses a user-supplied ``manifest.json`` file. This can be generated manually with dbt commands or via a CI/CD process. | ||
- ``dbt_ls``. Parses a dbt project directory using the ``dbt ls`` command. | ||
- ``custom``. Uses Cosmos' custom dbt parser, which extracts dependencies from your dbt's model code. | ||
|
||
There are benefits and drawbacks to each method: | ||
|
||
- ``dbt_manifest``: You have to generate the manifest file on your own. When using the manifest, Cosmos gets a complete set of metadata about your models. However, Cosmos uses its own selecting & excluding logic to determine which models to run, which may not be as robust as dbt's. | ||
- ``dbt_ls``: Cosmos will generate the manifest file for you. This method uses dbt's metadata AND dbt's selecting/excluding logic. This is the most robust method. However, this requires the dbt executable to be installed on your machine (either on the host directly or in a virtual environment). | ||
- ``custom``: Cosmos will parse your project and model files for you. This means that Cosmos will not have access to dbt's metadata. However, this method does not require the dbt executable to be installed on your machine. | ||
|
||
If you're using the ``local`` mode, you should use the ``dbt_ls`` method. | ||
|
||
If you're using the ``docker`` or ``kubernetes`` modes, you should use either ``dbt_manifest`` or ``custom`` modes. | ||
|
||
|
||
``automatic`` | ||
------------- | ||
|
||
When you don't supply an argument to the ``load_mode`` parameter (or you supply the value ``"automatic"``), Cosmos will attempt the other methods in order: | ||
|
||
1. Use a pre-existing ``manifest.json`` file (``dbt_manifest``) | ||
2. Try to generate a ``manifest.json`` file from your dbt project (``dbt_ls``) | ||
3. Use Cosmos' dbt parser (``custom``) | ||
|
||
To use this method, you don't need to supply any additional config. This is the default. | ||
|
||
``dbt_manifest`` | ||
---------------- | ||
|
||
If you already have a ``manifest.json`` file created by dbt, Cosmos will parse the manifest to generate your DAG. | ||
|
||
You can supply a ``manifest_path`` parameter on the DbtDag / DbtTaskGroup with a path to a ``manifest.json`` file. | ||
|
||
To use this: | ||
|
||
.. code-block:: python | ||
DbtDag( | ||
project_config=ProjectConfig( | ||
manifest_path="/path/to/manifest.json", | ||
), | ||
render_config=RenderConfig( | ||
load_mode=LoadMode.DBT_MANIFEST, | ||
) | ||
# ..., | ||
) | ||
``dbt_ls`` | ||
---------- | ||
|
||
.. note:: | ||
|
||
This only works for the ``local`` execution mode. | ||
|
||
If you don't have a ``manifest.json`` file, Cosmos will attempt to generate one from your dbt project. It does this by running ``dbt ls`` and parsing the output. | ||
|
||
When Cosmos runs ``dbt ls``, it also passes your ``select`` and ``exclude`` arguments to the command. This means that Cosmos will only generate a manifest for the models you want to run. | ||
|
||
To use this: | ||
|
||
.. code-block:: python | ||
DbtDag( | ||
render_config=RenderConfig( | ||
load_mode=LoadMode.DBT_LS, | ||
) | ||
# ..., | ||
) | ||
``custom`` | ||
---------- | ||
|
||
If the above methods fail, Cosmos will default to using its own dbt parser. This parser is not as robust as dbt's, so it's recommended that you use one of the above methods if possible. | ||
|
||
The following are known limitations of the custom parser: | ||
|
||
- it does not read from the ``dbt_project.yml`` file | ||
- it does not parse Python files or models | ||
|
||
To use this: | ||
|
||
.. code-block:: python | ||
DbtDag( | ||
render_config=RenderConfig( | ||
load_mode=LoadMode.CUSTOM, | ||
) | ||
# ..., | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Profile Config | ||
================ | ||
|
||
Cosmos has multiple methods for supplying profiles. For more information, click on the Profiles tab on the top navbar. |
Oops, something went wrong.