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

Added Tests for Search Pipeline and Notifications Plugin #668

Merged

Conversation

AbitraryYu
Copy link
Contributor

Description

Describe what this change achieves.

This change tries to solve #474

Issues Resolved

List any issues this PR will resolve, e.g. Closes [...].

If this is resolved, this closes #474

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link

codecov bot commented Feb 6, 2024

Codecov Report

Attention: Patch coverage is 56.52174% with 40 lines in your changes are missing coverage. Please review.

Project coverage is 71.80%. Comparing base (ba715b9) to head (3d7586c).
Report is 11 commits behind head on main.

❗ Current head 3d7586c differs from pull request most recent head 891c250. Consider uploading reports for the commit 891c250 to get more accurate results

Files Patch % Lines
opensearchpy/_async/plugins/notifications.py 53.57% 13 Missing ⚠️
opensearchpy/plugins/notifications.py 53.57% 13 Missing ⚠️
opensearchpy/_async/client/search_pipeline.py 50.00% 7 Missing ⚠️
opensearchpy/client/search_pipeline.py 50.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #668      +/-   ##
==========================================
- Coverage   71.95%   71.80%   -0.16%     
==========================================
  Files          91       95       +4     
  Lines        8001     8103     +102     
==========================================
+ Hits         5757     5818      +61     
- Misses       2244     2285      +41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@orangewise
Copy link

Question, would this also work with opensearch serverless (aws)?

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Was this code actually generated? The "right" way to do this is to add search pipelines to https://github.com/opensearch-project/opensearch-api-specification and then to generate the client.

@AbitraryYu
Copy link
Contributor Author

I see there's a PR in opensearch-api-specification . If that PR is merged, then does that mean the search pipeline api for opensearch-py can be generated? Thanks.

@saimedhi
Copy link
Collaborator

saimedhi commented Feb 7, 2024

I see there's a PR in opensearch-api-specification . If that PR is merged, then does that mean the search pipeline api for opensearch-py can be generated? Thanks.

  • @AbitraryYu, once the spec is merged, we can generate the search pipeline API. After generation, we'll review it for any necessary fixes to the generator code.

  • Your contribution to getting the spec merged would be greatly appreciated, and it will help us move forward with API generation. Thank you.

@lambda-science
Copy link

Any follow up on this ? .. We need search pipeline API

@saimedhi
Copy link
Collaborator

Any follow up on this ? .. We need search pipeline API

@lambda-science, @ArbitraryYu, please feel free to contribute to the spec to get it merged.

opensearch-project/opensearch-api-specification#172

@AbitraryYu
Copy link
Contributor Author

When I try to generate the code using nox -rs generate it fails at /utils/generate_api.py line 595. I have printed some of the debug logs (by inserting some print statements on my own) and saw the following:

{'name': 'config_id', 'in': 'query', 'description': 'A channel ID.', 'schema': {'type': 'string', 'description': 'A channel ID.'}}
{'name': 'config_id_list', 'in': 'query', 'description': 'A comma-separated list of channel IDs.', 'schema': {'type': 'string', 'description': 'A comma-separated list of channel IDs.'}}
{'name': 'last_updated_time_ms', 'in': 'query', 'schema': {'type': 'integer', 'format': 'int64'}}
Traceback (most recent call last):
  File "<repo_dir>/utils/generate_api.py", line 853, in <module>
    dump_modules(read_modules())
                 ^^^^^^^^^^^^^^
  File "<repo_dir>/utils/generate_api.py", line 595, in read_modules
    type=m["schema"]["type"], description=m["description"]
                                          ~^^^^^^^^^^^^^^^
KeyError: 'description'
nox > Command python utils/generate_api.py failed with exit code 1
nox > Session generate failed.

I take a look at the OpenSearch.openapi.json at raw.github, and find out it is the GET parameters of /_plugins/_notifications/configs that lack the description (on line 13377, or see the picture)
2024-03-26-110252_1920x1051_scrot

I saw some other parameters also lack description, I am not sure if there are more parameters that lack description.

My question is: Are there any methods that I can skip the problematic part and just generate the search pipeline API part?If not, is it a new issue that need to be raised in the opensearch-api-specification repository?

@saimedhi
Copy link
Collaborator

When I try to generate the code using nox -rs generate it fails at /utils/generate_api.py line 595. I have printed some of the debug logs (by inserting some print statements on my own) and saw the following:

