apache-airflow-providers-elasticsearch 5.4.0rc2__tar.gz → 5.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (12) hide show
  1. {apache_airflow_providers_elasticsearch-5.4.0rc2 → apache_airflow_providers_elasticsearch-5.4.1}/PKG-INFO +8 -8
  2. {apache_airflow_providers_elasticsearch-5.4.0rc2 → apache_airflow_providers_elasticsearch-5.4.1}/README.rst +3 -3
  3. {apache_airflow_providers_elasticsearch-5.4.0rc2 → apache_airflow_providers_elasticsearch-5.4.1}/airflow/providers/elasticsearch/__init__.py +3 -6
  4. {apache_airflow_providers_elasticsearch-5.4.0rc2 → apache_airflow_providers_elasticsearch-5.4.1}/airflow/providers/elasticsearch/get_provider_info.py +10 -2
  5. {apache_airflow_providers_elasticsearch-5.4.0rc2 → apache_airflow_providers_elasticsearch-5.4.1}/airflow/providers/elasticsearch/log/es_task_handler.py +25 -7
  6. {apache_airflow_providers_elasticsearch-5.4.0rc2 → apache_airflow_providers_elasticsearch-5.4.1}/pyproject.toml +5 -5
  7. {apache_airflow_providers_elasticsearch-5.4.0rc2 → apache_airflow_providers_elasticsearch-5.4.1}/airflow/providers/elasticsearch/LICENSE +0 -0
  8. {apache_airflow_providers_elasticsearch-5.4.0rc2 → apache_airflow_providers_elasticsearch-5.4.1}/airflow/providers/elasticsearch/hooks/__init__.py +0 -0
  9. {apache_airflow_providers_elasticsearch-5.4.0rc2 → apache_airflow_providers_elasticsearch-5.4.1}/airflow/providers/elasticsearch/hooks/elasticsearch.py +0 -0
  10. {apache_airflow_providers_elasticsearch-5.4.0rc2 → apache_airflow_providers_elasticsearch-5.4.1}/airflow/providers/elasticsearch/log/__init__.py +0 -0
  11. {apache_airflow_providers_elasticsearch-5.4.0rc2 → apache_airflow_providers_elasticsearch-5.4.1}/airflow/providers/elasticsearch/log/es_json_formatter.py +0 -0
  12. {apache_airflow_providers_elasticsearch-5.4.0rc2 → apache_airflow_providers_elasticsearch-5.4.1}/airflow/providers/elasticsearch/log/es_response.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: apache-airflow-providers-elasticsearch
3
- Version: 5.4.0rc2
3
+ Version: 5.4.1
4
4
  Summary: Provider package apache-airflow-providers-elasticsearch for Apache Airflow
5
5
  Keywords: airflow-provider,elasticsearch,airflow,integration
6
6
  Author-email: Apache Software Foundation <dev@airflow.apache.org>
@@ -21,13 +21,13 @@ Classifier: Programming Language :: Python :: 3.10
21
21
  Classifier: Programming Language :: Python :: 3.11
22
22
  Classifier: Programming Language :: Python :: 3.12
23
23
  Classifier: Topic :: System :: Monitoring
24
- Requires-Dist: apache-airflow-providers-common-sql>=1.3.1rc0
25
- Requires-Dist: apache-airflow>=2.7.0rc0
24
+ Requires-Dist: apache-airflow-providers-common-sql>=1.3.1
25
+ Requires-Dist: apache-airflow>=2.7.0
26
26
  Requires-Dist: elasticsearch>=8.10,<9
27
27
  Requires-Dist: apache-airflow-providers-common-sql ; extra == "common.sql"
28
28
  Project-URL: Bug Tracker, https://github.com/apache/airflow/issues
29
- Project-URL: Changelog, https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.0/changelog.html
30
- Project-URL: Documentation, https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.0
29
+ Project-URL: Changelog, https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.1/changelog.html
30
+ Project-URL: Documentation, https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.1
31
31
  Project-URL: Slack Chat, https://s.apache.org/airflow-slack
32
32
  Project-URL: Source Code, https://github.com/apache/airflow
33
33
  Project-URL: Twitter, https://twitter.com/ApacheAirflow
@@ -78,7 +78,7 @@ Provides-Extra: common.sql
78
78
 
79
79
  Package ``apache-airflow-providers-elasticsearch``
80
80
 
81
- Release: ``5.4.0.rc2``
81
+ Release: ``5.4.1``
82
82
 
83
83
 
84
84
  `Elasticsearch <https://www.elastic.co/elasticsearch>`__
@@ -91,7 +91,7 @@ This is a provider package for ``elasticsearch`` provider. All classes for this
91
91
  are in ``airflow.providers.elasticsearch`` python package.
92
92
 
93
93
  You can find package information and changelog for the provider
94
- in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.0/>`_.
94
+ in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.1/>`_.
95
95
 
96
96
  Installation
97
97
  ------------
@@ -133,4 +133,4 @@ Dependent package
133
133
  ============================================================================================================ ==============
134
134
 
135
135
  The changelog for the provider package can be found in the
136
- `changelog <https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.0/changelog.html>`_.
136
+ `changelog <https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.1/changelog.html>`_.
@@ -42,7 +42,7 @@
42
42
 
43
43
  Package ``apache-airflow-providers-elasticsearch``
44
44
 
45
- Release: ``5.4.0.rc2``
45
+ Release: ``5.4.1``
46
46
 
47
47
 
48
48
  `Elasticsearch <https://www.elastic.co/elasticsearch>`__
@@ -55,7 +55,7 @@ This is a provider package for ``elasticsearch`` provider. All classes for this
55
55
  are in ``airflow.providers.elasticsearch`` python package.
56
56
 
57
57
  You can find package information and changelog for the provider
58
- in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.0/>`_.
58
+ in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.1/>`_.
59
59
 
60
60
  Installation
61
61
  ------------
@@ -97,4 +97,4 @@ Dependent package
97
97
  ============================================================================================================ ==============
98
98
 
99
99
  The changelog for the provider package can be found in the
100
- `changelog <https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.0/changelog.html>`_.
100
+ `changelog <https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.1/changelog.html>`_.
@@ -25,14 +25,11 @@ from __future__ import annotations
25
25
 
26
26
  import packaging.version
27
27
 
28
- __all__ = ["__version__"]
28
+ from airflow import __version__ as airflow_version
29
29
 
30
- __version__ = "5.4.0"
30
+ __all__ = ["__version__"]
31
31
 
32
- try:
33
- from airflow import __version__ as airflow_version
34
- except ImportError:
35
- from airflow.version import version as airflow_version
32
+ __version__ = "5.4.1"
36
33
 
37
34
  if packaging.version.parse(packaging.version.parse(airflow_version).base_version) < packaging.version.parse(
38
35
  "2.7.0"
@@ -28,8 +28,9 @@ def get_provider_info():
28
28
  "name": "Elasticsearch",
29
29
  "description": "`Elasticsearch <https://www.elastic.co/elasticsearch>`__\n",
30
30
  "state": "ready",
31
- "source-date-epoch": 1714476311,
31
+ "source-date-epoch": 1716287658,
32
32
  "versions": [
33
+ "5.4.1",
33
34
  "5.4.0",
34
35
  "5.3.4",
35
36
  "5.3.3",
@@ -163,12 +164,19 @@ def get_provider_info():
163
164
  "default": "offset",
164
165
  },
165
166
  "index_patterns": {
166
- "description": "Comma separated list of index patterns to use when searching for logs (default: `_all`).\n",
167
+ "description": "Comma separated list of index patterns to use when searching for logs (default: `_all`).\nThe index_patterns_callable takes precedence over this.\n",
167
168
  "version_added": "2.6.0",
168
169
  "type": "string",
169
170
  "example": "something-*",
170
171
  "default": "_all",
171
172
  },
173
+ "index_patterns_callable": {
174
+ "description": "A string representing the full path to the Python callable path which accept TI object and\nreturn comma separated list of index patterns. This will takes precedence over index_patterns.\n",
175
+ "version_added": "5.5.0",
176
+ "type": "string",
177
+ "example": "module.callable",
178
+ "default": "",
179
+ },
172
180
  },
173
181
  },
174
182
  "elasticsearch_configs": {
@@ -41,6 +41,7 @@ from airflow.providers.elasticsearch.log.es_response import ElasticSearchRespons
41
41
  from airflow.utils import timezone
42
42
  from airflow.utils.log.file_task_handler import FileTaskHandler
43
43
  from airflow.utils.log.logging_mixin import ExternalLoggingMixin, LoggingMixin
44
+ from airflow.utils.module_loading import import_string
44
45
  from airflow.utils.session import create_session
45
46
 
46
47
  if TYPE_CHECKING:
@@ -108,7 +109,7 @@ def _ensure_ti(ti: TaskInstanceKey | TaskInstance, session) -> TaskInstance:
108
109
  .one_or_none()
109
110
  )
110
111
  if isinstance(val, TaskInstance):
111
- val._try_number = ti.try_number
112
+ val.try_number = ti.try_number
112
113
  return val
113
114
  else:
114
115
  raise AirflowException(f"Could not find TaskInstance for {ti}")
