Skip to content

added the logs api#760

Open
valkrypton wants to merge 1 commit into
meilisearch:mainfrom
valkrypton:add/logs-api
Open

added the logs api#760
valkrypton wants to merge 1 commit into
meilisearch:mainfrom
valkrypton:add/logs-api

Conversation

@valkrypton
Copy link
Copy Markdown

@valkrypton valkrypton commented Jan 30, 2026

Pull Request

Related issue

Fixes #759

What does this PR do?

  • Adds a new module logs that defines the LogMode enum, and LogStreamRequest required for the /logs/stream endpoint.
  • Also adds a NewLogLevel struct used in the /logs/stderr endpoint to customise the log level.
  • Adds customize_log_levels, interrupt_log_stream, and open_log_stream methods to Client for logs related operations.

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

    • Configure log levels for targets.
    • Start real-time log streaming with Human/JSON/Profile formats.
    • Interrupt active log streams.
  • Documentation

    • Added public code samples demonstrating logging configuration, streaming, and interruption.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 30, 2026

📝 Walkthrough

Walkthrough

Adds a new logs module and three public client APIs to support log streaming and control: open_log_stream, customize_log_levels, and interrupt_log_stream. Includes new data types for log requests and accompanying code samples.

Changes

Cohort / File(s) Summary
Code Samples
\.code-samples\.meilisearch\.yaml
Added three new samples demonstrating customize_log_levels_1, open_log_stream_1, and interrupt_log_stream_1.
Module Exports
src/lib.rs
Added public logs module and consolidated reqwest module declaration under the reqwest feature flag (removed duplicate).
Client API Methods
src/client.rs
Added two public async methods on Client<Http>: customize_log_levels(NewLogLevel) (POST /logs/stderr) and interrupt_log_stream() (DELETE /logs/stream).
Logging Implementation
src/logs.rs
New module defining NewLogLevel, LogStreamRequest, LogMode (Human/Json/Profile with serde camelCase), and open_log_stream() which POSTs /logs/stream and returns a bytes stream. Includes docs example and a test.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client (Rust)
    participant Reqwest as Reqwest HTTP Client
    participant Meili as Meilisearch API
    participant Network as Network Stream

    Client->>Reqwest: open_log_stream(LogStreamRequest)
    Reqwest->>Reqwest: serialize JSON, set Content-Type: application/json
    Reqwest->>Meili: POST /logs/stream
    Meili->>Network: accept streaming connection
    Network-->>Reqwest: streaming response (bytes)
    Reqwest-->>Client: Stream<Item = Result<Bytes>>
    Client->>Client: iterate/process chunks
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped to the stream where log-bytes play,
Human, Json, Profile — pick your way,
Post, delete, and listen all day long,
A rabbit's small cheer for a streaming song!

🚥 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 'added the logs api' directly summarizes the main change, which is adding a new logs API module with related methods to the Rust client.
Linked Issues check ✅ Passed The PR implements all key objectives from #759: the logs module with LogMode/LogStreamRequest, NewLogLevel for log customization, and Client methods (open_log_stream, customize_log_levels, interrupt_log_stream) matching the required API surface.
Out of Scope Changes check ✅ Passed The conditional feature gating of the reqwest module in lib.rs is a minor refactor supporting the new logs API implementation and is within scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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
Copy Markdown
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

🤖 Fix all issues with AI agents
In @.code-samples.meilisearch.yaml:
- Around line 2081-2092: Replace the invalid type and variable names so the
sample compiles: swap the old GetLogs type for the current API name (e.g.,
GetLogsConfig or GetLogsOptions as exported by the crate) and construct
logs_config with that type, and fix the typo by using the byte_stream variable
returned from client.open_log_stream(...) (change byte_s.for_each to
byte_stream.for_each) while keeping the same closure logic; references: GetLogs,
logs_config, open_log_stream, byte_stream, byte_s.

In `@src/logs.rs`:
- Around line 73-86: The test test_open_log_stream creates a hardcoded client
via Client::new("http://localhost:7700", Some("secret")), which bypasses the
meilisearch_test harness; replace that creation with the macro-injected Client
provided by meilisearch_test (i.e., use the Client instance the macro supplies
rather than calling Client::new) so the test uses the harness-managed server;
keep the rest of the test (LogStreamRequest, logs_config, and the
open_log_stream assertion) unchanged.
- Around line 30-70: The open_log_stream method on Client currently starts
streaming with res.bytes_stream() without checking HTTP status; call
.error_for_status_ref()? on the Response returned by
self.http_client.inner().post(...).body(...).send().await to surface non-2xx
errors before converting to a byte stream, then call .bytes_stream() on the
checked Response (ensure you use error_for_status_ref() so the Response is not
consumed), keeping function signature and returning the stream as before.

Comment on lines +2081 to +2092
use futures::StreamExt;
let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
let logs_config = GetLogs {
target: "info".to_string(),
mode: LogMode::Human
};
let byte_stream = client.open_log_stream(logs_config).await.unwrap();
byte_s.for_each(|chunk| async {
if let Ok(chunk) = chunk {
println!("{}", String::from_utf8_lossy(&chunk));
}
}).await;
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.

⚠️ Potential issue | 🟡 Minor

Fix type name and variable typo so the sample compiles.
GetLogs doesn’t exist in the new API surface and byte_s is undefined.

🔧 Proposed fix
-  let logs_config = GetLogs {
+  let logs_config = LogStreamRequest {
     target: "info".to_string(),
     mode: LogMode::Human
   };
   let byte_stream = client.open_log_stream(logs_config).await.unwrap();
-  byte_s.for_each(|chunk| async {
+  byte_stream.for_each(|chunk| async {
       if let Ok(chunk) = chunk {
         println!("{}", String::from_utf8_lossy(&chunk));
       }
   }).await;
📝 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
use futures::StreamExt;
let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
let logs_config = GetLogs {
target: "info".to_string(),
mode: LogMode::Human
};
let byte_stream = client.open_log_stream(logs_config).await.unwrap();
byte_s.for_each(|chunk| async {
if let Ok(chunk) = chunk {
println!("{}", String::from_utf8_lossy(&chunk));
}
}).await;
use futures::StreamExt;
let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
let logs_config = LogStreamRequest {
target: "info".to_string(),
mode: LogMode::Human
};
let byte_stream = client.open_log_stream(logs_config).await.unwrap();
byte_stream.for_each(|chunk| async {
if let Ok(chunk) = chunk {
println!("{}", String::from_utf8_lossy(&chunk));
}
}).await;
🤖 Prompt for AI Agents
In @.code-samples.meilisearch.yaml around lines 2081 - 2092, Replace the invalid
type and variable names so the sample compiles: swap the old GetLogs type for
the current API name (e.g., GetLogsConfig or GetLogsOptions as exported by the
crate) and construct logs_config with that type, and fix the typo by using the
byte_stream variable returned from client.open_log_stream(...) (change
byte_s.for_each to byte_stream.for_each) while keeping the same closure logic;
references: GetLogs, logs_config, open_log_stream, byte_stream, byte_s.

Comment thread src/logs.rs
Comment thread src/logs.rs
@valkrypton
Copy link
Copy Markdown
Author

@Strift can someone review this?

@Strift Strift added the enhancement New feature or request label Mar 17, 2026
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.

Add the /logs api

2 participants