Skip to content

Add stats size format options#979

Open
Moustafa-Ameen wants to merge 2 commits into
meilisearch:mainfrom
Moustafa-Ameen:codex/meilisearch-stats-size-options
Open

Add stats size format options#979
Moustafa-Ameen wants to merge 2 commits into
meilisearch:mainfrom
Moustafa-Ameen:codex/meilisearch-stats-size-options

Conversation

@Moustafa-Ameen

@Moustafa-Ameen Moustafa-Ameen commented Jul 1, 2026

Copy link
Copy Markdown

Pull Request

Related issue

Fixes #966

What does this PR do?

  • Adds StatsQuery support for the showInternalDatabaseSizes and sizeFormat query parameters.
  • Adds parameterized stats methods for global stats and index stats.
  • Adds response models that support raw numeric sizes and human-readable size strings.
  • Represents internalDatabaseSizes as a flexible map.
  • Updates tests for the new stats query parameters and response handling.
  • Updates .code-samples.meilisearch.yaml for get_index_stats_1 and get_indexes_stats_1.

PR checklist

Please check if your PR fulfills the following requirements:

  • Did you use any AI tool while implementing this PR (code, tests, docs, etc.)? If yes, disclose it in the PR description and describe what it was used for. AI usage is allowed when it is disclosed.
    • Used ChatGPT/Codex to inspect the SDK structure, implement the stats query/model changes, add focused tests, and prepare this PR description.
  • 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 read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Tests

  • .\gradlew.bat testClasses
  • .\gradlew.bat test --tests com.meilisearch.sdk.StatsTest --init-script <disable-jacoco> -x jacocoTestReport -x jacocoTestCoverageVerification --rerun-tasks

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • New Features
    • Stats requests can now include options for internal database sizes and human-readable size formatting.
    • Added overloads to retrieve enhanced stats at both the app-wide and index levels.
  • Bug Fixes
    • Updated Java stats examples to use the query-based approach for size formatting and internal size visibility.
  • Tests
    • Added coverage for stats query serialization and parsing of both human-formatted and raw numeric size responses for global and index stats.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds StatsQuery support for stats endpoints, introduces size-format stats response models, wires new getStats overloads through the SDK, and updates tests and code samples for the new query parameters and response shapes.

Changes

Stats query parameter support

Layer / File(s) Summary
StatsQuery and response models
src/main/java/com/meilisearch/sdk/model/StatsQuery.java, .../StatsWithSizeFormat.java, .../IndexStatsWithSizeFormat.java
Adds StatsQuery serialization and new stats response models that carry size values as Object and include nested index stats.
Stats retrieval wiring
src/main/java/com/meilisearch/sdk/InstanceHandler.java, src/main/java/com/meilisearch/sdk/Client.java, src/main/java/com/meilisearch/sdk/Index.java
Updates stats fetch paths to accept StatsQuery, build query-parameterized URLs, and return the new size-format response types.
Tests and samples
src/test/java/com/meilisearch/sdk/StatsTest.java, .code-samples.meilisearch.yaml
Adds coverage for query serialization, human-formatted and raw size responses, and updates stats code samples to pass StatsQuery.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

Poem

Hop hop, I fetched stats today,
With human sizes on display.
Query params in every hop,
Little ears up, stats don’t stop. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding size format options to stats APIs.
Linked Issues check ✅ Passed The PR adds the new stats query methods, response models, tests, and code-sample updates required by #966.
Out of Scope Changes check ✅ Passed The changes stay focused on stats API support, related models, tests, and documentation samples.
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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/test/java/com/meilisearch/sdk/StatsTest.java (1)

33-120: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for optional/default and raw-size responses.

These tests only exercise the sizeFormat=human path and a fully populated query. They never cover the API’s optional/default behavior or raw numeric size payloads, so the current sizeFormat=null serialization bug slips through and half of the new response contract remains unverified.

🤖 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 `@src/test/java/com/meilisearch/sdk/StatsTest.java` around lines 33 - 120, Add
test coverage in StatsTest for the missing StatsQuery paths: verify the
default/optional case where sizeFormat is not set still serializes correctly and
does not emit a null query value, and add raw-size response coverage for both
client.getStats and client.index("movies").getStats using numeric size payloads
rather than only the human-formatted contract. Use the existing StatsQuery,
getStatsWithQueryParameters, getIndexStatsWithQueryParameters, and
statsQuerySerializesParameters tests as the place to extend assertions so the
serialization bug and raw response handling are both exercised.
🤖 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.

