Skip to content

Commit 7a07003

Browse files
committed
feat: clean up code formatting and improve readability in various modules
1 parent 71eeb46 commit 7a07003

9 files changed

Lines changed: 67 additions & 102 deletions

File tree

crates/http-backend/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ use tokio::net::TcpStream;
2020
use tower_service::Service;
2121
use tracing::{debug, trace, warn};
2222

23+
use crate::stats::{ExtRequestStats, ExtStatsTimer};
2324
use reactor::gcore::fastedge::http::Headers;
2425
use reactor::gcore::fastedge::{
2526
http::{Error as HttpError, Method, Request, Response},
2627
http_client::Host,
2728
};
28-
use crate::stats::{ExtRequestStats, ExtStatsTimer};
2929

3030
type HeaderNameList = Vec<HeaderName>;
3131

@@ -58,7 +58,7 @@ pub struct Backend<C> {
5858
propagate_header_names: HeaderNameList,
5959
max_sub_requests: usize,
6060
pub strategy: BackendStrategy,
61-
ext_http_stats: Option<Arc<dyn ExtRequestStats>>
61+
ext_http_stats: Option<Arc<dyn ExtRequestStats>>,
6262
}
6363

6464
pub struct Builder {
@@ -296,7 +296,10 @@ where
296296
})?;
297297

298298
// start external request stats timer
299-
let _stats_timer = self.ext_http_stats.as_ref().map(|s| ExtStatsTimer::new(s.clone()));
299+
let _stats_timer = self
300+
.ext_http_stats
301+
.as_ref()
302+
.map(|s| ExtStatsTimer::new(s.clone()));
300303

301304
let res = self.client.request(request).await.map_err(|error| {
302305
warn!(cause=?error, "sending request to backend");

crates/http-backend/src/stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ impl Drop for ExtStatsTimer {
4747
self.observe()
4848
}
4949
}
50-
}
50+
}

