Skip to main content
The APC API GraphQL query, 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.cleanupAirflowDb section of your values.yaml file.
  • Manual Cleanup: The APC 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

  1. You must provision a GCP Service Account with appropriate read/write permissions to your bucket. Export these credentials as a JSON file.
  2. 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:
You use this Kubernetes secret to configure 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.
  1. You must provision a GCP Service Account with appropriate read/write permissions to your bucket. Export these credentials as a JSON file.
  2. Create an Airflow connection using these credentials. See Airflow documentation to learn how to configure your connection.
This strategy isn’t secure because the secret is in base64 encoded format in your config.yaml, which can be decoded.
You can use this connection as your connectionId when you make API queries as the cleanup job trigger, but it isn’t 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 APC API config section of your values.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.
You can configure the task metadata cleanup in different sections of the Helm chart, depending on your scope and use case. However, you can’t have cleanupAirflowDb.enabled: true enabled at multiple levels. You can only have the job enabled one of the three scope levels.
The env.name value must match the secret name that you configured for providerEnvSecretName in your values.yaml file.

Configure the provider secret in APC

Configure the storage provider secret in a Deployment

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 your cleanupAirflowDb configuration. These configurations become the new defaults for your cleanup job if you don’t 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.
You can override these resource definitions, or configure resources if you don’t define any, by using resourceSpec in an API query. See Scenario 4: Configure custom Pod Resources.

Step 6: Apply your configuration

Apply your platform configuration changes to enable cleanup jobs and to set your cronjob schedule.
If you want to upgrade all Deployments while updating your configuration, you can set astronomer.houston.upgradeDeployments.enabled to true.

Step 7: (Optional) Manually trigger the cleanup job

The following configuration enables you to trigger a cleanup job manually using an APC 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 the values.yaml configuration. This means you must specify the Deployment or Workspace in your query that you want to clean up.
Restrict cleanup to manual-only triggersIn Step 3, you set an automatic schedule for your platform to clean up task metadata by setting the astronomer.houston.cleanupAirflowDb.enabled configuration to true. To enable only triggering cleanup jobs manually, you must instead set astronomer.houston.cleanupAirflowDb.enabled to false. Manually triggered cleanup jobs require you to use an APC API query and specify the Deployments where you want to archive metadata.
The following examples shows different mutations that you can use depending on your needs. See APC API examples for all examples and scenarios that you can use to work with the APC API.

APC API parameters

Set dryRun: true to test this feature without deleting any data. When dry runs are enabled, the cleanup job will only print the data that it plans to modify in the serial output of the webserver Pod. To view the dryRun events of the cleanup job, check the logs of your webserver Pod for each Deployment.
The following examples show different queries you can use depending on your needs. For the full parameter reference, see Clean up and delete task metadata.

Clean up Deployments per Workspace

Query variables to clean up all Deployments older than 1 day within a Workspace that uses GCP as a cloud provider:

Clean up specific Deployments

Query variables to clean up specific Deployments older than 1 day within a Workspace:

Clean up using an Airflow connection ID

Requires configuring an Airflow Connection ID, connectionId, from the Airflow UI or CLI.
Query variables to clean up Deployments and export the cleanup logs to the storage provider configured in an Airflow Connection:

Configure custom Pod resources

If you don’t configure a default Pod CPU or memory resource amount, or want to override one, make a query that sets resourceSpec:
Query variables that configure resource requests and limits for the cleanup run:
You can also find Workspace IDs with the sysWorkspaces APC API query.

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.

UI access

Go to the Logs tab in your Deployments page and select the AirflowMetaCleanup tab to access the logs. Sidecar logging and DaemonSet logging are both supported.