-
Notifications
You must be signed in to change notification settings - Fork 108
added the logs api #760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
valkrypton
wants to merge
1
commit into
meilisearch:main
Choose a base branch
from
valkrypton:add/logs-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
added the logs api #760
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| use crate::client::Client; | ||
| use crate::errors::Error; | ||
| use bytes::Bytes; | ||
| use futures_core::Stream; | ||
| use serde::Serialize; | ||
|
|
||
| #[derive(Serialize)] | ||
| pub struct NewLogLevel { | ||
| pub target: String, | ||
| } | ||
|
|
||
| #[derive(Serialize)] | ||
| pub struct LogStreamRequest { | ||
| pub target: String, | ||
| pub mode: LogMode, | ||
| } | ||
|
|
||
| #[derive(Debug, Default, Clone, Copy, Serialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub enum LogMode { | ||
| /// Output the logs in a human-readable form | ||
| #[default] | ||
| Human, | ||
| /// Output the logs in JSON format | ||
| Json, | ||
| /// Output the logs in Firefox profiler format for visualization | ||
| Profile, | ||
| } | ||
|
|
||
| impl Client<crate::reqwest::ReqwestClient> { | ||
| /// Opens a continuous stream of logs for focused debugging sessions. | ||
| /// The stream will continue to run indefinitely until you | ||
| /// [interrupt](Client::interrupt_log_stream) it. | ||
| /// | ||
| /// The function returns a [`Stream`] that you can iterate over with | ||
| /// the [`StreamExt`] trait to process the logs. | ||
| /// | ||
| /// # Example | ||
| /// | ||
| /// ``` | ||
| /// # use meilisearch_sdk::{client::*, logs::*}; | ||
| /// # | ||
| /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); | ||
| /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); | ||
| /// # | ||
| /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async { | ||
| /// # 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(); | ||
| ///# }); | ||
| /// ``` | ||
| pub async fn open_log_stream( | ||
| &self, | ||
| get_logs: LogStreamRequest, | ||
| ) -> Result<impl Stream<Item = Result<Bytes, reqwest::Error>>, Error> { | ||
| let res = self | ||
| .http_client | ||
| .inner() | ||
| .post(format!("{}/logs/stream", self.host)) | ||
| .header("Content-Type", "application/json") | ||
| .body(serde_json::to_string(&get_logs)?) | ||
| .send() | ||
| .await?; | ||
| res.error_for_status_ref()?; | ||
| Ok(res.bytes_stream()) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use meilisearch_test_macro::meilisearch_test; | ||
| #[meilisearch_test] | ||
| async fn test_open_log_stream(client: Client) { | ||
| let logs_config = LogStreamRequest { | ||
| mode: LogMode::Human, | ||
| target: "info".to_string(), | ||
| }; | ||
| assert!(client.open_log_stream(logs_config).await.is_ok()); | ||
| assert!(client.interrupt_log_stream().await.is_ok()); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix type name and variable typo so the sample compiles.
GetLogsdoesn’t exist in the new API surface andbyte_sis undefined.🔧 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents