Skip to content

Share Elasticsearch and OpenSearch log response parsing in a shared library - #72310

Closed
Owen-CH-Leung wants to merge 3 commits into
apache:mainfrom
Owen-CH-Leung:refactor-search-provider
Closed

Owen-CH-Leung wants to merge 3 commits into
apache:mainfrom
Owen-CH-Leung:refactor-search-provider

Conversation

@Owen-CH-Leung

@Owen-CH-Leung Owen-CH-Leung commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

elasticsearch and opensearch each carried a near-identical copy of the search
response 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/search as apache-airflow-shared-search. It is symlinked into each
provider's _shared/ directory during development and vendored into the wheel and
sdist 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; ElasticSearchResponse and
    OpensearchResponse are preserved so existing import paths keep working.
  • es_json_formatter.py / os_json_formatter.py — now compose the shared ISO8601Formatter.
  • Both providers move from flit_core to hatchling (flit has no force-include) and
    declare pendulum>=3.1.0, which they relied on transitively before.
  • provider_distributions.py — breeze passed -t custom to hatch build for every
    hatchling provider; only the three that ship a hatch_build.py have that target, so
    the flag is now gated on the script existing.

No behaviour change. The provider response and formatter tests are unchanged from main
and still pass; the behavioural suite moved to shared/search/tests and was extended to
cover resolve_nested, slice access, fields merging and the AttributeError →
TypeError translation.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5)

Generated-by: Claude Code (Opus 5) following the guidelines

@Owen-CH-Leung Owen-CH-Leung changed the title refactor(search-lib): create base search library for opensearch and e… Extract shared Elasticsearch/OpenSearch log parsing into common-search provider Aug 31, 2026
@Owen-CH-Leung
Owen-CH-Leung force-pushed the refactor-search-provider branch 3 times, most recently from b3b65f4 to 51e1408 Compare September 6, 2026 00:42
@ashb

ashb commented Sep 10, 2026

Copy link
Copy Markdown
Member

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.

@Owen-CH-Leung
Owen-CH-Leung force-pushed the refactor-search-provider branch from 51e1408 to 7ff614d Compare September 12, 2026 14:11
@Owen-CH-Leung Owen-CH-Leung changed the title Extract shared Elasticsearch/OpenSearch log parsing into common-search provider Share Elasticsearch and OpenSearch log response parsing in a shared library Sep 13, 2026
@Owen-CH-Leung
Owen-CH-Leung force-pushed the refactor-search-provider branch 2 times, most recently from 7d1cd3c to fbee5a0 Compare September 13, 2026 01:41
@Owen-CH-Leung
Owen-CH-Leung marked this pull request as ready for review September 13, 2026 10:47
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

uv.lock on main just moved via #74132 ("Install ibmmq from a wheel in IBM MQ lowest-dependency tests"), commit c011b59 and this PR currently conflicts.

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-lease

Automated nudge — ignore if you're not ready to rebase. This comment is updated in place on future uv.lock bumps.

…ibrary

Both providers carried byte-identical copies that had already drifted, so
every fix had to be written twice.
@Owen-CH-Leung
Owen-CH-Leung force-pushed the refactor-search-provider branch from 229fc25 to 24730c7 Compare September 18, 2026 01:11
@Owen-CH-Leung

Copy link
Copy Markdown
Contributor Author

@ashb Can I ask for your review again ?

@subhramit subhramit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not introduced in this PR, but wouldn't this always be False?
I think this should be:

Suggested change
if isinstance(val, slice):
if isinstance(k, slice):

otherwise the slice will return a plain list instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be fixed in #73725

Comment on lines +115 to +120
def __init__(self, document):
data = {}
if "_source" in document:
data = document["_source"]
if "fields" in document:
data.update(document["fields"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also not introduced by the PR, but this changes the caller's dict. Perhaps a good opportunity to fix.

Suggested change
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also be fixed in #73725

Comment on lines +182 to +184
{% if SHARED_DISTRIBUTIONS %}
"provider.yaml",
{% endif %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is provider.yaml tied to SHARED_DISTRIBUTIONS? It does not seem to be related.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment on lines -19 to +20
from airflow.providers.opensearch.version_compat import AIRFLOW_V_3_3_PLUS
from airflow.providers.opensearch._shared.search.formatter import ISO8601Formatter

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants