Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-https elasticsearch external links #16489

Merged
merged 1 commit into from Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions airflow/config_templates/config.yml
Expand Up @@ -1973,10 +1973,11 @@
description: |
Qualified URL for an elasticsearch frontend (like Kibana) with a template argument for log_id
Code will construct log_id using the log_id template from the argument above.
NOTE: The code will prefix the https:// automatically, don't include that here.
NOTE: scheme will default to https if one if not provided
version_added: 1.10.4
type: string
example: ~
example: "http://localhost:5601/app/kibana#/discover\
?_a=(columns:!(message),query:(language:kuery,query:'log_id: \"{log_id}\"'),sort:!(log.offset,asc))"
default: ""
- name: write_stdout
description: |
Expand Down
3 changes: 2 additions & 1 deletion airflow/config_templates/default_airflow.cfg
Expand Up @@ -980,7 +980,8 @@ end_of_log_mark = end_of_log

# Qualified URL for an elasticsearch frontend (like Kibana) with a template argument for log_id
# Code will construct log_id using the log_id template from the argument above.
# NOTE: The code will prefix the https:// automatically, don't include that here.
# NOTE: scheme will default to https if one if not provided
# Example: frontend = http://localhost:5601/app/kibana#/discover?_a=(columns:!(message),query:(language:kuery,query:'log_id: "{{log_id}}"'),sort:!(log.offset,asc))
frontend =

# Write the task logs to the stdout of the worker, rather than the default files
Expand Down
3 changes: 2 additions & 1 deletion airflow/providers/elasticsearch/log/es_task_handler.py
Expand Up @@ -336,7 +336,8 @@ def get_external_log_url(self, task_instance: TaskInstance, try_number: int) ->
:rtype: str
"""
log_id = self._render_log_id(task_instance, try_number)
return 'https://' + self.frontend.format(log_id=quote(log_id))
scheme = '' if '://' in self.frontend else 'https://'
return scheme + self.frontend.format(log_id=quote(log_id))

@property
def supports_external_link(self) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion docs/apache-airflow-providers-elasticsearch/logging.rst
Expand Up @@ -98,5 +98,5 @@ To enable it, ``airflow.cfg`` must be configured as in the example below. Note t
[elasticsearch]
# Qualified URL for an elasticsearch frontend (like Kibana) with a template argument for log_id
# Code will construct log_id using the log_id template from the argument above.
# NOTE: The code will prefix the https:// automatically, don't include that here.
# NOTE: scheme will default to https if one if not provided
frontend = <host_port>/{log_id}
4 changes: 4 additions & 0 deletions tests/providers/elasticsearch/log/test_es_task_handler.py
Expand Up @@ -413,6 +413,10 @@ def test_clean_execution_date(self):
(False, 'localhost:5601/{log_id}', 'https://localhost:5601/' + quote(LOG_ID)),
# Ignore template if "{log_id}"" is missing in the URL
(False, 'localhost:5601', 'https://localhost:5601'),
# scheme handling
(False, 'https://localhost:5601/path/{log_id}', 'https://localhost:5601/path/' + quote(LOG_ID)),
(False, 'http://localhost:5601/path/{log_id}', 'http://localhost:5601/path/' + quote(LOG_ID)),
(False, 'other://localhost:5601/path/{log_id}', 'other://localhost:5601/path/' + quote(LOG_ID)),
]
)
def test_get_external_log_url(self, json_format, es_frontend, expected_url):
Expand Down