Skip to content
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

fix: add max_log_length APIs and use missing configs #956

Merged
merged 3 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,4 @@ jobs:
wasm-pack test --headless --firefox
wasm-pack test --headless --chrome
pkill substrate
working-directory: wasm-tests
working-directory: tests/wasm-tests
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[workspace]
members = [
"examples",
"benches",
"server",
"test-utils",
"jsonrpsee",
"tests",
"types",
"core",
"client/ws-client",
"client/http-client",
"client/transport",
"client/wasm-client",
"client/ws-client",
"core",
"examples",
"jsonrpsee",
"proc-macros",
"wasm-tests",
"server",
"test-utils",
"tests",
"tests/wasm-tests",
"types",
]
resolver = "2"
25 changes: 15 additions & 10 deletions client/http-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,23 @@ impl HttpClientBuilder {

/// Build the HTTP client with target to connect to.
pub fn build(self, target: impl AsRef<str>) -> Result<HttpClient, Error> {
let transport = HttpTransportClient::new(
target,
self.max_request_body_size,
self.certificate_store,
self.max_log_length,
self.headers,
)
.map_err(|e| Error::Transport(e.into()))?;
let Self {
max_request_body_size,
max_concurrent_requests,
request_timeout,
certificate_store,
id_kind,
headers,
max_log_length,
} = self;

let transport =
HttpTransportClient::new(target, max_request_body_size, certificate_store, max_log_length, headers)
.map_err(|e| Error::Transport(e.into()))?;
Ok(HttpClient {
transport,
id_manager: Arc::new(RequestIdManager::new(self.max_concurrent_requests, self.id_kind)),
request_timeout: self.request_timeout,
id_manager: Arc::new(RequestIdManager::new(max_concurrent_requests, id_kind)),
request_timeout,
})
}
}
Expand Down
39 changes: 24 additions & 15 deletions client/wasm-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use std::time::Duration;

use jsonrpsee_client_transport::web;
use jsonrpsee_core::client::{ClientBuilder, IdKind};
use jsonrpsee_core::{Error, TEN_MB_SIZE_BYTES};
use jsonrpsee_core::Error;

/// Builder for [`Client`].
///
Expand All @@ -59,34 +59,28 @@ use jsonrpsee_core::{Error, TEN_MB_SIZE_BYTES};
/// }
///
/// ```
#[derive(Clone, Debug)]
#[derive(Copy, Clone, Debug)]
pub struct WasmClientBuilder {
max_request_body_size: u32,
request_timeout: Duration,
id_kind: IdKind,
max_concurrent_requests: usize,
max_notifs_per_subscription: usize,
id_kind: IdKind,
max_log_length: u32,
request_timeout: Duration,
}

impl Default for WasmClientBuilder {
fn default() -> Self {
Self {
max_request_body_size: TEN_MB_SIZE_BYTES,
request_timeout: Duration::from_secs(60),
id_kind: IdKind::Number,
max_log_length: 4096,
max_concurrent_requests: 256,
max_notifs_per_subscription: 1024,
id_kind: IdKind::Number,
request_timeout: Duration::from_secs(60),
}
}
}

