Skip to content

Conversation

kumarUjjawal
Copy link
Contributor

@kumarUjjawal kumarUjjawal commented Sep 22, 2025

Pull Request

This PR aims to bring the SDK close to the Mealisearch Meilisearch 1.19 features and add support for sharding .

Related issue

Fixes #700

What does this PR do?

As per the tasks described in the origina issue #700

  • Update the Network methods to accept sending the sharding parameter

  • Update the Network methods to include remotes.[remoteName].writeApiKey in the responses

  • Update the Tasks methods to include remotes objects in the tasks reponse index update method to allow renaming

  • Add new test cases to test implementation

PR checklist

Please check if your PR fulfills the following requirements:

  • 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?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • New Features

    • Manage network configuration from the client: view/update network state, toggle sharding, and set the local remote.
    • Public Network module exposing remotes, self identity, and sharding configuration.
    • Multi-search federation options can target a specific remote.
  • Improvements

    • Task details (enqueued, processing, succeeded) now include remotes information when available.
  • Tests

    • Added tests for network updates and task deserialization with remotes.

Copy link

codecov bot commented Sep 22, 2025

Codecov Report

❌ Patch coverage is 82.69231% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.84%. Comparing base (910f9e9) to head (d27dbed).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
src/client.rs 75.00% 16 Missing ⚠️
src/tasks.rs 94.87% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #709      +/-   ##
==========================================
- Coverage   85.89%   85.84%   -0.06%     
==========================================
  Files          19       19              
  Lines        5950     6054     +104     
==========================================
+ Hits         5111     5197      +86     
- Misses        839      857      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

coderabbitai bot commented Sep 23, 2025

Walkthrough

Adds a public network module with DTOs, implements GET/PATCH /network client endpoints plus convenience setters, extends query federation options with remote, adds optional remotes to task structs, and includes unit tests for network and task behaviors.

Changes

Cohort / File(s) Summary of changes
Network API client endpoints
src/client.rs
Adds get_network_state, update_network_state, set_sharding, set_self_remote; imports NetworkState/NetworkUpdate; adds unit test mocking PATCH /network.
Public module wiring
src/lib.rs
Exposes pub mod network.
Network types and DTOs
src/network.rs
Adds RemoteConfig, RemotesMap, NetworkState, NetworkUpdate with serde camelCase renames and optional fields (writeApiKey, self, sharding, remotes).
Search federation option extension
src/search.rs
Adds remote: Option<String> to QueryFederationOptions; initializes remote: None in MultiSearchQuery::with_search_query_and_weight.
Tasks remotes field
src/tasks.rs
Adds remotes: Option<Map<String, Value>> to SucceededTask, EnqueuedTask, ProcessingTask; imports serde_json::{Map, Value}; adds deserialization tests for tasks with remotes.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Dev as Caller
    participant C as Client
    participant H as HttpClient
    participant S as Meilisearch Server

    rect rgb(240,245,255)
    note over Dev,C: Read network state
    Dev->>C: get_network_state()
    C->>H: GET /network
    H->>S: GET /network
    S-->>H: 200 NetworkState
    H-->>C: NetworkState
    C-->>Dev: NetworkState
    end

    rect rgb(240,255,240)
    note over Dev,C: Update sharding / self remote
    Dev->>C: set_sharding(enabled) / set_self_remote(name)
    C->>C: Build NetworkUpdate
    C->>H: PATCH /network (NetworkUpdate)
    H->>S: PATCH /network
    alt success
      S-->>H: 200 NetworkState
      H-->>C: NetworkState
      C-->>Dev: NetworkState
    else error
      S-->>H: 4xx/5xx Error
      H-->>C: Error
      C-->>Dev: Error
    end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Poem

I hop through bytes where network threads twine,
I stitch sharding seams with a carrot and line.
Remotes gather round in a soft, coded cheer,
Tasks carry messages I nudge in the rear.
A rabbit-sized patch — the meadow’s now clear. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues Check ✅ Passed The PR implements the linked issue #700 requirements: network endpoints accept and send the sharding parameter (NetworkUpdate and set_sharding), RemoteConfig now includes writeApiKey for remotes in NetworkState responses, task detail structs include remotes with accompanying deserialization tests, and unit tests were added to validate the behavior.
Out of Scope Changes Check ✅ Passed All modifications appear in-scope for sharding support and related API updates: new network module/types, client network methods, task remotes fields, tests, and a small QueryFederationOptions.remote addition that aligns with sharding/federation needs; I do not see unrelated or out-of-scope file changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the primary intent of the pull request, which is to add sharding support to the network-related methods, without extraneous detail, making it clear and specific.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (4)
src/tasks.rs (2)

773-798: New test: processing task with remotes — LGTM; consider also covering SucceededTask.

Add a small test case for the succeeded variant to fully cover the three task kinds.


800-803: Redundant use super::*; import

This second import is unnecessary. Remove to reduce noise.

-    use super::*;
src/client.rs (2)