crates/http-service/src/executor/http.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ mod tests {
182182
};
183183
use bytes::Bytes;
184184
use claims::*;
185-
use utils::{Dictionary, UserDiagStats};
185+
use http_backend::stats::ExtRequestStats;
186186
use http_backend::{Backend, BackendStrategy, FastEdgeConnector};
187187
use http_body_util::Empty;
188188
use key_value_store::ReadStats;
@@ -197,9 +197,9 @@ mod tests {
197197
use secret::SecretStore;
198198
use smol_str::{SmolStr, ToSmolStr};
199199
use std::collections::HashMap;
200+
use utils::{Dictionary, UserDiagStats};
200201
use wasmtime::component::Component;
201202
use wasmtime::{Engine, Module};
202-
use http_backend::stats::ExtRequestStats;
203203

204204
#[derive(Clone)]
205205
struct TestStats;
@@ -211,13 +211,11 @@ mod tests {
211211
}
212212

213213
impl UserDiagStats for TestStats {
214-
fn set_user_diag(&self, _diag: &str) {
215-
}
214+
fn set_user_diag(&self, _diag: &str) {}
216215
}
217216

218217
impl ExtRequestStats for TestStats {
219-
fn observe_ext(&self, _elapsed: Duration) {
220-
}
218+
fn observe_ext(&self, _elapsed: Duration) {}
221219
}
222220

223221
impl StatsVisitor for TestStats {
@@ -238,8 +236,6 @@ mod tests {
238236
}
239237

240238
fn cdn_phase(&self, _phase: CdnPhase) {}
241-
242-
243239
}
244240

245241
#[derive(Clone)]
@@ -275,10 +271,7 @@ mod tests {
275271
todo!()
276272
}
277273

278-
fn make_key_value_store(
279-
&self,
280-
_stores: &Vec<KvStoreOption>,
281-
) -> key_value_store::Builder {
274+
fn make_key_value_store(&self, _stores: &Vec<KvStoreOption>) -> key_value_store::Builder {
282275
todo!()
283276
}
284277

crates/key-value-store/src/lib.rs

Lines changed: 45 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,13 @@ mod tests {
359359

360360
impl ReadStats for MockReadStats {
361361
fn count_kv_read(&self, value: i32) {
362-
self.kv_reads.fetch_add(value, std::sync::atomic::Ordering::Relaxed);
362+
self.kv_reads
363+
.fetch_add(value, std::sync::atomic::Ordering::Relaxed);
363364
}
364365

365366
fn count_kv_byod_read(&self, value: i32) {
366-
self.byod_reads.fetch_add(value, std::sync::atomic::Ordering::Relaxed);
367+
self.byod_reads
368+
.fetch_add(value, std::sync::atomic::Ordering::Relaxed);
367369
}
368370
}
369371

@@ -392,10 +394,7 @@ mod tests {
392394
param: &str,
393395
_metric: Arc<dyn ReadStats>,
394396
) -> Result<Arc<dyn Store>, Error> {
395-
self.stores
396-
.get(param)
397-
.cloned()
398-
.ok_or(Error::NoSuchStore)
397+
self.stores.get(param).cloned().ok_or(Error::NoSuchStore)
399398
}
400399
}
401400

@@ -407,9 +406,10 @@ mod tests {
407406

408407
#[tokio::test]
409408
async fn test_builder_new() {
410-
let allowed_stores = vec![
411-
(SmolStr::new("store1"), SmolStr::new("redis://localhost:6379")),
412-
];
409+
let allowed_stores = vec![(
410+
SmolStr::new("store1"),
411+
SmolStr::new("redis://localhost:6379"),
412+
)];
413413
let manager = Arc::new(NoSuchStoreManager);
414414
let builder = Builder::new(allowed_stores.clone(), manager);
415415

@@ -421,13 +421,13 @@ mod tests {
421421
async fn test_store_impl_open_allowed_store() {
422422
let mock_store = Arc::new(MockStore::new());
423423
let manager = Arc::new(
424-
MockStoreManager::new()
425-
.with_store("redis://localhost:6379", mock_store.clone())
424+
MockStoreManager::new().with_store("redis://localhost:6379", mock_store.clone()),
426425
);
427426

428-
let allowed_stores = vec![
429-
(SmolStr::new("mystore"), SmolStr::new("redis://localhost:6379")),
430-
];
427+
let allowed_stores = vec![(
428+
SmolStr::new("mystore"),
429+
SmolStr::new("redis://localhost:6379"),
430+
)];
431431
let stats = Arc::new(MockReadStats::new());
432432
let mut store_impl = Builder::new(allowed_stores, manager).build(stats.clone());
433433

@@ -439,9 +439,10 @@ mod tests {
439439
#[tokio::test]
440440
async fn test_store_impl_open_denied_store() {
441441
let manager = Arc::new(NoSuchStoreManager);
442-
let allowed_stores = vec![
443-
(SmolStr::new("allowed"), SmolStr::new("redis://localhost:6379")),
444-
];
442+
let allowed_stores = vec![(
443+
SmolStr::new("allowed"),
444+
SmolStr::new("redis://localhost:6379"),
445+
)];
445446
let stats = Arc::new(MockReadStats::new());
446447
let mut store_impl = Builder::new(allowed_stores, manager).build(stats.clone());
447448

@@ -456,7 +457,7 @@ mod tests {
456457
let manager = Arc::new(
457458
MockStoreManager::new()
458459
.with_store("redis://store1", mock_store1.clone())
459-
.with_store("redis://store2", mock_store2.clone())
460+
.with_store("redis://store2", mock_store2.clone()),
460461
);
461462

462463
let allowed_stores = vec![
@@ -475,16 +476,10 @@ mod tests {
475476

476477
#[tokio::test]
477478
async fn test_get_value_success() {
478-
let mock_store = Arc::new(
479-
MockStore::new().with_data("key1", b"value1".to_vec())
480-
);
481-
let manager = Arc::new(
482-
MockStoreManager::new().with_store("redis://localhost", mock_store)
483-
);
479+
let mock_store = Arc::new(MockStore::new().with_data("key1", b"value1".to_vec()));
480+
let manager = Arc::new(MockStoreManager::new().with_store("redis://localhost", mock_store));
484481

485-
let allowed_stores = vec![
486-
(SmolStr::new("mystore"), SmolStr::new("redis://localhost")),
487-
];
482+
let allowed_stores = vec![(SmolStr::new("mystore"), SmolStr::new("redis://localhost"))];
488483
let stats = Arc::new(MockReadStats::new());
489484
let mut store_impl = Builder::new(allowed_stores, manager).build(stats.clone());
490485

@@ -498,13 +493,9 @@ mod tests {
498493
#[tokio::test]
499494
async fn test_get_value_not_found() {
500495
let mock_store = Arc::new(MockStore::new());
501-
let manager = Arc::new(
502-
MockStoreManager::new().with_store("redis://localhost", mock_store)
503-
);
496+
let manager = Arc::new(MockStoreManager::new().with_store("redis://localhost", mock_store));
504497

505-
let allowed_stores = vec![
506-
(SmolStr::new("mystore"), SmolStr::new("redis://localhost")),
507-
];
498+
let allowed_stores = vec![(SmolStr::new("mystore"), SmolStr::new("redis://localhost"))];
508499
let stats = Arc::new(MockReadStats::new());
509500
let mut store_impl = Builder::new(allowed_stores, manager).build(stats.clone());
510501

@@ -534,18 +525,16 @@ mod tests {
534525
(b"item4".to_vec(), 7.5),
535526
];
536527
let mock_store = Arc::new(MockStore::new().with_zset("sorted_set", items));
537-
let manager = Arc::new(
538-
MockStoreManager::new().with_store("redis://localhost", mock_store)
539-
);
528+
let manager = Arc::new(MockStoreManager::new().with_store("redis://localhost", mock_store));
540529

541-
let allowed_stores = vec![
542-
(SmolStr::new("mystore"), SmolStr::new("redis://localhost")),
543-
];
530+
let allowed_stores = vec![(SmolStr::new("mystore"), SmolStr::new("redis://localhost"))];
544531
let stats = Arc::new(MockReadStats::new());
545532
let mut store_impl = Builder::new(allowed_stores, manager).build(stats.clone());
546533

547534
let store_id = store_impl.open("mystore").await.unwrap();
548-
let result = store_impl.zrange_by_score(store_id, "sorted_set", 2.0, 6.0).await;
535+
let result = store_impl
536+
.zrange_by_score(store_id, "sorted_set", 2.0, 6.0)
537+
.await;
549538

550539
assert!(result.is_ok());
551540
let items = result.unwrap();
@@ -570,15 +559,11 @@ mod tests {
570559
MockStore::new()
571560
.with_data("user:1", b"alice".to_vec())
572561
.with_data("user:2", b"bob".to_vec())
573-
.with_data("post:1", b"hello".to_vec())
574-
);
575-
let manager = Arc::new(
576-
MockStoreManager::new().with_store("redis://localhost", mock_store)
562+
.with_data("post:1", b"hello".to_vec()),
577563
);
564+
let manager = Arc::new(MockStoreManager::new().with_store("redis://localhost", mock_store));
578565

579-
let allowed_stores = vec![
580-
(SmolStr::new("mystore"), SmolStr::new("redis://localhost")),
581-
];
566+
let allowed_stores = vec![(SmolStr::new("mystore"), SmolStr::new("redis://localhost"))];
582567
let stats = Arc::new(MockReadStats::new());
583568
let mut store_impl = Builder::new(allowed_stores, manager).build(stats.clone());
584569

@@ -610,13 +595,9 @@ mod tests {
610595
(b"banana".to_vec(), 3.0),
611596
];
612597
let mock_store = Arc::new(MockStore::new().with_zset("fruits", items));
613-
let manager = Arc::new(
614-
MockStoreManager::new().with_store("redis://localhost", mock_store)
615-
);
598+
let manager = Arc::new(MockStoreManager::new().with_store("redis://localhost", mock_store));
616599

617-
let allowed_stores = vec![
618-
(SmolStr::new("mystore"), SmolStr::new("redis://localhost")),
619-
];
600+
let allowed_stores = vec![(SmolStr::new("mystore"), SmolStr::new("redis://localhost"))];
620601
let stats = Arc::new(MockReadStats::new());
621602
let mut store_impl = Builder::new(allowed_stores, manager).build(stats.clone());
622603

@@ -641,18 +622,12 @@ mod tests {
641622
#[tokio::test]
642623
async fn test_bf_exists_true() {
643624
let mock_store = Arc::new(
644-
MockStore::new().with_bloom(
645-
"bloom_key",
646-
vec!["item1".to_string(), "item2".to_string()],
647-
)
648-
);
649-
let manager = Arc::new(
650-
MockStoreManager::new().with_store("redis://localhost", mock_store)
625+
MockStore::new()
626+
.with_bloom("bloom_key", vec!["item1".to_string(), "item2".to_string()]),
651627
);
628+
let manager = Arc::new(MockStoreManager::new().with_store("redis://localhost", mock_store));
652629

653-
let allowed_stores = vec![
654-
(SmolStr::new("mystore"), SmolStr::new("redis://localhost")),
655-
];
630+
let allowed_stores = vec![(SmolStr::new("mystore"), SmolStr::new("redis://localhost"))];
656631
let stats = Arc::new(MockReadStats::new());
657632
let mut store_impl = Builder::new(allowed_stores, manager).build(stats.clone());
658633

@@ -665,21 +640,18 @@ mod tests {
665640

666641
#[tokio::test]
667642
async fn test_bf_exists_false() {
668-
let mock_store = Arc::new(
669-
MockStore::new().with_bloom("bloom_key", vec!["item1".to_string()])
670-
);
671-
let manager = Arc::new(
672-
MockStoreManager::new().with_store("redis://localhost", mock_store)
673-
);
643+
let mock_store =
644+
Arc::new(MockStore::new().with_bloom("bloom_key", vec!["item1".to_string()]));
645+
let manager = Arc::new(MockStoreManager::new().with_store("redis://localhost", mock_store));
674646

675-
let allowed_stores = vec![
676-
(SmolStr::new("mystore"), SmolStr::new("redis://localhost")),
677-
];
647+
let allowed_stores = vec![(SmolStr::new("mystore"), SmolStr::new("redis://localhost"))];
678648
let stats = Arc::new(MockReadStats::new());
679649
let mut store_impl = Builder::new(allowed_stores, manager).build(stats.clone());
680650

681651
let store_id = store_impl.open("mystore").await.unwrap();
682-
let result = store_impl.bf_exists(store_id, "bloom_key", "nonexistent").await;
652+
let result = store_impl
653+
.bf_exists(store_id, "bloom_key", "nonexistent")
654+
.await;
683655

684656
assert!(result.is_ok());
685657
assert_eq!(result.unwrap(), false);

crates/runtime/src/store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::registry::CachedGraphRegistry;
44
use crate::util::stats::StatsVisitor;
55
use crate::{Data, Wasi, WasiVersion, DEFAULT_EPOCH_TICK_INTERVAL};
66
use anyhow::Result;
7-
use utils::{Dictionary, Utils};
87
use secret::SecretStore;
98
use std::sync::Arc;
109
use std::{
@@ -13,6 +12,7 @@ use std::{
1312
ops::{Deref, DerefMut},
1413
};
1514
use tracing::{debug, instrument, trace};
15+
use utils::{Dictionary, Utils};
1616
use wasmtime::component::ResourceTable;
1717
use wasmtime_wasi::WasiCtxBuilder;
1818
use wasmtime_wasi_http::WasiHttpCtx;
@@ -270,7 +270,7 @@ impl StoreBuilder {
270270
secret_store: self.secret_store,
271271
key_value_store,
272272
dictionary: self.dictionary,
273-
utils
273+
utils,
274274
},
275275
);
276276
inner.limiter(|state| &mut state.store_limits);

crates/runtime/src/util/stats.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use serde::Serialize;
22
use std::sync::Arc;
33

4-
use std::time::{Duration, Instant};
54
use http_backend::stats::ExtRequestStats;
65
pub use key_value_store::ReadStats;
6+
use std::time::{Duration, Instant};
77
use utils::UserDiagStats;
88

99
#[repr(i32)]
@@ -153,7 +153,7 @@ mod tests {
153153
}
154154

155155
impl ExtRequestStats for MockStatsVisitor {
156-
fn observe_ext(&self, _: std::time::Duration) { }
156+
fn observe_ext(&self, _: std::time::Duration) {}
157157
}
158158

159159
impl StatsVisitor for MockStatsVisitor {
@@ -185,8 +185,6 @@ mod tests {
185185
fn cdn_phase(&self, phase: CdnPhase) {
186186
self.cdn_phase.store(phase as i32, Ordering::Relaxed);
187187
}
188-
189-
190188
}
191189

192190
#[test]
@@ -413,4 +411,3 @@ mod tests {
413411
assert_eq!(stats.kv_reads.load(Ordering::Relaxed), 10);
414412
}
415413
}
416-

0 commit comments

Comments
 (0)