Skip to content

Add stats size format options#979

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

Add stats size format options#979
Moustafa-Ameen wants to merge 1 commit 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 support for retrieving enhanced stats at both the app-wide and index levels.
  • Bug Fixes

    • Updated stats examples to use the new query-based approach.
    • Improved parsing of stats responses that include size-related values and nested database details.
  • Tests

    • Added coverage for stats query serialization and response handling for both global and index stats.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a StatsQuery model to pass showInternalDatabaseSizes and sizeFormat parameters to Meilisearch stats endpoints, introduces StatsWithSizeFormat/IndexStatsWithSizeFormat response models, adds corresponding getStats overloads on Client/Index/InstanceHandler, and updates tests and code samples.

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
New StatsQuery model with chainable setters/getters and toQuery() serialization; new StatsWithSizeFormat and IndexStatsWithSizeFormat models representing size fields as Object to support raw or human-readable formats.
InstanceHandler stats retrieval with query params
src/main/java/com/meilisearch/sdk/InstanceHandler.java
Replaces getStats()/getIndexStats(uid) with overloads accepting StatsQuery, building URLs with optional toQuery() params and returning the new size-format response types.
Client and Index public getStats overloads
src/main/java/com/meilisearch/sdk/Client.java, src/main/java/com/meilisearch/sdk/Index.java
Adds public getStats(StatsQuery params) overloads delegating to InstanceHandler.
Tests and code samples
src/test/java/com/meilisearch/sdk/StatsTest.java, .code-samples.meilisearch.yaml
New StatsTest verifies query serialization and parsed responses; code samples updated to demonstrate StatsQuery usage.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related issues

Poem

A rabbit hops through stats so bright,
With human sizes, oh what a sight!
StatsQuery in paw, params to send,
Internal sizes 'round every bend.
Thump thump — the tests all pass tonight! 🐇✨

🚥 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 describes the main change: adding stats size format options.
Linked Issues check ✅ Passed The PR adds the new stats query params, updates both stats methods and models, adds tests, and refreshes the required code samples.
Out of Scope Changes check ✅ Passed No unrelated code changes stand out; the diff aligns with the stats API and documentation updates requested.
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 on lines +22 to +29
public String toQuery() {
URLBuilder urlb =
new URLBuilder()
.addParameter(
"showInternalDatabaseSizes",
this.getShowInternalDatabaseSizes())
.addParameter("sizeFormat", this.getSizeFormat());
return urlb.getURL();

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Omit sizeFormat when it is unset.

Line 28 always passes sizeFormat into URLBuilder, but that helper only skips empty strings. With new StatsQuery() or new StatsQuery().setShowInternalDatabaseSizes(true), this serializes as ?sizeFormat=null, which violates the new optional-parameter contract and breaks the request.

Proposed fix
     public String toQuery() {
-        URLBuilder urlb =
-                new URLBuilder()
-                        .addParameter(
-                                "showInternalDatabaseSizes",
-                                this.getShowInternalDatabaseSizes())
-                        .addParameter("sizeFormat", this.getSizeFormat());
+        URLBuilder urlb =
+                new URLBuilder()
+                        .addParameter(
+                                "showInternalDatabaseSizes",
+                                this.getShowInternalDatabaseSizes());
+        if (this.getSizeFormat() != null && !this.getSizeFormat().isEmpty()) {
+            urlb.addParameter("sizeFormat", this.getSizeFormat());
+        }
         return urlb.getURL();
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public String toQuery() {
URLBuilder urlb =
new URLBuilder()
.addParameter(
"showInternalDatabaseSizes",
this.getShowInternalDatabaseSizes())
.addParameter("sizeFormat", this.getSizeFormat());
return urlb.getURL();
public String toQuery() {
URLBuilder urlb =
new URLBuilder()
.addParameter(
"showInternalDatabaseSizes",
this.getShowInternalDatabaseSizes());
if (this.getSizeFormat() != null && !this.getSizeFormat().isEmpty()) {
urlb.addParameter("sizeFormat", this.getSizeFormat());
}
return urlb.getURL();
}
🤖 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/main/java/com/meilisearch/sdk/model/StatsQuery.java` around lines 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.

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