1251-1293: Test for network update and remotes deserialization — LGTM

Good assertion on writeApiKey. Consider adding a test for set_self_remote() and one for GET /network.


1152-1190: Network endpoints: GET/PATCH /network — PATCH returns 200 OK (verified)
Docs for Meilisearch v1.19 confirm PATCH /network returns 200 OK; no change needed to the response code.

  • Optional: add a small helper to update remotes (e.g., set_remotes(...)) and a unit test for set_self_remote.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 910f9e9 and d4c2866.

📒 Files selected for processing (5)
  • src/client.rs (3 hunks)
  • src/lib.rs (1 hunks)
  • src/network.rs (1 hunks)
  • src/search.rs (2 hunks)
  • src/tasks.rs (6 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-12T13:28:23.700Z
Learnt from: LukasKalbertodt
PR: meilisearch/meilisearch-rust#625
File: src/search.rs:368-370
Timestamp: 2025-06-12T13:28:23.700Z
Learning: In the Meilisearch Rust client, `SearchQuery` serializes its per-query federation settings under the key `federationOptions`; only the top-level multi-search parameter is named `federation`.

Applied to files:

  • src/search.rs
🧬 Code graph analysis (2)
src/client.rs (2)
src/request.rs (1)
  • body (49-56)
src/features.rs (1)
  • update (102-114)
src/search.rs (1)
src/client.rs (2)
  • None (1283-1283)
  • None (1362-1362)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: integration-tests
🔇 Additional comments (9)
src/lib.rs (1)

247-249: Expose network module publicly — LGTM

Makes the new network API available at meilisearch_sdk::network.

src/search.rs (2)

769-775: Initialize remote: None — LGTM

Keeps previous behavior while allowing future remote selection.


418-424: Confirmed: per-query remote belongs under federationOptions (resolved)

Confirmed — Meilisearch v1.19 expects a per-query string at queries[].federationOptions.remote. Example:
{ "federation": {}, "queries": [ { "indexUid":"movies","q":"batman","federationOptions":{"remote":"ms-00"} }, { "indexUid":"movies","q":"batman","federationOptions":{"remote":"ms-01"} } ] }

Optional: add a convenience helper (e.g., with_search_query_and_remote) to mirror with_search_query_and_weight.

src/tasks.rs (5)

2-2: Import for serde_json::{Map, Value} — LGTM

Required for flexible remotes payloads.


161-164: Add remotes to SucceededTask — LGTM

Optional and skipped when absent; compatible with 1.19 responses.


181-184: Add remotes to EnqueuedTask — LGTM

Matches server behavior for enqueued tasks.


203-206: Add remotes to ProcessingTask — LGTM

Matches server behavior for processing tasks.


753-771: New test: enqueued task with remotes — LGTM

Covers the new field.

src/client.rs (1)

11-12: Import network types — LGTM

Wires client to the new network module.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/tasks.rs (4)

2-2: Import looks good; consider a shared type alias for reuse.

Define a crate-wide alias to keep the shape consistent across modules (tasks/network) and ease future refactors:

For example:

pub type Remotes = serde_json::Map<String, serde_json::Value>;

Then use Option<Remotes> for these fields.


161-164: Add remotes field: OK; verify potential secret exposure in Debug output.

  • If task remotes can include secrets (e.g., writeApiKey), #[derive(Debug)] will print them. Consider redaction (custom Debug/newtype) or documenting that these structs may contain sensitive data.
  • Also, add a test for Succeeded (and possibly Failed) variants containing remotes for parity.

749-770: Good coverage for enqueued; add a stronger assertion.

Also assert nested value equality to ensure structure is preserved, and consider adding a Succeeded/Failed counterpart test.

Example:

let ms00 = remotes.get("ms-00").unwrap();
assert_eq!(ms00.get("status").and_then(|v| v.as_str()), Some("ok"));

772-797: Processing test looks good; mirror stronger assertion.

Add a direct check on the nested "status" value, similar to the enqueued test suggestion.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b07f76 and d27dbed.

📒 Files selected for processing (1)
  • src/tasks.rs (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: integration-tests
🔇 Additional comments (3)
src/tasks.rs (3)

181-184: Same concerns as in SucceededTask.

Duplicate of earlier comment: verify secret exposure via Debug; consider redaction and add a Succeeded/Failed test for remotes.


203-206: Same concerns as in SucceededTask.

Duplicate of earlier comment: verify secret exposure via Debug; consider redaction and add a Succeeded/Failed test for remotes.


843-843: Pattern updated with .. to tolerate new fields — LGTM.

Prevents fragile test matches after adding remotes.

@kumarUjjawal
Copy link
Contributor Author

@curquiza could you take a look when you get the time.

@curquiza curquiza added the enhancement New feature or request label Oct 7, 2025
Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

bors merge

Copy link
Contributor

meili-bors bot commented Oct 7, 2025

@meili-bors meili-bors bot merged commit 5e84bdf into meilisearch:main Oct 7, 2025
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v1.19.0] Add sharding support

2 participants