Skip to content

Commit 7dbbe7e

Browse files
authored
Merge pull request #5 from sio2project/3-add-metrics-endpoint
Add metrics endpoint
2 parents 59484ca + 052c8bc commit 7dbbe7e

File tree

14 files changed

+806
-8
lines changed

14 files changed

+806
-8
lines changed

Cargo.lock

Lines changed: 47 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ async-trait = "0.1.77"
2727
flate2 = "1.0.28"
2828
urlencoding = "2.1.3"
2929
clap = { version = "4.5.0", features = ["derive"] }
30-
reqwest = { version = "0.12.0", features = ["json", "gzip"] }
30+
reqwest = { version = "0.12.0", features = ["json", "gzip"] }
31+
prometheus = "0.13.4"
32+
lazy_static = "1.5.0"

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ version: '3.8'
22

33
# MinIO and PostgreSQL setup for s3dedup development
44
# Buckets are automatically created by the application on startup
5+
# PostgreSQL creates both 's3dedup' (main) and 's3dedup_test' (for tests) databases
56
services:
67
minio:
78
image: minio/minio:RELEASE.2024-10-02T17-50-41Z
@@ -34,6 +35,7 @@ services:
3435
POSTGRES_DB: s3dedup
3536
volumes:
3637
- postgres_data:/var/lib/postgresql/data
38+
- ./docker/init-test-db.sh:/docker-entrypoint-initdb.d/init-test-db.sh
3739
healthcheck:
3840
test: ["CMD-SHELL", "pg_isready -U postgres"]
3941
interval: 10s

docker/init-test-db.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
5+
CREATE DATABASE s3dedup_test;
6+
EOSQL

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod filetracker_client;
77
pub mod kvstorage;
88
pub mod locks;
99
pub mod logging;
10+
pub mod metrics;
1011
pub mod migration;
1112
pub mod routes;
1213
pub mod s3storage;
@@ -18,6 +19,7 @@ pub struct AppState {
1819
pub locks: Arc<Mutex<Box<locks::LocksStorage>>>,
1920
pub s3storage: Arc<Mutex<Box<s3storage::S3Storage>>>,
2021
pub filetracker_client: Option<Arc<filetracker_client::FiletrackerClient>>,
22+
pub metrics: Arc<metrics::Metrics>,
2123
}
2224

2325
impl AppState {
@@ -27,12 +29,14 @@ impl AppState {
2729
let kvstorage = kvstorage::KVStorage::new(config).await?;
2830
let locks = locks::LocksStorage::new(&config.locks_type);
2931
let s3storage = s3storage::S3Storage::new(config).await?;
32+
let metrics = Arc::new(metrics::Metrics::new());
3033
Ok(Self {
3134
bucket_name: config.name.clone(),
3235
kvstorage: Arc::new(Mutex::new(kvstorage)),
3336
locks: Arc::new(Mutex::new(locks)),
3437
s3storage: Arc::new(Mutex::new(s3storage)),
3538
filetracker_client: None,
39+
metrics,
3640
})
3741
}
3842

@@ -44,12 +48,18 @@ impl AppState {
4448
let locks = locks::LocksStorage::new(&config.locks_type);
4549
let s3storage = s3storage::S3Storage::new(config).await?;
4650
let filetracker_client = filetracker_client::FiletrackerClient::new(filetracker_url);
51+
let metrics = Arc::new(metrics::Metrics::new());
52+
53+
// Mark migration as active
54+
metrics::MIGRATION_ACTIVE.set(1);
55+
4756
Ok(Self {
4857
bucket_name: config.name.clone(),
4958
kvstorage: Arc::new(Mutex::new(kvstorage)),
5059
locks: Arc::new(Mutex::new(locks)),
5160
s3storage: Arc::new(Mutex::new(s3storage)),
5261
filetracker_client: Some(Arc::new(filetracker_client)),
62+
metrics,
5363
})
5464
}
5565
}

src/main.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ async fn run_s3dedup_server(config_path: Option<&str>, use_env: bool) {
104104
.put(ft_put_file)
105105
.delete(ft_delete_file),
106106
)
107+
.route("/metrics", get(s3dedup::routes::metrics::metrics_handler))
108+
.route(
109+
"/metrics/json",
110+
get(s3dedup::routes::metrics::metrics_json_handler),
111+
)
107112
.layer(
108113
// Logging middleware
109114
TraceLayer::new_for_http()
@@ -252,6 +257,11 @@ async fn run_live_migrate(config_path: Option<&str>, use_env: bool, max_concurre
252257
.put(s3dedup::routes::ft::put_file::ft_put_file)
253258
.delete(s3dedup::routes::ft::delete_file::ft_delete_file),
254259
)
260+
.route("/metrics", get(s3dedup::routes::metrics::metrics_handler))
261+
.route(
262+
"/metrics/json",
263+
get(s3dedup::routes::metrics::metrics_json_handler),
264+
)
255265
.layer(
256266
TraceLayer::new_for_http()
257267
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))
@@ -316,6 +326,11 @@ async fn run_live_migrate(config_path: Option<&str>, use_env: bool, max_concurre
316326
.put(s3dedup::routes::ft::put_file::ft_put_file)
317327
.delete(s3dedup::routes::ft::delete_file::ft_delete_file),
318328
)
329+
.route("/metrics", get(s3dedup::routes::metrics::metrics_handler))
330+
.route(
331+
"/metrics/json",
332+
get(s3dedup::routes::metrics::metrics_json_handler),
333+
)
319334
.layer(
320335
TraceLayer::new_for_http()
321336
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))

0 commit comments

Comments
 (0)