Repository navigation
Share Elasticsearch and OpenSearch log response parsing in a shared library - #72310
Owen-CH-Leung wants to merge 3 commits into
Conversation
b3b65f4 to
51e1408
Compare
|
I'd rather we had a single dist rather than a common base + two identical almost-empty shim dist. Since for the bits we use they are 100% identical in behaviour I think. |
51e1408 to
7ff614d
Compare
7d1cd3c to
fbee5a0
Compare
|
Quickest fix: git fetch upstream main && git rebase upstream/main
rm uv.lock && uv lock
git add uv.lock && git rebase --continue
git push --force-with-leaseAutomated nudge — ignore if you're not ready to rebase. This comment is updated in place on future |
…ibrary Both providers carried byte-identical copies that had already drifted, so every fix had to be written twice.
229fc25 to
24730c7
Compare
|
@ashb Can I ask for your review again ? |
subhramit
left a comment
There was a problem hiding this comment.
Some observations (some linked to your changes, some existing)
| def __getitem__(self, k): | ||
| """Retrieve an item or a slice from the list. If the item is a dictionary, it is wrapped in an AttributeDict.""" | ||
| val = self._l_[k] | ||
| if isinstance(val, slice): |
There was a problem hiding this comment.
Not introduced in this PR, but wouldn't this always be False?
I think this should be:
| if isinstance(val, slice): | |
| if isinstance(k, slice): |
otherwise the slice will return a plain list instead.
There was a problem hiding this comment.
What, however, is introduced in this PR is test_slice_access_returns_plain_list which makes this bug the expected behavior. That would also need fixing.
| def __init__(self, document): | ||
| data = {} | ||
| if "_source" in document: | ||
| data = document["_source"] | ||
| if "fields" in document: | ||
| data.update(document["fields"]) |
There was a problem hiding this comment.
This is also not introduced by the PR, but this changes the caller's dict. Perhaps a good opportunity to fix.
| def __init__(self, document): | |
| data = {} | |
| if "_source" in document: | |
| data = document["_source"] | |
| if "fields" in document: | |
| data.update(document["fields"]) | |
| def __init__(self, document): | |
| data = dict(document.get("_source", {})) | |
| if "fields" in document: | |
| data.update(document["fields"]) |
Please also add a test for it.
| {% if SHARED_DISTRIBUTIONS %} | ||
| "provider.yaml", | ||
| {% endif %} |
There was a problem hiding this comment.
Why is provider.yaml tied to SHARED_DISTRIBUTIONS? It does not seem to be related.
There was a problem hiding this comment.
Ah I see. The flit providers (including elasticsearch and opensearch) have provider.yaml in the sdist, but that is never the case for hatchling providers.
Then can we use one rule for all hatchling providers? Either include provider.yaml always, or remove it for elasticsearch and opensearch too (if nothing reads it from the sdist).
| from airflow.providers.opensearch.version_compat import AIRFLOW_V_3_3_PLUS | ||
| from airflow.providers.opensearch._shared.search.formatter import ISO8601Formatter |
There was a problem hiding this comment.
I think (as per my IDE), both providers' AIRFLOW_V_3_3_PLUS in version_compat.py will now be unused?
SHould that then be cleaned up?
elasticsearchandopensearcheach carried a near-identical copy of the searchresponse wrappers and the log timestamp formatter. The copies had already
drifted, and every fix had to be written twice.
The shared code now lives in
shared/searchasapache-airflow-shared-search. It is symlinked into eachprovider's
_shared/directory during development and vendored into the wheel andsdist at build time, so both providers stay independently installable and releasable.
What changed
shared/search/— new private shared library (response.py,formatter.py) plus its tests.es_response.py/os_response.py— now thin re-exports;ElasticSearchResponseandOpensearchResponseare preserved so existing import paths keep working.es_json_formatter.py/os_json_formatter.py— now compose the sharedISO8601Formatter.flit_coretohatchling(flit has noforce-include) anddeclare
pendulum>=3.1.0, which they relied on transitively before.provider_distributions.py— breeze passed-t customtohatch buildfor everyhatchling provider; only the three that ship a
hatch_build.pyhave that target, sothe flag is now gated on the script existing.
No behaviour change. The provider response and formatter tests are unchanged from
mainand still pass; the behavioural suite moved to
shared/search/testsand was extended tocover
resolve_nested, slice access,fieldsmerging and theAttributeError→TypeErrortranslation.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5) following the guidelines