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

Updating ESApi class methods to use ES client calls instead of temporary wrapper methods #3110

Merged
merged 19 commits into from
Jan 28, 2025

Conversation

mattnowzari
Copy link
Contributor

@mattnowzari mattnowzari commented Jan 15, 2025

Closes #2964

This PR updates the few methods of class ESApi to utilize ES client methods instead of TemporaryConnectorAPIWrapper methods. This does not fully replace all of the methods of TemporaryConnectorAPIWrapper, as we are waiting on ES client v8.17.1 to support sync_job_claim and sync_job_update_stats API calls. This will be attended to post-8.17.1 release.

Checklists

Pre-Review Checklist

  • this PR does NOT contain credentials of any kind, such as API keys or username/passwords (double check config.yml.example)
  • this PR has a meaningful title
  • this PR links to all relevant github issues that it fixes or partially addresses
  • this PR has a thorough description
  • Covered the changes with automated tests
  • Tested the changes locally
  • Added a label for each target release version (example: v7.13.2, v7.14.0, v8.0.0)

@mattnowzari mattnowzari changed the title Updated some ESApi class methods to use ES client calls instead of temporary wrapper methods Updating ESApi class methods to use ES client calls instead of temporary wrapper methods Jan 17, 2025
@mattnowzari mattnowzari marked this pull request as ready for review January 23, 2025 18:07
@mattnowzari mattnowzari requested a review from a team as a code owner January 23, 2025 18:07
@@ -255,3 +255,166 @@ async def test_get_all_docs(mock_responses):
assert doc_count == total

await index.close()


Choose a reason for hiding this comment

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

I see that we mock the calls to the API, call the API, and then check that the mock was called with the params we specified. It does not feel this tests anything other than the signature of the method. Is this typical in our tests?

Copy link
Contributor Author

@mattnowzari mattnowzari Jan 23, 2025

Choose a reason for hiding this comment

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

I saw a few tests that behave this way (here is an example of one), and I figured that because ESApi extends* the ES client, we could simply have coverage to make sure we are calling those classes correctly.

I can totally go back to the drawing board with these if we wanted to make them do more, though!

Copy link
Member

Choose a reason for hiding this comment

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

We do test like this sometimes, alternative is testing with mocking HTTP requests: https://github.com/elastic/connectors/blob/main/tests/test_sink.py#L95

Copy link

@erikcurrin-elastic erikcurrin-elastic Jan 27, 2025

Choose a reason for hiding this comment

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

I feel like the later we can mock, the better. Otherwise, we are testing things which are not likely to reveal a bug. The questions is why do we write the test? It should be to do sanity checking and to protect ourselves against an incompatible change, not just for the sake of tests. I defer to the team's judgement on the level of testing needed/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree with your thoughts, Erik. These tests are rather thin, much like ESApi itself.

Given that ESApi acts like a partial wrapper around the ES client dependency, I would say any deeper testing would be akin to testing the client itself which, from connectors' perspective, is an import that presumably was tested already.

I don't think these unit tests are hurting anything overall, and they do follow precedent in how other tests are written in connectors. I am guaranteed to revisit this part of the code base when 9.0 releases, so I personally would advocate for these diffs as they sit.

The unit tests also technically don't exist yet, so I could be convinced we don't need them at all - we've come this far without them 🤣

Choose a reason for hiding this comment

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

OK. If something changed in the underlying call and this test fails, it is worthy to keep. Your call

Copy link
Member

Choose a reason for hiding this comment

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

I agree with Matt, these tests follow the pattern found in this repo and ensure that we pass arguments correctly to the client from our wrapper methods, which add the retry logic.

For the end-to-end scenario, we have a suite of functional tests that spin up an ES cluster and use these client calls to communicate with ES.

So, this code will ultimately be tested during the functional test step anyway.

@mattnowzari
Copy link
Contributor Author

buildkite test this

1 similar comment
@mattnowzari
Copy link
Contributor Author

buildkite test this

Copy link
Member

@jedrazb jedrazb left a comment

Choose a reason for hiding this comment

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

LGTM, all of those client calls should be tested by the smoke test and functional tests in our CI pipeline.

The only exception is the code responsible for the filtering validation:
Can you follow docs and try setting up advanced sync rules for a connector that is managed by connector service from this branch, you can find some examples in this tutorial

If you manage add sync rule and see that framework is able to validate it or detect errors then feel free to merge

@@ -255,3 +255,166 @@ async def test_get_all_docs(mock_responses):
assert doc_count == total

await index.close()


Copy link
Member

Choose a reason for hiding this comment

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

I agree with Matt, these tests follow the pattern found in this repo and ensure that we pass arguments correctly to the client from our wrapper methods, which add the retry logic.

For the end-to-end scenario, we have a suite of functional tests that spin up an ES cluster and use these client calls to communicate with ES.

So, this code will ultimately be tested during the functional test step anyway.

@mattnowzari mattnowzari enabled auto-merge (squash) January 28, 2025 19:22
@mattnowzari mattnowzari merged commit c08af2e into main Jan 28, 2025
2 checks passed
@mattnowzari mattnowzari deleted the mnowzari_es_client_api_calls branch January 28, 2025 19:42
Copy link

💔 Failed to create backport PR(s)

Status Branch Result
8.17 Commit could not be cherrypicked due to conflicts
8.x Commit could not be cherrypicked due to conflicts

To backport manually run:
backport --pr 3110 --autoMerge --autoMergeMethod squash

mattnowzari added a commit that referenced this pull request Jan 29, 2025
…ary wrapper methods (#3110)

Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit c08af2e)

# Conflicts:
#	connectors/es/index.py
@mattnowzari
Copy link
Contributor Author

💔 Some backports could not be created

Status Branch Result
8.x
8.17 Conflict resolution was aborted by the user

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

backport --pr 3110

Questions ?

Please refer to the Backport tool documentation

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.

Use ES client for Connector API calls
5 participants