Feat/index stats query params#1237
Conversation
Support showInternalDatabaseSizes and sizeFormat on index stats, extend IndexStats with internal_database_sizes, and add integration tests.
Support showInternalDatabaseSizes and sizeFormat on global stats, with integration tests and updated code sample.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR extends the Meilisearch Python SDK's stats APIs: ChangesStats API Query Parameters Extension
Test Infrastructure Improvements
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/client/test_client_stats_meilisearch.py (1)
39-54: ⚡ Quick winThe internal-sizes human-format check can silently no-op.
Unlike
test_get_all_stats_with_internal_database_sizes, this test has noany(...)guard asserting that at least one index actually containsinternalDatabaseSizes. If no index returns the key, the loop body never runs and the human-format assertion on internal sizes is skipped (only the top-leveldatabaseSizecheck on Line 48 would cover the format). Add a presence guard to ensure the internal-size branch is exercised.✅ Proposed guard
assert isinstance(response["databaseSize"], str) assert HUMAN_SIZE_PATTERN.match(response["databaseSize"]) + assert any( + "internalDatabaseSizes" in index_stats for index_stats in response["indexes"].values() + ) for index_stats in response["indexes"].values(): if "internalDatabaseSizes" in index_stats:🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/client/test_client_stats_meilisearch.py` around lines 39 - 54, The test test_get_all_stats_with_size_format can silently skip the internalDatabaseSizes checks if no index contains that key; update the test to assert the branch is exercised by collecting presence from response (e.g., use any(...) on response["indexes"].values() to check for "internalDatabaseSizes") and assert that at least one index contains internalDatabaseSizes before running the loop that validates HUMAN_SIZE_PATTERN on those values; operate on the existing response variable and keep the databaseSize string checks, then add the presence guard to fail the test if no internal sizes are present.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/client/test_client_stats_meilisearch.py`:
- Around line 39-54: The test test_get_all_stats_with_size_format can silently
skip the internalDatabaseSizes checks if no index contains that key; update the
test to assert the branch is exercised by collecting presence from response
(e.g., use any(...) on response["indexes"].values() to check for
"internalDatabaseSizes") and assert that at least one index contains
internalDatabaseSizes before running the loop that validates HUMAN_SIZE_PATTERN
on those values; operate on the existing response variable and keep the
databaseSize string checks, then add the presence guard to fail the test if no
internal sizes are present.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e585e2a7-2f74-4d44-95cb-53d88495ad07
📒 Files selected for processing (6)
.code-samples.meilisearch.yamlmeilisearch/client.pymeilisearch/index.pymeilisearch/models/index.pytests/client/test_client_stats_meilisearch.pytests/index/test_index_stats_meilisearch.py
Address CodeRabbit feedback: fail test_get_all_stats_with_size_format if no index returns internalDatabaseSizes, so human-size checks cannot pass silently.
Strift
left a comment
There was a problem hiding this comment.
Hello @vivek378521, thanks for your PR!
This looks good, but CI is not passing. I suggest you run tests + formatting locally before requesting another review 🙏
…ery-params # Conflicts: # tests/settings/test_settings_embedders.py
|
Hello @Strift I ran all tests locally and now everything looks good. Please review. Thank you for the time. I really appreciate it. :) |
Pull Request
Related issue
Fixes #1234
What does this PR do?
Meilisearch v1.44.0 adds two optional query parameters to
GET /indexes/{indexUid}/statsandGET /stats:showInternalDatabaseSizes— when true, index stat objects include aninternalDatabaseSizesdictionarysizeFormat—"human"for readable sizes (e.g."19.64 MiB") or"raw"for byte counts (default)This PR wires those parameters through the Python SDK:
Index.get_stats()— keyword-onlyshow_internal_database_sizesandsize_formatClient.get_all_stats()— same parametersIndexStats— optionalinternal_database_sizes: Dict[str, Any](loosely typed; keys may change between Meilisearch versions, per API guidance)SizeFormatenum (raw/human) for optional typing onsize_format.code-samples.meilisearch.yaml— updatedget_index_stats_1andget_indexes_stats_1Query params are only sent when the caller provides them (backward compatible). Boolean values are encoded as lowercase
true/false.Example:
PR checklist
Please check if your PR fulfills the following requirements:
Overview
Adds support for two optional query parameters introduced in Meilisearch v1.44.0 to the Python SDK’s index and global stats endpoints:
show_internal_database_sizes: When true, includes aninternalDatabaseSizesdictionary showing internal database names and sizes (keys intentionally kept loosely typed due to API variability)size_format: Controls output format—"human"for human-readable units (e.g., "19.64 MiB") or"raw"for byte counts (default)Changes
New Type Definition (
meilisearch/models/index.py)SizeFormatenum withRAW = "raw"andHUMAN = "human"IndexStatswith optionalinternal_database_sizes: Optional[Dict[str, Any]] = NoneAPI Updates
Index.get_stats(): Added keyword-only parametersshow_internal_database_sizes: Optional[bool] = Noneandsize_format: Optional[Union[SizeFormat, str]] = NoneClient.get_all_stats(): Added the same keyword-only parameterstrue/falsesize_formatsupports bothSizeFormatenum values and raw string valuesTest Coverage
tests/index/test_index_stats_meilisearch.pyinternal_database_sizesis present and non-empty whenshow_internal_database_sizes=Truesize_format=SizeFormat.HUMAN(validated viaHUMAN_SIZE_PATTERN)size_format="human"is passed as a stringtests/client/test_client_stats_meilisearch.pyget_all_stats) for:show_internal_database_sizes=Truewith raw sizesshow_internal_database_sizes=Truewithsize_format=SizeFormat.HUMANshow_internal_database_sizes=Truewithsize_format="human"Documentation
.code-samples.meilisearch.yamlto reflect the new parameters inget_index_stats_1andget_indexes_stats_1, demonstratingshow_internal_database_sizes=Truewithsize_format='human'