Skip to content
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
51 changes: 47 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ async-trait = "0.1.77"
flate2 = "1.0.28"
urlencoding = "2.1.3"
clap = { version = "4.5.0", features = ["derive"] }
reqwest = { version = "0.12.0", features = ["json", "gzip"] }
reqwest = { version = "0.12.0", features = ["json", "gzip"] }
prometheus = "0.13.4"
lazy_static = "1.5.0"
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: '3.8'

# MinIO and PostgreSQL setup for s3dedup development
# Buckets are automatically created by the application on startup
# PostgreSQL creates both 's3dedup' (main) and 's3dedup_test' (for tests) databases
services:
minio:
image: minio/minio:RELEASE.2024-10-02T17-50-41Z
Expand Down Expand Up @@ -34,6 +35,7 @@ services:
POSTGRES_DB: s3dedup
volumes:
- postgres_data:/var/lib/postgresql/data
- ./docker/init-test-db.sh:/docker-entrypoint-initdb.d/init-test-db.sh
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
Expand Down
6 changes: 6 additions & 0 deletions docker/init-test-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE DATABASE s3dedup_test;
EOSQL
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod filetracker_client;
pub mod kvstorage;
pub mod locks;
pub mod logging;
pub mod metrics;
pub mod migration;
pub mod routes;
pub mod s3storage;
Expand All @@ -18,6 +19,7 @@ pub struct AppState {
pub locks: Arc<Mutex<Box<locks::LocksStorage>>>,
pub s3storage: Arc<Mutex<Box<s3storage::S3Storage>>>,
pub filetracker_client: Option<Arc<filetracker_client::FiletrackerClient>>,
pub metrics: Arc<metrics::Metrics>,
}

impl AppState {
Expand All @@ -27,12 +29,14 @@ impl AppState {
let kvstorage = kvstorage::KVStorage::new(config).await?;
let locks = locks::LocksStorage::new(&config.locks_type);
let s3storage = s3storage::S3Storage::new(config).await?;
let metrics = Arc::new(metrics::Metrics::new());
Ok(Self {
bucket_name: config.name.clone(),
kvstorage: Arc::new(Mutex::new(kvstorage)),
locks: Arc::new(Mutex::new(locks)),
s3storage: Arc::new(Mutex::new(s3storage)),
filetracker_client: None,
metrics,
})
}

Expand All @@ -44,12 +48,18 @@ impl AppState {
let locks = locks::LocksStorage::new(&config.locks_type);
let s3storage = s3storage::S3Storage::new(config).await?;
let filetracker_client = filetracker_client::FiletrackerClient::new(filetracker_url);
let metrics = Arc::new(metrics::Metrics::new());

// Mark migration as active
metrics::MIGRATION_ACTIVE.set(1);

Ok(Self {
bucket_name: config.name.clone(),
kvstorage: Arc::new(Mutex::new(kvstorage)),
locks: Arc::new(Mutex::new(locks)),
s3storage: Arc::new(Mutex::new(s3storage)),
filetracker_client: Some(Arc::new(filetracker_client)),
metrics,
})
}
}
15 changes: 15 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ async fn run_s3dedup_server(config_path: Option<&str>, use_env: bool) {
.put(ft_put_file)
.delete(ft_delete_file),
)
.route("/metrics", get(s3dedup::routes::metrics::metrics_handler))
.route(
"/metrics/json",
get(s3dedup::routes::metrics::metrics_json_handler),
)
.layer(
// Logging middleware
TraceLayer::new_for_http()
Expand Down Expand Up @@ -252,6 +257,11 @@ async fn run_live_migrate(config_path: Option<&str>, use_env: bool, max_concurre
.put(s3dedup::routes::ft::put_file::ft_put_file)
.delete(s3dedup::routes::ft::delete_file::ft_delete_file),
)
.route("/metrics", get(s3dedup::routes::metrics::metrics_handler))
.route(
"/metrics/json",
get(s3dedup::routes::metrics::metrics_json_handler),
)
.layer(
TraceLayer::new_for_http()
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))
Expand Down Expand Up @@ -316,6 +326,11 @@ async fn run_live_migrate(config_path: Option<&str>, use_env: bool, max_concurre
.put(s3dedup::routes::ft::put_file::ft_put_file)
.delete(s3dedup::routes::ft::delete_file::ft_delete_file),
)
.route("/metrics", get(s3dedup::routes::metrics::metrics_handler))
.route(
"/metrics/json",
get(s3dedup::routes::metrics::metrics_json_handler),
)
.layer(
TraceLayer::new_for_http()
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))
Expand Down
Loading