impl WasmClientBuilder {
/// Max request body size.
pub fn max_request_body_size(mut self, size: u32) -> Self {
self.max_request_body_size = size;
self
}

/// See documentation [`ClientBuilder::request_timeout`] (default is 60 seconds).
pub fn request_timeout(mut self, timeout: Duration) -> Self {
self.request_timeout = timeout;
Expand All @@ -111,11 +105,26 @@ impl WasmClientBuilder {
self
}

/// Set maximum length for logging calls and responses.
///
/// Logs bigger than this limit will be truncated.
pub fn set_max_logging_length(mut self, max: u32) -> Self {
self.max_log_length = max;
self
}

/// Build the client with specified URL to connect to.
pub async fn build(self, url: impl AsRef<str>) -> Result<Client, Error> {
let Self { max_log_length, id_kind, request_timeout, max_concurrent_requests, max_notifs_per_subscription } =
self;
let (sender, receiver) = web::connect(url).await.map_err(|e| Error::Transport(e.into()))?;

let builder = ClientBuilder::default();
let builder = ClientBuilder::default()
.set_max_logging_length(max_log_length)
.request_timeout(request_timeout)
.id_format(id_kind)
.max_notifs_per_subscription(max_notifs_per_subscription)
.max_concurrent_requests(max_concurrent_requests);

Ok(builder.build_with_wasm(sender, receiver))
}
Expand Down
45 changes: 35 additions & 10 deletions client/ws-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub struct WsClientBuilder {
max_notifs_per_subscription: usize,
max_redirections: usize,
id_kind: IdKind,
max_log_length: u32,
}

impl Default for WsClientBuilder {
Expand All @@ -100,6 +101,7 @@ impl Default for WsClientBuilder {
max_notifs_per_subscription: 1024,
max_redirections: 5,
id_kind: IdKind::Number,
max_log_length: 4096,
}
}
}
Expand Down Expand Up @@ -165,31 +167,54 @@ impl WsClientBuilder {
self
}

/// Set maximum length for logging calls and responses.
///
/// Logs bigger than this limit will be truncated.
pub fn set_max_logging_length(mut self, max: u32) -> Self {
self.max_log_length = max;
self
}

/// Build the client with specified URL to connect to.
/// You must provide the port number in the URL.
///
/// ## Panics
///
/// Panics if being called outside of `tokio` runtime context.
pub async fn build(self, url: impl AsRef<str>) -> Result<WsClient, Error> {
let Self {
certificate_store,
max_concurrent_requests,
max_request_body_size,
request_timeout,
connection_timeout,
ping_interval,
headers,
max_redirections,
max_notifs_per_subscription,
id_kind,
max_log_length,
} = self;

let transport_builder = WsTransportClientBuilder {
certificate_store: self.certificate_store,
connection_timeout: self.connection_timeout,
headers: self.headers,
max_request_body_size: self.max_request_body_size,
max_redirections: self.max_redirections,
certificate_store,
connection_timeout,
headers,
max_request_body_size,
max_redirections,
};

let uri: Uri = url.as_ref().parse().map_err(|e: InvalidUri| Error::Transport(e.into()))?;
let (sender, receiver) = transport_builder.build(uri).await.map_err(|e| Error::Transport(e.into()))?;

let mut client = ClientBuilder::default()
.max_notifs_per_subscription(self.max_notifs_per_subscription)
.request_timeout(self.request_timeout)
.max_concurrent_requests(self.max_concurrent_requests)
.id_format(self.id_kind);
.max_notifs_per_subscription(max_notifs_per_subscription)
.request_timeout(request_timeout)
.max_concurrent_requests(max_concurrent_requests)
.id_format(id_kind)
.set_max_logging_length(max_log_length);

if let Some(interval) = self.ping_interval {
if let Some(interval) = ping_interval {
client = client.ping_interval(interval);
}

Expand Down
1 change: 1 addition & 0 deletions core/src/client/async_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ impl ClientBuilder {
self.max_log_length = max;
self
}

/// Set the interval at which pings frames are submitted (disabled by default).
///
/// Periodically submitting pings at a defined interval has mainly two benefits:
Expand Down
8 changes: 8 additions & 0 deletions server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,14 @@ impl<B, L> Builder<B, L> {
self
}

/// Set maximum length for logging calls and responses.
///
/// Logs bigger than this limit will be truncated.
pub fn set_max_logging_length(mut self, max: u32) -> Self {
self.settings.max_log_length = max;
self
}

/// Finalize the configuration of the server. Consumes the [`Builder`].
///
/// ```rust
Expand Down
13 changes: 13 additions & 0 deletions tests/wasm-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "wasm-test"
version = "0.1.0"
edition = "2021"

[dev-dependencies]
wasm-bindgen-test = "0.3.24"
tracing-wasm = "0.2.1"
console_error_panic_hook = "0.1.7"
serde_json = "1.0.57"
jsonrpsee-wasm-client = { path = "../../client/wasm-client" }
jsonrpsee-core = { path = "../../core" , features = ["client"] }
jsonrpsee-client-transport = { path = "../../client/transport", features = ["web"] }
File renamed without changes.
13 changes: 0 additions & 13 deletions wasm-tests/Cargo.toml

This file was deleted.