Skip to content

Commit 23f80f2

Browse files
committed
improve: code cleanup
1 parent af36433 commit 23f80f2

File tree

93 files changed

+334
-273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+334
-273
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,20 @@ jobs:
399399
- name: Checkout code
400400
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
401401

402-
- name: Install Rust toolchain
402+
- name: Install Rust toolchain (stable + nightly for udeps)
403403
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
404404
with:
405405
toolchain: stable
406406

407+
- name: Install Rust nightly toolchain (for cargo-udeps)
408+
uses: dtolnay/rust-toolchain@0b1efabc08b657293548b77fb76cc02d26091c7e # master
409+
with:
410+
toolchain: nightly
411+
407412
- name: Install development tools via Mise
408413
uses: step-security/mise-action@2fa1b2b4fa1577588d8ac75f4dfa0f67c266d2a0 # v3.4.1
409414
with:
410-
install_args: cargo:cargo-outdated
415+
install_args: protobuf cargo:cargo-outdated cargo:cargo-udeps
411416
cache: true
412417

413418
- name: Cache Rust dependencies
@@ -416,6 +421,9 @@ jobs:
416421
- name: Check outdated dependencies
417422
run: cargo outdated --exit-code 1 || echo "Some dependencies are outdated"
418423

424+
- name: Check for unused dependencies
425+
run: cargo +nightly udeps --workspace --all-targets || echo "Some dependencies may be unused"
426+
419427
- name: Check for duplicate dependencies
420428
run: cargo tree --duplicates
421429

Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bon = "3.8"
3232

3333
# Error handling
3434
anyhow = "1.0"
35-
thiserror = "2.0"
35+
snafu = "0.8"
3636

3737
# System
3838
num_cpus = "1.16"
@@ -143,6 +143,16 @@ rustls = { version = "0.23", default-features = false, features = [
143143
"aws_lc_rs",
144144
] }
145145

146+
[workspace.lints.rust]
147+
unsafe_code = "deny"
148+
149+
[workspace.lints.clippy]
150+
unwrap_used = "warn"
151+
expect_used = "warn"
152+
panic = "warn"
153+
todo = "warn"
154+
unimplemented = "warn"
155+
146156
[profile.release]
147157
codegen-units = 1
148158
lto = "thin"

crates/inferadb-control-api/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ chrono = { workspace = true }
2828
ed25519-dalek = { workspace = true }
2929
jsonwebtoken = { workspace = true }
3030
metrics-exporter-prometheus = { workspace = true }
31-
pem = "3.0"
31+
pem = { workspace = true }
3232
rand = { workspace = true }
33-
reqwest = { workspace = true }
3433
serde = { workspace = true }
3534
serde_json = { workspace = true }
36-
serde_yaml = { workspace = true }
3735
time = { workspace = true }
3836
tokio = { workspace = true }
3937
tower = { workspace = true }
@@ -46,5 +44,8 @@ inferadb-control-test-fixtures = { path = "../inferadb-control-test-fixtures" }
4644
inferadb-engine-auth = { path = "../../../engine/crates/inferadb-engine-auth" }
4745
rand_core = { version = "0.6", features = ["getrandom"] }
4846

47+
[lints]
48+
workspace = true
49+
4950
[features]
5051
default = []

crates/inferadb-control-api/src/handlers/audit_logs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ pub async fn list_audit_logs(
133133
}
134134

135135
#[cfg(test)]
136+
#[allow(clippy::unwrap_used, clippy::expect_used)]
136137
mod tests {
137138
use std::sync::Arc;
138139

crates/inferadb-control-api/src/handlers/auth.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ pub async fn confirm_password_reset(
529529
}
530530

531531
#[cfg(test)]
532+
#[allow(clippy::unwrap_used, clippy::expect_used)]
532533
mod tests {
533534
use tower::ServiceExt;
534535

crates/inferadb-control-api/src/handlers/cli_auth.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ fn generate_secure_code(length: usize) -> Vec<u8> {
157157
}
158158

159159
#[cfg(test)]
160+
#[allow(clippy::unwrap_used, clippy::expect_used)]
160161
mod tests {
161162
use std::sync::Arc;
162163

crates/inferadb-control-api/src/handlers/emails.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ pub async fn delete_email(
287287
}
288288

289289
#[cfg(test)]
290+
#[allow(clippy::unwrap_used, clippy::expect_used)]
290291
mod tests {
291292
use std::sync::Arc;
292293

crates/inferadb-control-api/src/handlers/health.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,10 @@ pub async fn healthz_handler(State(state): State<AppState>) -> impl IntoResponse
112112
// Get instance details from state
113113
let instance_id = state.worker_id;
114114
let start_time = state.start_time;
115-
let is_leader = state
116-
.leader
117-
.as_ref()
118-
.map(|l| {
119-
let leader_check = l.clone();
120-
// Use tokio::task::block_in_place to avoid blocking the runtime
121-
tokio::task::block_in_place(|| {
122-
tokio::runtime::Handle::current().block_on(leader_check.is_leader())
123-
})
124-
})
125-
.unwrap_or(false);
115+
let is_leader = match &state.leader {
116+
Some(leader) => leader.is_leader().await,
117+
None => false,
118+
};
126119

127120
// Calculate uptime
128121
let uptime_seconds = SystemTime::now().duration_since(start_time).unwrap_or_default().as_secs();
@@ -145,6 +138,7 @@ pub async fn healthz_handler(State(state): State<AppState>) -> impl IntoResponse
145138
}
146139

147140
#[cfg(test)]
141+
#[allow(clippy::unwrap_used, clippy::expect_used)]
148142
mod tests {
149143
use std::sync::Arc;
150144

crates/inferadb-control-api/src/handlers/metrics.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ static METRICS_HANDLE: OnceLock<PrometheusHandle> = OnceLock::new();
1414
/// It sets up the Prometheus exporter that will collect and expose metrics.
1515
pub fn init_exporter() {
1616
METRICS_HANDLE.get_or_init(|| {
17+
// Metrics recorder installation failure is unrecoverable at startup
18+
#[allow(clippy::expect_used)]
1719
let handle = PrometheusBuilder::new()
1820
.install_recorder()
1921
.expect("Failed to install Prometheus recorder");
@@ -45,6 +47,7 @@ pub async fn metrics_handler() -> Response {
4547
}
4648

4749
#[cfg(test)]
50+
#[allow(clippy::unwrap_used, clippy::expect_used)]
4851
mod tests {
4952
use super::*;
5053

crates/inferadb-control-api/src/handlers/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub mod tokens;
1313
pub mod users;
1414
pub mod vaults;
1515

16-
pub use auth::*;
16+
pub use auth::{
17+
AppState, confirm_password_reset, login, logout, register, request_password_reset, verify_email,
18+
};
1719
pub use health::{healthz_handler, livez_handler, readyz_handler, startupz_handler};
1820
pub use metrics::{init_exporter, metrics_handler};

0 commit comments

Comments
 (0)