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

Use ES aliases instead of index names in queries #26733

Merged
merged 96 commits into from
Jul 22, 2020
Merged

Use ES aliases instead of index names in queries #26733

merged 96 commits into from
Jul 22, 2020

Conversation

sravfeyn
Copy link
Member

@sravfeyn sravfeyn commented Feb 27, 2020

This is only open to get any feedback and not ready for merge.

We are currently querying ES via index names. Querying via alias is supported and will be needed for ICDS where we are thinking to have multiple indices under one alias. This PR doesn't implement any multiple index support, but as a starting point simply queries ES using alias instead of index in all places that I could find. I have added a logger to find any places that I missed where an index is directly queried instead of an alias.

My plan for this PR is

  • to get tests passing
  • test it on staging with ENABLE_ES_INTERFACE_LOGGING
  • if those two go okay, I will open this PR for merge.

After this my plan to actually add multiple index support for single alias. My tentative plan is

  • add an additional write_alias attribute to ElasticsearchIndexInfo and use that for all write operations.
  • add a validation to check that write_alias points to only single index
  • rename current alias attribute of ElasticsearchIndexInfo to read_alias and use that for all read operations.

This will enable individual envs to manage their ES indices outside of HQ with custom settings, rolling indices etc

corehq/elastic.py Outdated Show resolved Hide resolved
corehq/elastic.py Outdated Show resolved Hide resolved
@sravfeyn sravfeyn changed the title WIP: Use aliases instead of index names Use ES aliases instead of index names in queries Feb 27, 2020
Copy link
Contributor

@snopoke snopoke left a comment

Choose a reason for hiding this comment

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

Looks good @sravfeyn

"sms": SMS_INDEX_INFO,
"report_cases": REPORT_CASE_INDEX,
"report_xforms": REPORT_XFORM_INDEX,
"case_search": CASE_SEARCH_INDEX_INFO,
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

corehq/util/es/interface.py Outdated Show resolved Hide resolved
corehq/util/es/interface.py Outdated Show resolved Hide resolved
corehq/util/es/interface.py Outdated Show resolved Hide resolved
@sravfeyn sravfeyn added the product/invisible Change has no end-user visible impact label Feb 28, 2020
@sravfeyn
Copy link
Member Author

Bumping for review on recently added commits.

@sravfeyn
Copy link
Member Author

sravfeyn commented Jul 1, 2020

@snopoke @dannyroberts Bumping again for review on last 3 commits

@sravfeyn
Copy link
Member Author

sravfeyn commented Jul 3, 2020

@dannyroberts @snopoke Is this good to go?

@snopoke
Copy link
Contributor

snopoke commented Jul 6, 2020

@sravfeyn still some outstanding comments

@sravfeyn
Copy link
Member Author

sravfeyn commented Jul 7, 2020

@snopoke Sorry, which ones Simon?

@snopoke
Copy link
Contributor

snopoke commented Jul 7, 2020

@sravfeyn
Copy link
Member Author

sravfeyn commented Jul 7, 2020

I am not sure why you are not able to see my responses made couple days back. See below screenshot

Screenshot 2020-07-07 at 4 58 11 PM

@snopoke
Copy link
Contributor

snopoke commented Jul 7, 2020

@sravfeyn thanks for the responses, your comments are still pending, you need to click 'submit review' (I've been bitten by that many times).

@sravfeyn
Copy link
Member Author

sravfeyn commented Jul 7, 2020

you need to click 'submit review' (I've been bitten by that many times).
Ah, thanks!

@sravfeyn
Copy link
Member Author

sravfeyn commented Jul 9, 2020

@snopoke I have responded to the comments (hope you are able to see them) and update the docs per your comment.

@snopoke
Copy link
Contributor

snopoke commented Jul 9, 2020

@sravfeyn have these changes been tested on staging at all?

@sravfeyn sravfeyn added the awaiting QA QA in progress. Do not merge label Jul 10, 2020
@sravfeyn
Copy link
Member Author

sravfeyn commented Jul 10, 2020

Yes, they have been live on staging for more than few weeks now. I have tested basic things and made sure requests are coming to aliases and not indices.

Also submitted a QA ticket to go along with #28032

@sravfeyn sravfeyn mentioned this pull request Jul 10, 2020
@sravfeyn sravfeyn added QA Passed and removed awaiting QA QA in progress. Do not merge labels Jul 21, 2020
@sravfeyn
Copy link
Member Author

QA is passed on this https://dimagi-dev.atlassian.net/browse/QA-1532

@snopoke think we can merge this now?

@sravfeyn
Copy link
Member Author

Hello @dimagi/team-commcare-hq

This is a pretty big change in Elasticsearch, so wanted to make an announcement. From this PR on, HQ code will use Elasticsearch aliases to interact with Elasticsearch instead of index names as it previously did. There is also a change in the workflow of changing ES index mappings, please read it here https://github.com/dimagi/commcare-hq/pull/26733/files#diff-55ae021bb3841b645117710c304ad227

This is QA and review pass. I am going to merge it tomorrow (to give some time for people to be aware and raise any concerns if any)

corehq/apps/api/es.py Outdated Show resolved Hide resolved
@sravfeyn sravfeyn merged commit 87be4b1 into master Jul 22, 2020
@sravfeyn
Copy link
Member Author

sravfeyn commented Jul 22, 2020

This is well tested but just to be safe, if any issues with pillows do come up form this PR, this can be reverted. We just need to rewind pillows https://github.com/dimagi/commcare-hq/blob/master/corehq/apps/es/management/commands/restore_es_snapshot.py#L91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product/invisible Change has no end-user visible impact QA Passed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants