airflow.providers.opensearch.log.os_task_handler¶
Attributes¶
Classes¶
OpensearchTaskHandler is a Python log handler that reads logs from OpenSearch. |
|
Convenience super-class to have a logger configured with the class name. |
Functions¶
|
Get item from obj but return default if not found. |
Module Contents¶
- airflow.providers.opensearch.log.os_task_handler.TASK_LOG_FIELDS = ['timestamp', 'event', 'level', 'chan', 'logger', 'error_detail', 'message', 'levelname'][source]¶
- airflow.providers.opensearch.log.os_task_handler.getattr_nested(obj, item, default)[source]¶
Get item from obj but return default if not found.
E.g. calling
getattr_nested(a, 'b.c', "NA")will returna.b.cif such a value exists, and “NA” otherwise.
- class airflow.providers.opensearch.log.os_task_handler.OpensearchTaskHandler(base_log_folder, end_of_log_mark, write_stdout, json_format, json_fields, host, port, username, password, write_to_opensearch=False, target_index='airflow-logs', host_field='host', offset_field='offset', index_patterns=conf.get('opensearch', 'index_patterns', fallback='_all'), index_patterns_callable=conf.get('opensearch', 'index_patterns_callable', fallback=''), log_id_template=conf.get('opensearch', 'log_id_template', fallback='') or '{dag_id}-{task_id}-{run_id}-{map_index}-{try_number}', os_kwargs='default_os_kwargs', max_bytes=0, backup_count=0, delay=False, **kwargs)[source]¶
Bases:
airflow.utils.log.file_task_handler.FileTaskHandler,airflow.utils.log.logging_mixin.ExternalLoggingMixin,airflow.utils.log.logging_mixin.LoggingMixinOpensearchTaskHandler is a Python log handler that reads logs from OpenSearch.
Airflow flushes task logs to local files. Additional software setup can then ship those logs to OpenSearch. On Airflow 3, this task handler also registers a matching
OpensearchRemoteLogIOso the new remote logging path can read from OpenSearch too. Airflow can also be configured to write task logs to OpenSearch directly. To enable this feature, setjson_formatandwrite_to_opensearchtoTrue.To efficiently query and sort OpenSearch results, this handler assumes each log message has a field log_id consists of ti primary keys: log_id = {dag_id}-{task_id}-{logical_date}-{try_number} Log messages with specific log_id are sorted based on offset, which is a unique integer indicates log message’s order. Timestamps here are unreliable because multiple log messages might have the same timestamp.
- Parameters:
base_log_folder (str) – Base folder to store logs locally.
end_of_log_mark (str) – A marker string to signify the end of logs.
write_stdout (bool) – Whether to also write logs to stdout.
json_format (bool) – Whether to format logs as JSON.
json_fields (str) – Comma-separated list of fields to include in the JSON log output.
host (str) – OpenSearch host name.
port (int | None) – OpenSearch port.
username (str) – Username for OpenSearch authentication.
password (str) – Password for OpenSearch authentication.
write_to_opensearch (bool) – Whether to write logs directly to OpenSearch.
target_index (str) – Name of the index to write to when direct OpenSearch writes are enabled.
host_field (str) – The field name for the host in the logs (default is “host”).
offset_field (str) – The field name for the log offset (default is “offset”).
index_patterns (str) – Index pattern or template for storing logs.
index_patterns_callable (str) – Callable that dynamically generates index patterns based on context.
os_kwargs (dict | None | Literal['default_os_kwargs']) – Additional OpenSearch client options. This can be set to “default_os_kwargs” to load the default configuration from Airflow’s settings.
- formatter: logging.Formatter[source]¶
- handler: logging.FileHandler | logging.StreamHandler | None = None[source]¶
- set_context(ti, *, identifier=None)[source]¶
Provide task_instance context to airflow task handler.
- Parameters:
ti (airflow.models.taskinstance.TaskInstance) – task instance object
identifier (str | None) – if set, identifies the Airflow component which is relaying logs from exceptional scenarios related to the task instance
- emit(record)[source]¶
Do whatever it takes to actually log the specified logging record.
This version is intended to be implemented by subclasses and so raises a NotImplementedError.
- close()[source]¶
Tidy up any resources used by the handler.
This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods.
- property supports_external_link: bool[source]¶
Whether we can support external links.
TODO: It should support frontend just like ElasticSearchTaskhandler.
- class airflow.providers.opensearch.log.os_task_handler.OpensearchRemoteLogIO(context=None)[source]¶
Bases:
airflow.utils.log.logging_mixin.LoggingMixinConvenience super-class to have a logger configured with the class name.
- base_log_folder: pathlib.Path[source]¶