Skip to content

Add human-formatted sizes and internal database sizes to stats#1257

Closed
qorexdevs wants to merge 1 commit into
meilisearch:mainfrom
qorexdevs:stats-size-format
Closed

Add human-formatted sizes and internal database sizes to stats#1257
qorexdevs wants to merge 1 commit into
meilisearch:mainfrom
qorexdevs:stats-size-format

Conversation

@qorexdevs

@qorexdevs qorexdevs commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Related issue

Closes #1234

What does this PR do?

  • Add show_internal_database_sizes and size_format params to client.get_all_stats() and Index.get_stats(), sent as the showInternalDatabaseSizes and sizeFormat query params introduced in Meilisearch 1.44
  • Expose the new internalDatabaseSizes (and rawDatabaseSize) keys on the IndexStats model as optional fields, so nothing breaks when they are absent
  • Add live tests for the human size format and internal database sizes on both the client and index stats routes

AI disclosure

None

PR checklist

  • Have you read the contributing guidelines?
  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you made sure that the title is accurate and descriptive of the changes?

Summary by CodeRabbit

  • New Features

    • Stats requests now support optional size-formatting and additional internal size details.
    • Index and instance stats responses can include more detailed storage information when requested.
  • Bug Fixes

    • Improved stats request handling so optional parameters are included only when needed, preserving existing behavior by default.
  • Tests

    • Added coverage for formatted database size output and internal database size fields in stats responses.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Client.get_all_stats and Index.get_stats now accept optional show_internal_database_sizes and size_format parameters, building query strings appended to the stats endpoints. IndexStats model adds raw_database_size and internal_database_sizes optional fields. New tests validate human-formatted sizes and internal database size responses for both client and index stats.

Changes

Stats API Query Parameter Support

Layer / File(s) Summary
Stats model fields
meilisearch/models/index.py
IndexStats adds optional raw_database_size and internal_database_sizes fields.
Client stats endpoint parameters
meilisearch/client.py, tests/client/test_client_stats_meilisearch.py
get_all_stats accepts show_internal_database_sizes and size_format, builds an encoded query string appended to the stats URL when present; tests verify human size format and internal database sizes inclusion.
Index stats endpoint parameters
meilisearch/index.py, tests/index/test_index_stats_meilisearch.py
get_stats accepts the same two parameters, conditionally appends a query string to the stats endpoint, and returns IndexStats; test verifies internal_database_sizes is populated.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ClientOrIndex
  participant MeilisearchAPI

  Caller->>ClientOrIndex: get_all_stats/get_stats(show_internal_database_sizes, size_format)
  ClientOrIndex->>ClientOrIndex: build query parameters dict
  ClientOrIndex->>MeilisearchAPI: GET stats endpoint with encoded query
  MeilisearchAPI-->>ClientOrIndex: stats response (with internalDatabaseSizes/human sizes)
  ClientOrIndex-->>Caller: parsed stats result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

A rabbit hopped through bytes and bits,
Counting sizes, raw and human fits,
"showInternalDatabaseSizes," I cheer,
New params bloom, the stats are clear!
🐇📊✨ Thump-thump, tests all pass here!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning [#1234] Core stats API and tests were updated, but the required .code-samples.meilisearch.yaml entries are not reflected in the PR summary. Add the missing code-sample examples for get_index_stats_1 and get_indexes_stats_1 in .code-samples.meilisearch.yaml and align them with the docs.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding human-formatted sizes and internal database sizes to stats.
Out of Scope Changes check ✅ Passed The changed files align with the stats API update and related tests, with no clear unrelated modifications shown.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
meilisearch/models/index.py (1)

28-35: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

raw_database_size doesn't match the stats payload, and it needs to accept human-formatted strings. Meilisearch returns rawDocumentDbSize, so this field won't populate as written. sizeFormat="human" also turns database sizes into strings, so int | None will reject valid responses.

🤖 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 `@meilisearch/models/index.py` around lines 28 - 35, The IndexStats model is
using a field type/name that does not match Meilisearch’s stats payload, so the
raw database size value will not bind correctly. Update IndexStats in the model
definition to map the rawDocumentDbSize response key to the existing
raw_database_size field, and change its type so it can accept both numeric
values and human-formatted strings returned when sizeFormat="human" is used.
Keep the same adjustment consistent with the other stats fields in IndexStats.
🧹 Nitpick comments (1)
tests/index/test_index_stats_meilisearch.py (1)

20-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

LGTM! Once the raw_database_size field/type is fixed in meilisearch/models/index.py, consider adding a companion test calling get_stats(size_format="human") to lock in that IndexStats still validates correctly.

🤖 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/index/test_index_stats_meilisearch.py` around lines 20 - 25, The
existing stats test only covers show_internal_database_sizes, so add a companion
test around IndexStats validation for the human-sized path once
raw_database_size is fixed in meilisearch/models/index.py. Reuse the get_stats
entry point in test_get_stats_internal_database_sizes and add coverage for
get_stats(size_format="human") to verify the response still instantiates
IndexStats and validates the database size field/type correctly.
🤖 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.

Outside diff comments:
In `@meilisearch/models/index.py`:
- Around line 28-35: The IndexStats model is using a field type/name that does
not match Meilisearch’s stats payload, so the raw database size value will not
bind correctly. Update IndexStats in the model definition to map the
rawDocumentDbSize response key to the existing raw_database_size field, and
change its type so it can accept both numeric values and human-formatted strings
returned when sizeFormat="human" is used. Keep the same adjustment consistent
with the other stats fields in IndexStats.

---

Nitpick comments:
In `@tests/index/test_index_stats_meilisearch.py`:
- Around line 20-25: The existing stats test only covers
show_internal_database_sizes, so add a companion test around IndexStats
validation for the human-sized path once raw_database_size is fixed in
meilisearch/models/index.py. Reuse the get_stats entry point in
test_get_stats_internal_database_sizes and add coverage for
get_stats(size_format="human") to verify the response still instantiates
IndexStats and validates the database size field/type correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c4126e78-67f1-4a29-86d8-17287a6b5cf2

📥 Commits

Reviewing files that changed from the base of the PR and between 8330e28 and 5ea33e1.

📒 Files selected for processing (5)
  • meilisearch/client.py
  • meilisearch/index.py
  • meilisearch/models/index.py
  • tests/client/test_client_stats_meilisearch.py
  • tests/index/test_index_stats_meilisearch.py

@qorexdevs

Copy link
Copy Markdown
Contributor Author

just realized #1237 already covers #1234 with the same two params and it predates this - closing mine so it doesn't split the review. sorry for the noise @vivek378521, yours should land.

@qorexdevs qorexdevs closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Meilisearch v1.44.0] Add human-formatted sizes and detailed DB sizes in stats

1 participant