{'name': 'config_id', 'in': 'query', 'description': 'A channel ID.', 'schema': {'type': 'string', 'description': 'A channel ID.'}}
{'name': 'config_id_list', 'in': 'query', 'description': 'A comma-separated list of channel IDs.', 'schema': {'type': 'string', 'description': 'A comma-separated list of channel IDs.'}}
{'name': 'last_updated_time_ms', 'in': 'query', 'schema': {'type': 'integer', 'format': 'int64'}}
Traceback (most recent call last):
  File "<repo_dir>/utils/generate_api.py", line 853, in <module>
    dump_modules(read_modules())
                 ^^^^^^^^^^^^^^
  File "<repo_dir>/utils/generate_api.py", line 595, in read_modules
    type=m["schema"]["type"], description=m["description"]
                                          ~^^^^^^^^^^^^^^^
KeyError: 'description'
nox > Command python utils/generate_api.py failed with exit code 1
nox > Session generate failed.

I take a look at the OpenSearch.openapi.json at raw.github, and find out it is the GET parameters of /_plugins/_notifications/configs that lack the description (on line 13377, or see the picture) 2024-03-26-110252_1920x1051_scrot

I saw some other parameters also lack description, I am not sure if there are more parameters that lack description.

My question is: Are there any methods that I can skip the problematic part and just generate the search pipeline API part?If not, is it a new issue that need to be raised in the opensearch-api-specification repository?

When I try to generate the code using nox -rs generate it fails at /utils/generate_api.py line 595. I have printed some of the debug logs (by inserting some print statements on my own) and saw the following:

{'name': 'config_id', 'in': 'query', 'description': 'A channel ID.', 'schema': {'type': 'string', 'description': 'A channel ID.'}}
{'name': 'config_id_list', 'in': 'query', 'description': 'A comma-separated list of channel IDs.', 'schema': {'type': 'string', 'description': 'A comma-separated list of channel IDs.'}}
{'name': 'last_updated_time_ms', 'in': 'query', 'schema': {'type': 'integer', 'format': 'int64'}}
Traceback (most recent call last):
  File "<repo_dir>/utils/generate_api.py", line 853, in <module>
    dump_modules(read_modules())
                 ^^^^^^^^^^^^^^
  File "<repo_dir>/utils/generate_api.py", line 595, in read_modules
    type=m["schema"]["type"], description=m["description"]
                                          ~^^^^^^^^^^^^^^^
KeyError: 'description'
nox > Command python utils/generate_api.py failed with exit code 1
nox > Session generate failed.

I take a look at the OpenSearch.openapi.json at raw.github, and find out it is the GET parameters of /_plugins/_notifications/configs that lack the description (on line 13377, or see the picture) 2024-03-26-110252_1920x1051_scrot

I saw some other parameters also lack description, I am not sure if there are more parameters that lack description.

My question is: Are there any methods that I can skip the problematic part and just generate the search pipeline API part?If not, is it a new issue that need to be raised in the opensearch-api-specification repository?

Hey @AbitraryYu, to avoid the generator error, we could tweak the code to first check if the parameter description exists before using it. Yet, I believe it's even better to include the parameter description that is missing in the spec.

@dblock, what's your take on this?

@saimedhi
Copy link
Collaborator

saimedhi commented Mar 26, 2024

@AbitraryYu, please try fixing #710.

So, that all APIs from spec will be generated by update_api workflow and PR will be raised automatically if changes detected. Consider raising PR for spec repo with missing descriptions or fix generator to skip using description if not present. Thank you.

@dblock
Copy link
Member

dblock commented Mar 26, 2024

@dblock, what's your take on this?

If the description is not required, the generator should gracefully handle that.

@AbitraryYu
Copy link
Contributor Author

AbitraryYu commented Apr 2, 2024

The code is generated via nox, and I modified the generator in generate_api.py to gracefully ignore messages if the API specification is empty.

By the way, the raw link of the opensearch "https://raw.githubusercontent.com/opensearch-project/opensearch-api-specification/main/OpenSearch.openapi.json" seems giving me 404 (line 550-554), so I use my local version downloaded from last week.

@AbitraryYu
Copy link
Contributor Author

AbitraryYu commented Apr 2, 2024

A side note, the latest version of opensearch (docker) require admin password, and I cannot get it run tests locally. I am not sure if this repository supports password parsing so I am using an older version: 2.11.1 (docker).

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Let me try to help with the password issue.

In 2.12 you need a default password, https://opensearch.org/blog/replacing-default-admin-credentials/, this repo was updated to act accordingly AFAIK.

We're moving things around in opensearch-api-specification, so you might hit issues, opensearch-project/opensearch-api-specification#189

