Configure task log collection and exporting to ElasticSearch
Airflow task logs are stored in a logging backend to ensure you can access them after your Pods terminate. By default, Astronomer uses Fluentd to collect task logs and export them to an ElasticSearch instance.
You can configure how Astronomer collects Deployment task logs and exports them to ElasticSearch. The following are the supported methods for exporting task logs to ElasticSearch:
- Using a Fluentd Daemonset pod on each Kubernetes node in your cluster.
- Using container sidecars for Deployment components.
Export task logs using a Fluentd DaemonSet
By default, Astronomer Software uses a Fluentd DaemonSet to aggregate task logs. The is the workflow for the default implementation:
- Deployments write task logs to stdout.
- Kubernetes takes the output from stdout and writes it to the Deployment’s node.
- A Fluentd pod reads logs from the node and forwards them to ElasticSearch.
This implementation is recommended for organizations that:
- Run longer tasks using Celery executor.
- Run Astronomer Software in a dedicated cluster.
- Run privileged containers in a cluster with a ClusterRole.
This approach is not suited for organizations that run many small tasks using the Kubernetes executor. Because task logs exist only for the lifetime of the pod, your pods running small tasks might complete before Fluentd can collect their task logs.
Export logs using container sidecars
You can use a logging sidecar container to collect and export logs. In this implementation:
- Each container running an Airflow component for a Deployment receives its own Vector sidecar.
- Task logs are written to a shared directory.
- The Vector sidecar reads logs from the shared directory and writes them to ElasticSearch.
This implementation is recommended for organizations that:
- Run Astronomer Software in a multi-tenant cluster, where security is a concern.
- Use the KubernetesExecutor to run many short-lived tasks, which requires improved reliability.
Configure logging sidecars
-
Retrieve your
values.yaml
file. See Apply a config change. -
Add the following entry to your
values.yaml
file:If you’re migrating from Fluentd, additionally set the following configuration so that Astronomer Software can retain logs:
-
Push the configuration change. See Apply a config change.
To revert to the default behavior and export task logs using a Fluentd Daemonset, remove this configuration from your values.yaml
file and reapply it.
Customize Vector logging sidecars
You can customize the default Astronomer Vector logging sidecar to have different transformations and sinks based on your team’s requirements. This is useful if you want to annotate, otherwise customize, or filter your logs before sending them to your logging platform.
-
Add the following line to your
values.yaml
file: -
Push the configuration change to your cluster. See Apply a config change.
-
Create a custom vector configuration
yaml
file to change how and where sidecars forward your logs. The following examples are template configurations for each commonly used external logging service. For the complete default logging sidecar configmap, see the Astronomer GitHub.
Elasticsearch
Honeycomb
Datadog
-
Run the following command to add the configuration file to your cluster as a Kubernetes secret:
-
Run the following command to annotate the secret so that it’s automatically applied to all new Deployments:
-
Run the following command to sync existing Deployments with the new configuration:
Use an external Elasticsearch instance for Airflow task log management
Add Airflow task logs from your Astronomer Deployment to an existing Elasticsearch instance on Elastic Cloud to centralize log management and analysis. Centralized log management allows you to quickly identify, troubleshoot, and resolve task failure issues. Although these examples use Elastic Cloud, you can also use AWS Managed OpenSearch Service or any other elastic service (managed or hosted). With an external Elasticsearch instance configured for Astronomer Software, you can see the logs in your Elasticsearch instance and browse the logs from the Software UI.
Create an Elastic Deployment and endpoint
- In your browser, go to
https://cloud.elastic.co/
and create a new Elastic Cloud deployment. See Create a deployment. - Copy and save your Elastic Cloud deployment credentials when the Save the deployment credentials screen appears.
- On the Elastic dashboard, click the Gear icon for your Deployment.
-
Click Copy endpoint next to Elasticsearch.
-
Optional. Test the Elastic Cloud deployment endpoint:
- Open a new browser window, paste the endpoint you copied in step 4 in the Address bar, and then press Enter.
- Enter the username and password you copied in step 2 and click Sign in. Output similar to the following appears:
Save your Elastic Cloud deployment credentials
After you’ve created an Elastic deployment and endpoint, you have two options to store your Elastic deployment credentials. You can store the credentials in your Astronomer Software helm values, or for greater security, as a secret in your Astronomer Software Kubernetes cluster. For additional information about adding an Astronomer Software configuration change, see Apply a config change.
values.yaml
Kubernetes secret
- Run the following command to base64 encode your Elastic Cloud deployment credentials:
- Add the following entry to your
values.yaml
file:
- Add the following entry to your
values.yaml
file to disable internal logging:
- Run the following command to upgrade the Astronomer Software release version in the
values.yaml
file:
View Airflow task logs in Elastic
- On the Elastic dashboard in the Elasticsearch Service area, click the Deployment name.
-
Click Menu > Discover. The Create index pattern screen appears.
-
Enter
fluentd.*
, orvector.*
if you use Vector Sidecar Logging. In the Name field, enter@timestamp
in the Timestamp field, and then click Create index pattern. -
Click Menu > Dashboard to view all of the Airflow task logs for your Deployment on Astronomer.