From 9d39e1b39702debc4a0c9c64651fa92be66d6444 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Fri, 8 Dec 2023 18:11:18 +0900 Subject: [PATCH] minor improvments for simian army --- quickwit/quickwit-common/src/rate_limiter.rs | 13 +++++++++++++ quickwit/quickwit-rest-client/src/lib.rs | 4 ++++ quickwit/quickwit-rest-client/src/rest_client.rs | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/quickwit/quickwit-common/src/rate_limiter.rs b/quickwit/quickwit-common/src/rate_limiter.rs index ddcb3c1baae..4b93e4045b2 100644 --- a/quickwit/quickwit-common/src/rate_limiter.rs +++ b/quickwit/quickwit-common/src/rate_limiter.rs @@ -101,6 +101,19 @@ impl RateLimiter { } } + pub fn acquire_with_duration(&mut self, num_permits: u64) -> Option { + if self.acquire_inner(num_permits) { + return None; + } + self.refill(Instant::now()); + if self.acquire_inner(num_permits) { + return None; + } + let missing = num_permits - self.available_permits; + let wait = Duration::from_micros(missing * self.refill_period_micros / self.refill_amount); + Some(wait) + } + pub fn acquire_bytes(&mut self, bytes: ByteSize) -> bool { self.acquire(bytes.as_u64()) } diff --git a/quickwit/quickwit-rest-client/src/lib.rs b/quickwit/quickwit-rest-client/src/lib.rs index 6c6d442d188..0039452261a 100644 --- a/quickwit/quickwit-rest-client/src/lib.rs +++ b/quickwit/quickwit-rest-client/src/lib.rs @@ -29,6 +29,10 @@ pub mod error; pub mod models; pub mod rest_client; +// re-exports +pub use quickwit_config::ConfigFormat; +pub use reqwest::Url; + pub(crate) struct BatchLineReader { buf_reader: BufReader>, buffer: Vec, diff --git a/quickwit/quickwit-rest-client/src/rest_client.rs b/quickwit/quickwit-rest-client/src/rest_client.rs index 6b333131b93..3d08ddf3be7 100644 --- a/quickwit/quickwit-rest-client/src/rest_client.rs +++ b/quickwit/quickwit-rest-client/src/rest_client.rs @@ -329,11 +329,12 @@ impl<'a> IndexClient<'a> { pub async fn create( &self, - body: Bytes, + index_config: &str, config_format: ConfigFormat, overwrite: bool, ) -> Result { let header_map = header_from_config_format(config_format); + let body = bytes::Bytes::from(index_config.to_string()); let response = self .transport .send(