Iterate this change to green?

utils/generate_api.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@saimedhi saimedhi left a comment

Choose a reason for hiding this comment

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

Hello @AbitraryYu,

  • It appears there might have been an issue during the generation process.
  • Could you confirm if you ran nox -rs generate and it is successful? This command triggers both the generator and the formatter. If the formatter step was skipped, it might explain the extensive changes to files. Generally, with the formatter running, modifications should be limited to newly added APIs.
  • Feel free to reach out if you require any assistance. Your contribution is greatly appreciated!

utils/generate_api.py Outdated Show resolved Hide resolved
@saimedhi
Copy link
Collaborator

saimedhi commented Apr 8, 2024

@AbitraryYu, Thank you for implementing the requested changes! Could you also include tests for these generated APIs?

@AbitraryYu
Copy link
Contributor Author

Hi @saimedhi , I got confused where I should implement the tests. I saw test_opensearch/test_helpers/test_search.py and test_opensearch/test_async/test_helpers/test_search.py, and they are using from opensearchpy.helpers import search. I am wondering do I need to create a new helper file in opensearchpy.helpers plus creating both new test files in test_opensearch/test_helpers/ and test_opensearch//test_async/test_helpers/. Thanks.

@saimedhi
Copy link
Collaborator

Hi @saimedhi , I got confused where I should implement the tests. I saw test_opensearch/test_helpers/test_search.py and test_opensearch/test_async/test_helpers/test_search.py, and they are using from opensearchpy.helpers import search. I am wondering do I need to create a new helper file in opensearchpy.helpers plus creating both new test files in test_opensearch/test_helpers/ and test_opensearch//test_async/test_helpers/. Thanks.

@AbitraryYu,

  • For search_pipeline unit tests, they can be added here. Please create a file for search_pipeline test cases in that folder.
  • For search_pipeline integration tests, removing the skip test here is sufficient.
  • Notification plugin tests can be added here, and async tests here.

@saimedhi
Copy link
Collaborator

Thank you for your contribution, @ArbitraryYu. The Search Pipeline and Notification APIs have now been added to opensearch-py. We would greatly appreciate your help in adding tests for the Notifications Plugin whenever you have the chance.

@AbitraryYu
Copy link
Contributor Author

AbitraryYu commented Apr 20, 2024

Sorry for all the dirty commits, I accidentally committed some sensitive data to this branch and I attempt to remove it both locally and remotely. I already force push the git history so the my local repo feature branch cannot access it. However, this PR still have the stray commit that contain the sensitive data.

I just submitted a Github support request for to clear the cached views but might need this PR's admin permission to actually take effect.

Update: The affected commit seems to be hidden after 2 hours, would let you guys know if Github support need your support. Thank you.

Update 2: The GitHub support team removed the affected commit cache and I confirmed the affected commit is no longer accessible, so I think the case is closed. Thank you.

@@ -224,6 +224,7 @@ class as kwargs, or a string in the format of ``host[:port]`` which will be
self.ingest = IngestClient(self)
self.nodes = NodesClient(self)
self.remote = RemoteClient(self)
self.search_pipeline = SearchPipelineClient(self)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ArbitraryYu, thanks for your contribution. Just a few adjustments needed.

  • No modification needed for this file. In a recent PR, self.search_pipeline = SearchPipelineClient(self) was added.

@@ -224,6 +224,7 @@ class as kwargs, or a string in the format of ``host[:port]`` which will be
self.ingest = IngestClient(self)
self.nodes = NodesClient(self)
self.remote = RemoteClient(self)
self.search_pipeline = SearchPipelineClient(self)
Copy link
Collaborator

Choose a reason for hiding this comment

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

No modification needed for this file

