Skip to content

Commit 70f05ac

Browse files
authored
Add log_id field to log lines on ES handler (#10411)
* Add `log_id` field to log lines on ES handler * Add `offset` field to log lines on ES handler it will be set to the epoch timestamp in nanoseconds (this will just be used for ordering log lines when displayed in the webserver UI). * Update UPDATING.md With information regarding log_id and offset fields in JSON log lines written to stdout
1 parent cc551ba commit 70f05ac

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

UPDATING.md

+14
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,20 @@ The following configurations have been moved from `[core]` to the new `[logging]
518518
* `dag_processor_manager_log_location`
519519
* `task_log_reader`
520520

521+
#### Changes to Elasticsearch logging provider
522+
523+
When JSON output to stdout is enabled, log lines will now contain the `log_id` & `offset` fields, this should make reading task logs from elasticsearch on the webserver work out of the box. Example configuration:
524+
```ini
525+
[logging]
526+
remote_logging = True
527+
[elasticsearch]
528+
host = http://es-host:9200
529+
write_stdout = True
530+
json_format = True
531+
```
532+
533+
Note that the webserver expects the log line data itself to be present in the `message` field of the document.
534+
521535
#### Remove gcp_service_account_keys option in airflow.cfg file
522536

523537
This option has been removed because it is no longer supported by the Google Kubernetes Engine. The new

airflow/providers/elasticsearch/log/es_task_handler.py

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import logging
2020
import sys
2121
from datetime import datetime
22+
from time import time
2223
from typing import Optional, Tuple
2324
from urllib.parse import quote
2425

@@ -224,6 +225,8 @@ def set_context(self, ti: TaskInstance) -> None:
224225
'task_id': str(ti.task_id),
225226
'execution_date': self._clean_execution_date(ti.execution_date),
226227
'try_number': str(ti.try_number),
228+
'log_id': self._render_log_id(ti, ti.try_number),
229+
'offset': int(time() * (10 ** 9)),
227230
},
228231
)
229232

0 commit comments

Comments
 (0)