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 (1)
🚧 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
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 sizessize_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"membersIndexStatsmodel with optionalinternal_database_sizes: Optional[Dict[str, Any]]field to accommodate loosely-typed internal database informationAPI Updates
Index.get_stats(): Added keyword-only parametersshow_internal_database_sizes(Optional[bool]) andsize_format(Optional[Union[SizeFormat, str]])Client.get_all_stats(): Added the same keyword-only parametersSizeFormatenum values and raw string values forsize_formatTest Coverage
tests/index/test_index_stats_meilisearch.py: Added tests validating:internal_database_sizespresence and content whenshow_internal_database_sizes=Truesize_format=SizeFormat.HUMANis combined with internal database sizestests/client/test_client_stats_meilisearch.py: Added tests for global stats with similar coverage for internal database sizes and human-readable formattingHUMAN_SIZE_PATTERNto validate human-readable size stringsDocumentation
.code-samples.meilisearch.yaml: Examples forget_index_stats_1andget_indexes_stats_1now demonstrate both parameters withshow_internal_database_sizes=Trueandsize_format='human'Technical Notes