opensearch-py icon indicating copy to clipboard operation
opensearch-py copied to clipboard

Ignore name of index when fetching settings

Open tienne-B opened this issue 1 year ago • 4 comments

Description

This commit fixes a situation where an index cannot be updated through this client as the index is aliased, with the client pointing to the alias.

As the GET /<index>/_settings request will only ever return the settings for the specified index (through the alias), it would only have one key, so the name of the key would not matter. We can pop the key to get the settings object for the index through the alias.

Describe what this change achieves.

Issues Resolved

Closes #822

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.

tienne-B avatar Sep 18 '24 02:09 tienne-B

Codecov Report

Attention: Patch coverage is 20.00000% with 8 lines in your changes missing coverage. Please review.

Project coverage is 70.34%. Comparing base (ba715b9) to head (e7532db). Report is 63 commits behind head on main.

Files with missing lines Patch % Lines
opensearchpy/_async/helpers/index.py 20.00% 4 Missing :warning:
opensearchpy/helpers/index.py 20.00% 4 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #823      +/-   ##
==========================================
- Coverage   71.95%   70.34%   -1.61%     
==========================================
  Files          91      113      +22     
  Lines        8001     8896     +895     
==========================================
+ Hits         5757     6258     +501     
- Misses       2244     2638     +394     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Sep 18 '24 02:09 codecov[bot]

Thank you @dblock for your quick response! The value of removing self._name is that saving an index previously wouldn't work if OS-py accesses it through an alias (and using an alias seems to be a good practice for downtime prevention). All the requests that are triggered by the .save() method can work transparently through an index, however, when making the GET /<alias>/_settings request, the dict response key is the name of the true index, rather than the alias. This causes the KeyError. However, the data we're extracting doesn't depend on the name, so it'd be safe to disregard and pop the key/value.

If it's wanted, I could add a check that the alias only points to one index to raise a more specific error. Would that be appreciated?

I've added a test, but I'm a little skeptical of the coverage report as it's based off a 6-month-old commit.

Thank you!

tienne-B avatar Sep 18 '24 16:09 tienne-B

If it's wanted, I could add a check that the alias only points to one index to raise a more specific error. Would that be appreciated?

Possibly, but doesn't have to block this PR. Give it a shot after I merge this!

dblock avatar Sep 19 '24 08:09 dblock

I've added support for async, the checks for multiple indices, and testing for these.

tienne-B avatar Sep 20 '24 11:09 tienne-B

~@tienne-B so we can't merge this without a passing CI, help out with whatever the right answer is to get it to pass and ensuring that the tests you have added do run in CI, please?~

I debugged the test failure but couldn't find a solution. You can rebase with the workaround in https://github.com/opensearch-project/opensearch-py/pull/828 for now (or maybe you know how to fix that failure?).

dblock avatar Sep 25 '24 19:09 dblock

@dblock Rebased.

tienne-B avatar Sep 26 '24 13:09 tienne-B

good work merci @tienne-B !

dblock avatar Sep 26 '24 18:09 dblock