cleanupAirflowDb, triggers the Airflow metadata cleanup job. You can run a cleanup job to automatically delete task and Dag metadata from your Deployment. This job runs an Astronomer custom cleanup script for all of your Deployments and exports the results in a CSV-formatted file structure to your configured external storage service.
You can enable this feature by setting the config flag in astronomer.houston.cleanupAirflowDb.enabled to true in your values.yaml file.
There are two ways to use this feature:
- Scheduled Cleanup: You can configure a Kubernetes CronJob to run the cleanup job at regular intervals by defining the schedule and job parameters in the
astronomer.houston.cleanupAirflowDbsection of yourvalues.yamlfile. - Manual Cleanup: The Houston API GraphQL query,
cleanupAirflowDb, manually triggers the Airflow metadata cleanup job for immediate execution.
The cleanup job deletes any data that’s older than the number of days specified in your
olderThan configuration. Ensure that none of your historical data is required to run current Dags or tasks before enabling this feature.Prerequisites
- System admin user privileges
- External storage credentials that allow read/write permissions to your storage
- (AWS Cloud Provider) The AWS CLI
Step 1: Configure your external storage credentials
- Google Cloud Storage
- AWS
- You must provision a GCP Service Account with appropriate read/write permissions to your bucket. Export these credentials as a JSON file.
-
Create a Kubernetes secret in your Astronomer platform namespace with a name such as
astronomer-gcs-keyfile. Then, run the following commands to update your environment:
providerEnvSecretName when you configure the cleanup job and env.name when you set the storage provider secret.(Optional) Configure a connection ID
If you want to run jobs for specific Deployments or within a Workspace or run manually triggered jobs using an API query, you can choose to configure an Airflow connection to your external storage service so that it can be stored as an environment variable. You must use the service account credentials to authenticate to your service when configuring your connection.- Google Cloud Storage
- AWS
- You must provision a GCP Service Account with appropriate read/write permissions to your bucket. Export these credentials as a JSON file.
- Create an Airflow connection using these credentials. See Airflow documentation to learn how to configure your connection.
connectionId when you make API queries as the cleanupjob trigger, but it is not required.
Step 3: Configure the cleanup job
The cronjob configuration provides the default values that your cleanup job uses whether you run a scheduled or manual cleanup job. The following example shows the automatic cleanup job configuration that runs at 5:23AM and cleans up Deployments that are more than one year old.Step 4: Set the storage provider secret
In the Houston config section of yourvalues.yaml file, set the storage provider secret that you configured in Step 1, so that the cleanup job can export your cleanup results to your cloud storage.
The env.name value must match the secret name that you configured for providerEnvSecretName in your values.yaml file.
Configure the provider secret in Houston
- Google Cloud Storage
- AWS
Configure the storage provider secret in a Deployment
- Google Cloud Storage
- AWS
Step 5: (Optional) Set container CPU and memory limits or requests
You can set limits and requests for CPU and Memory of the cleanup container by adding the following to yourcleanupAirflowDb configuration. These configurations become the new defaults for your cleanup job if you do not pass any additional configurations in your GraphQL mutation. Additionally, if you don’t use the manual trigger and instead use the cleanup cronjob, these resources also become the new default used when scheduling cleanup jobs.
Step 6: Apply your configuration
Apply your platform configuration changes to enable cleanup jobs and to set your cronjob schedule.Step 7: (Optional) Manually trigger the cleanup job
The following configuration enables you to trigger a cleanup job manually using a Houston API query. When you use the cleanup job in this way, the values you include in the query are used instead of the defaults set in thevalues.yaml configuration. This means you must specify the Deployment or Workspace in your query that you want to clean up.
Houston API Parameters
Scenario 1: Cleanup Deployments per Workspace
You can use the following query to clean up Deployments in a specific Workspace. Configure theworkspaceId parameter with the Workspace whose Deployments you want to clean up. You can also find Workspace IDs with the sysWorkspaces Houston API query.
cma40n66l000008l89nye86o1, that uses GCP as a cloud provider.
Scenario 2: Cleanup Deployments across your system
You can use the following query to clean up specific Deployments in a specific workspace. Configure theworkspaceId parameter with the Workspace and the deploymentIds with the specific Deployments.. You can also find Workspace IDs with the sysWorkspaces Houston API query.
cma42z570000008l8f6rpc72f.
Scenario 3: Clean up Deployment using Airflow connection ID
You can also both clean up all Deployments in a Workspace or specific Deployments and export the clean up logs to a storage provider configured in an Airflow Connection.connectionId.
Scenario 4: Configure custom Pod resources
If you do not configure a specific default Pod CPU or memory resource amount, or if you want to override a configuration, you can make a GraphQL query to set a user-defined resource configuration.Access your cleanup logs
You can access your cleanup logs through the UI or with your Pod logs.Pod Logs
You can access your Pod logs with vector sidecar logging or FluentD with<release-name>-meta-cleanup-job in the Airflow namespace.