@@ -72,7 +72,6 @@
# broken YAML tests on some releases
SKIP_TESTS = {
# Warning about date_histogram.interval deprecation is raised randomly
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/search_pipeline/10_basic",
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/pit/10_basic",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove the change OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/search_pipeline/10_basic to avoid blocking this PR, as two tests are currently failing.

It will be handled in #726 . Integration tests with OpenSearch 2.7 and 2.8 are failing due to a server bug, and I'll raise an issue in the appropriate repo.

@saimedhi saimedhi added the skip-changelog Skips changelog verifier label Apr 22, 2024
@saimedhi
Copy link
Collaborator

@ArbitraryYu, please resolve the failing DCO check.

@AbitraryYu AbitraryYu force-pushed the feature/search_pipeline_api branch 2 times, most recently from 846c25b to ead8373 Compare April 22, 2024 11:05
@AbitraryYu
Copy link
Contributor Author

For the DCO, I try to follow the DCO guide, git rebase HEAD~10 --signoff, going through the rebase process, and once I push it, the PR got 49+ files changed. I was wondering if I can add those signoff(s) by modifying a specific commit?

@dblock
Copy link
Member

dblock commented Apr 22, 2024

For the DCO, I try to follow the DCO guide, git rebase HEAD~10 --signoff, going through the rebase process, and once I push it, the PR got 49+ files changed. I was wondering if I can add those signoff(s) by modifying a specific commit?

It's probably easier to re-create the changes in the branch, or do https://code.dblock.org/2015/08/31/getting-out-of-your-first-git-mess.html.

git checkout feature/search_pipeline_api
git checkout -b feature/search_pipeline_api-backup
git checkout feature/search_pipeline_api
git reset HEAD~1 # repeat this until you've rewound your branch enough
git add .
git commit -s -m ...
git push origin feature/search_pipeline_api-backup -f

@saimedhi saimedhi changed the title Added Search Pipeline API Added Tests for Search Pipeline and Notifications Plugin Apr 22, 2024
Signed-off-by: AbitraryYu <nikkoyhc@gmail.com>
Signed-off-by: AbitraryYu <nikkoyhc@gmail.com>
…nflict.

Signed-off-by: AbitraryYu <nikkoyhc@gmail.com>
@AbitraryYu
Copy link
Contributor Author

Fixed the DCO, and the tests seems ok.



class TestNotificationPlugin(OpenSearchTestCase):
async def test_create_channel_notification(self) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • @AbitraryYu, please remove async from all the test cases in this file.
  • After removing async, you might notice that some test cases fail. Please fix them.
  • For example, test_delete_channel_configuration may fail. Remember, each test case is isolated, so create the configuration before deleting it within the same test case. See this reference. Thank you.

Signed-off-by: AbitraryYu <nikkoyhc@gmail.com>
@saimedhi
Copy link
Collaborator

@AbitraryYu, please try to fix failing tests.

Signed-off-by: AbitraryYu <nikkoyhc@gmail.com>
@AbitraryYu
Copy link
Contributor Author

AbitraryYu commented Apr 28, 2024

I followed the example on test_index_management.py of this reference, and I got errors like:

  • error: Unsupported target for indexed assignment ("Collection[str]") on here
  • error: Value of type "Collection[str]" is not indexable on here.

How can I fix that?

Meanwhile, the test_list_all_config() returns an empty list of config list, so I didn't write an assertEqual test; while test_get_config() returns something on the config list. I am not sure if test_list_all_config() is behaving properly, both tests create an index self.test_create_config() at the start.

@saimedhi
Copy link
Collaborator

saimedhi commented Apr 29, 2024

I followed the example on test_index_management.py of this reference, and I got errors like:

  • error: Unsupported target for indexed assignment ("Collection[str]") on here
  • error: Value of type "Collection[str]" is not indexable on here.

How can I fix that?

@ArbitraryYu, follow these steps to resolve the errors:

  • Format the code using nox -rs format.
  • Add type hints for CONTENT here:
CONTENT: Dict[str, Any] = {
    "config_id": "sample-id",
    # ... other keys ...
}

Signed-off-by: AbitraryYu <nikkoyhc@gmail.com>
@saimedhi saimedhi requested a review from dblock April 30, 2024 19:29
@saimedhi
Copy link
Collaborator

@dblock, I'm unable to merge the PR. Could you please review, approve, and merge it? Thank you!

@dblock dblock merged commit 0caacf8 into opensearch-project:main Apr 30, 2024
55 checks passed
dblock pushed a commit to dblock/opensearch-py that referenced this pull request Aug 15, 2024
…project#668)

* Added Tests for Notification and Search Pipeline.ml

Signed-off-by: AbitraryYu <nikkoyhc@gmail.com>

* Add back the lines of comment in indices.py during resolving merge conflict.

Signed-off-by: AbitraryYu <nikkoyhc@gmail.com>

* Fix notification plugin tests, from async def to def.

Signed-off-by: AbitraryYu <nikkoyhc@gmail.com>

* Fix test errors. Rename function names and rewrite assertion tests.

Signed-off-by: AbitraryYu <nikkoyhc@gmail.com>

* Fix formatting errors. Added typings to CONTENT.

Signed-off-by: AbitraryYu <nikkoyhc@gmail.com>

---------

Signed-off-by: AbitraryYu <nikkoyhc@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add support for search pipeline APIs
5 participants