feat: Improves meilisearch configuration step#38384
feat: Improves meilisearch configuration step#38384farhaanbukhsh wants to merge 5 commits intoopenedx:masterfrom
Conversation
|
Thanks for the pull request, @farhaanbukhsh! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
…up with a migration plan and configuration plan depending on the state. This introduces a mechanism it or a drift engine which drill down the Meiliseach configuration and figures out what has changed: - settings - primary key depending on the change we follow a strategy wether to migrate the data or recreate the index Signed-off-by: Farhaan Bukhsh <farhaan@opencraft.com>
e37d5a1 to
71169b2
Compare
…index. Signed-off-by: Farhaan Bukhsh <farhaan@opencraft.com>
bradenmacdonald
left a comment
There was a problem hiding this comment.
This is looking great!
| class Command(BaseCommand): | ||
| """ | ||
| Build or re-build the Meilisearch search index for courses and libraries in Studio. | ||
| Queue incremental population of the Meilisearch search index for Studio. |
There was a problem hiding this comment.
| Queue incremental population of the Meilisearch search index for Studio. | |
| Add all course and library content to the Studio search index. |
I think "queue incremental population" sounds a bit weird because of how "population" is being used. So I just suggest re-wording this a bit.
| """ | ||
|
|
||
| # TODO: improve this - see https://github.com/openedx/edx-platform/issues/36868 | ||
| help = "Queue incremental population of the Studio Meilisearch search index via Celery." |
There was a problem hiding this comment.
| help = "Queue incremental population of the Studio Meilisearch search index via Celery." | |
| help = "Add all course and library content to the Studio search index." |
| raise CommandError( | ||
| "The --incremental flag has been removed. " | ||
| "Incremental population is now the default behavior of this command." | ||
| ) |
There was a problem hiding this comment.
You could print this as a warning but still run the command ? Because what the user is asking for is the same as what you're about to do.
| """ | ||
|
|
||
| exists: bool | ||
| is_empty: bool | None = field(default=None) # None if index doesn't exist |
There was a problem hiding this comment.
| is_empty: bool | None = field(default=None) # None if index doesn't exist | |
| is_empty: bool | None = None # None if index doesn't exist |
Nit: For all of these attrs fields, I think you can just use = None to set the default value. You only really need to use field(...) to specify a default with a factory function, like field(factory=list) for empty list defaults.
There was a problem hiding this comment.
I saw attrs documentation and they were using fields to set default values, hence I made that call. :)
There was a problem hiding this comment.
Ahh! thank you for pointing this out :)
| @property | ||
| def is_drifted(self) -> bool: | ||
| """True if settings are drifted OR primary key is incorrect.""" | ||
| return self.is_settings_drifted or self.primary_key_correct is False |
There was a problem hiding this comment.
Nit: would be good to have a comment here explaining why we have is_settings_drifted separate from is_drifted (Because changing the primary key requires re-creating the index?)
There was a problem hiding this comment.
is_drifted and is_configured both helped me a lot in writing proper tests. I am just wondering about removing these.
There was a problem hiding this comment.
OK, feel free to leave them both in .
There was a problem hiding this comment.
I removed them and changed the tests a bit. I think it's good to remove code so that there is less confusion when we are maintaining it.
| Unlike _configure_index() which fires-and-forgets, this function waits for | ||
| confirmation that each setting has been applied. This is used during reconciliation | ||
| where we need a definitive state before returning. |
There was a problem hiding this comment.
What do you think about combining these into one function with a wait=True/False parameter?
There was a problem hiding this comment.
I agree with it, it makes sense to do it.
| if not drift.exists: | ||
| status_cb("Studio search index not found. Creating and configuring...") | ||
| reset_index(status_cb) | ||
| status_cb("Index created. Run ./manage.py cms reindex_studio to populate.") |
There was a problem hiding this comment.
| status_cb("Index created. Run ./manage.py cms reindex_studio to populate.") | |
| status_cb("Index created. Run './manage.py cms reindex_studio' to populate.") |
| return | ||
|
|
||
| reset_index(status_cb) | ||
| # CASE: Index populated |
There was a problem hiding this comment.
| # CASE: Index populated | |
| # CASE: Index populated, but configuration is outdated |
| """ | ||
| Initialize the Meilisearch index, creating it and configuring it if it doesn't exist. | ||
|
|
||
| This is a compatibility wrapper around reconcile_index(). |
There was a problem hiding this comment.
Should we mark this API method as deprecated?
There was a problem hiding this comment.
How do we do that? Log a warning that it is going to be deprecated?
There was a problem hiding this comment.
Yeah, just mention in the docstring that it is deprecated as of Verawood. I don't think the formal DEPR process is necessary just for one API method like this that isn't super well known nor widely used, when there's a new alternative.
| _apply_settings_with_waits(STUDIO_INDEX_NAME, status_cb) | ||
| warn_cb( | ||
| "Settings applied. Meilisearch will re-index documents in the background. " | ||
| "Consider running ./manage.py cms reindex_studio for a full rebuild " |
There was a problem hiding this comment.
| "Consider running ./manage.py cms reindex_studio for a full rebuild " | |
| "Consider running './manage.py cms reindex_studio' for a full rebuild " |
…d come up with a migration plan and configuration plan depending on the state. This introduces a mechanism it or a drift engine which drill down the Meiliseach configuration and figures out what has changed:

Description
The changes here are to add a Drift Calculator for the Meilisearch index to help us configure Meiliseach at the fresh installation or upgrade. This mechanism triggers on each run of migrate so wether it is a new installation or upgrade. This makes sure that we calculate and gauge the status of Meiliseach studio index and have a plan to mitigate it.
Useful information to include:
We try to caculate and see here how far the changes have gone from codebase and try to bring it back to codebase. Specially with change in PK there is not much we can do we have to drop the index and create and configure a new one.
We are making use to make that happen when migrate runs. Hence, whenever
./manage.py cms migrateruns this command follows it. The diff is calculate so only when an action is needed it will be taken into effect.Supporting information
tutor dev stoptutor images build openedx-devtutor dev start -dtutor dev status | rg meilisearch--> This helps us find out if meilisearch is running.tutor dev exec -it cms -- /bin/bash./manage.py cms migrateapi.py:580 - Index is populated and correctly configured. No action needed.in the logLets do a bit more tests
./manage.py cms shell./manage.py cms migrateagain, you will the script is fixing the changes.Deadline
ASAP
Other information
TBD
Private Ref: BB-10767