Inline comments:
In `@src/main/java/com/meilisearch/sdk/model/StatsQuery.java`:
- Around line 22-29: The StatsQuery.toQuery() serialization currently always
adds sizeFormat, which produces an unwanted null query value when it is unset.
Update toQuery() so it only calls URLBuilder.addParameter("sizeFormat", ...)
when getSizeFormat() is non-null/non-empty, while keeping
showInternalDatabaseSizes behavior unchanged. Use the StatsQuery and URLBuilder
symbols to locate the optional-parameter handling and align it with the new
contract.

---

Nitpick comments:
In `@src/test/java/com/meilisearch/sdk/StatsTest.java`:
- Around line 33-120: Add test coverage in StatsTest for the missing StatsQuery
paths: verify the default/optional case where sizeFormat is not set still
serializes correctly and does not emit a null query value, and add raw-size
response coverage for both client.getStats and client.index("movies").getStats
using numeric size payloads rather than only the human-formatted contract. Use
the existing StatsQuery, getStatsWithQueryParameters,
getIndexStatsWithQueryParameters, and statsQuerySerializesParameters tests as
the place to extend assertions so the serialization bug and raw response
handling are both exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b537f053-e8f8-49e8-b95c-4bb90a6a4576

📥 Commits

Reviewing files that changed from the base of the PR and between acfe026 and 6a752ee.

📒 Files selected for processing (8)
  • .code-samples.meilisearch.yaml
  • src/main/java/com/meilisearch/sdk/Client.java
  • src/main/java/com/meilisearch/sdk/Index.java
  • src/main/java/com/meilisearch/sdk/InstanceHandler.java
  • src/main/java/com/meilisearch/sdk/model/IndexStatsWithSizeFormat.java
  • src/main/java/com/meilisearch/sdk/model/StatsQuery.java
  • src/main/java/com/meilisearch/sdk/model/StatsWithSizeFormat.java
  • src/test/java/com/meilisearch/sdk/StatsTest.java

Comment thread src/main/java/com/meilisearch/sdk/model/StatsQuery.java

@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.

🧹 Nitpick comments (1)
src/test/java/com/meilisearch/sdk/StatsTest.java (1)

114-191: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider extracting shared JSON fixtures/assertions.

getStatsWithRawSizeResponse/getIndexStatsWithRawSizeResponse largely duplicate the structure of getStatsWithQueryParameters/getIndexStatsWithQueryParameters (same JSON shape, same assertions, just numeric vs. string values). A small helper (e.g., parameterizing size values or extracting a common request/response verification method) would reduce duplication, but the current tests are correct and readable as-is.

🤖 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 `@src/test/java/com/meilisearch/sdk/StatsTest.java` around lines 114 - 191, The
two new stats tests duplicate the same response shape and assertion pattern
already covered by the existing query-parameter tests, so the main issue is
avoidable test repetition. Extract a shared helper in StatsTest for building the
stats JSON and verifying the common fields/request path, or parameterize the
size values so getStatsWithRawSizeResponse and getIndexStatsWithRawSizeResponse
reuse the same setup/assertion logic while keeping the raw-size-specific checks
in place.
🤖 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 `@src/test/java/com/meilisearch/sdk/StatsTest.java`:
- Around line 114-191: The two new stats tests duplicate the same response shape
and assertion pattern already covered by the existing query-parameter tests, so
the main issue is avoidable test repetition. Extract a shared helper in
StatsTest for building the stats JSON and verifying the common fields/request
path, or parameterize the size values so getStatsWithRawSizeResponse and
getIndexStatsWithRawSizeResponse reuse the same setup/assertion logic while
keeping the raw-size-specific checks in place.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bb971aea-61b1-46d3-b4db-55c4791d676a

📥 Commits

Reviewing files that changed from the base of the PR and between 6a752ee and 9a1fa20.

📒 Files selected for processing (2)
  • src/main/java/com/meilisearch/sdk/model/StatsQuery.java
  • src/test/java/com/meilisearch/sdk/StatsTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/meilisearch/sdk/model/StatsQuery.java

@Moustafa-Ameen

Copy link
Copy Markdown
Author

Thanks for the review. Since the duplicated setup keeps the raw-size and human-size cases explicit and readable, I’ll leave this as-is for now unless maintainers prefer a helper-based refactor.

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