@@ -152,7 +153,8 @@ class ElasticsearchTaskHandler(FileTaskHandler, ExternalLoggingMixin, LoggingMix
152
153
  offset_field: str = "offset",
153
154
  host: str = "http://localhost:9200",
154
155
  frontend: str = "localhost:5601",
155
- index_patterns: str | None = conf.get("elasticsearch", "index_patterns", fallback="_all"),
156
+ index_patterns: str = conf.get("elasticsearch", "index_patterns"),
157
+ index_patterns_callable: str = conf.get("elasticsearch", "index_patterns_callable", fallback=""),
156
158
  es_kwargs: dict | None | Literal["default_es_kwargs"] = "default_es_kwargs",
157
159
  *,
158
160
  filename_template: str | None = None,
@@ -184,6 +186,7 @@ class ElasticsearchTaskHandler(FileTaskHandler, ExternalLoggingMixin, LoggingMix
184
186
  self.host_field = host_field
185
187
  self.offset_field = offset_field
186
188
  self.index_patterns = index_patterns
189
+ self.index_patterns_callable = index_patterns_callable
187
190
  self.context_set = False
188
191
 
189
192
  self.formatter: logging.Formatter
@@ -213,6 +216,19 @@ class ElasticsearchTaskHandler(FileTaskHandler, ExternalLoggingMixin, LoggingMix
213
216
 
214
217
  return host
215
218
 
219
+ def _get_index_patterns(self, ti: TaskInstance | None) -> str:
220
+ """
221
+ Get index patterns by calling index_patterns_callable, if provided, or the configured index_patterns.
222
+
223
+ :param ti: A TaskInstance object or None.
224
+ """
225
+ if self.index_patterns_callable:
226
+ self.log.debug("Using index_patterns_callable: %s", self.index_patterns_callable)
227
+ index_pattern_callable_obj = import_string(self.index_patterns_callable)
228
+ return index_pattern_callable_obj(ti)
229
+ self.log.debug("Using index_patterns: %s", self.index_patterns)
230
+ return self.index_patterns
231
+
216
232
  def _render_log_id(self, ti: TaskInstance | TaskInstanceKey, try_number: int) -> str:
217
233
  from airflow.models.taskinstance import TaskInstanceKey
218
234
 
@@ -302,7 +318,7 @@ class ElasticsearchTaskHandler(FileTaskHandler, ExternalLoggingMixin, LoggingMix
302
318
 
303
319
  offset = metadata["offset"]
304
320
  log_id = self._render_log_id(ti, try_number)
305
- response = self._es_read(log_id, offset)
321
+ response = self._es_read(log_id, offset, ti)
306
322
  if response is not None and response.hits:
307
323
  logs_by_host = self._group_logs_by_host(response)
308
324
  next_offset = attrgetter(self.offset_field)(response[-1])
@@ -372,12 +388,13 @@ class ElasticsearchTaskHandler(FileTaskHandler, ExternalLoggingMixin, LoggingMix
372
388
  # Just a safe-guard to preserve backwards-compatibility
373
389
  return hit.message
374
390
 
375
- def _es_read(self, log_id: str, offset: int | str) -> ElasticSearchResponse | None:
391
+ def _es_read(self, log_id: str, offset: int | str, ti: TaskInstance) -> ElasticSearchResponse | None:
376
392
  """
377
393
  Return the logs matching log_id in Elasticsearch and next offset or ''.
378
394
 
379
395
  :param log_id: the log_id of the log to read.
380
396
  :param offset: the offset start to read log from.
397
+ :param ti: the task instance object
381
398
 
382
399
  :meta private:
383
400
  """
@@ -388,16 +405,17 @@ class ElasticsearchTaskHandler(FileTaskHandler, ExternalLoggingMixin, LoggingMix
388
405
  }
389
406
  }
390
407
 
408
+ index_patterns = self._get_index_patterns(ti)
391
409
  try:
392
- max_log_line = self.client.count(index=self.index_patterns, query=query)["count"] # type: ignore
410
+ max_log_line = self.client.count(index=index_patterns, query=query)["count"] # type: ignore
393
411
  except NotFoundError as e:
394
- self.log.exception("The target index pattern %s does not exist", self.index_patterns)
412
+ self.log.exception("The target index pattern %s does not exist", index_patterns)
395
413
  raise e
396
414
 
397
415
  if max_log_line != 0:
398
416
  try:
399
417
  res = self.client.search(
400
- index=self.index_patterns,
418
+ index=index_patterns,
401
419
  query=query,
402
420
  sort=[self.offset_field],
403
421
  size=self.MAX_LINE_PER_PAGE,
@@ -28,7 +28,7 @@ build-backend = "flit_core.buildapi"
28
28
 
29
29
  [project]
30
30
  name = "apache-airflow-providers-elasticsearch"
31
- version = "5.4.0.rc2"
31
+ version = "5.4.1"
32
32
  description = "Provider package apache-airflow-providers-elasticsearch for Apache Airflow"
33
33
  readme = "README.rst"
34
34
  authors = [
@@ -56,14 +56,14 @@ classifiers = [
56
56
  ]
57
57
  requires-python = "~=3.8"
58
58
  dependencies = [
59
- "apache-airflow-providers-common-sql>=1.3.1rc0",
60
- "apache-airflow>=2.7.0rc0",
59
+ "apache-airflow-providers-common-sql>=1.3.1",
60
+ "apache-airflow>=2.7.0",
61
61
  "elasticsearch>=8.10,<9",
62
62
  ]
63
63
 
64
64
  [project.urls]
65
- "Documentation" = "https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.0"
66
- "Changelog" = "https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.0/changelog.html"
65
+ "Documentation" = "https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.1"
66
+ "Changelog" = "https://airflow.apache.org/docs/apache-airflow-providers-elasticsearch/5.4.1/changelog.html"
67
67
  "Bug Tracker" = "https://github.com/apache/airflow/issues"
68
68
  "Source Code" = "https://github.com/apache/airflow"
69
69
  "Slack Chat" = "https://s.apache.org/airflow-slack"