Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

refactor(metrics): add storage layer and scheduler execution metrics (#13963)

Sanchith Hegde8d20dc99d048
diff --git a/.deepsource.toml b/.deepsource.toml
index 5db492d68c..b1f6f3d0ea 100644
--- a/.deepsource.toml
+++ b/.deepsource.toml
@@ -13,4 +13,4 @@ name = "rust"
enabled = true
[analyzers.meta]
-msrv = "1.85.0"
+msrv = "1.92.0"
diff --git a/Cargo.lock b/Cargo.lock
index 07d5425274..32b7266f18 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -635,15 +635,15 @@ dependencies = [
[[package]]
name = "async-bb8-diesel"
-version = "0.2.1"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ebc03a2806f66f36513d65e0a7f34200382230250cadcf8a8397cfbe3f26b795"
+checksum = "433a78c27b116e74d1c773b4b2e76a83cde6dc1e7ca2b65345dcf597d34f16b4"
dependencies = [
"async-trait",
"bb8",
"diesel",
"futures 0.3.31",
- "thiserror 1.0.69",
+ "thiserror 2.0.12",
"tokio 1.48.0",
]
@@ -701,7 +701,7 @@ checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667"
dependencies = [
"proc-macro2",
"quote",
- "syn 3.0.9",
+ "syn 3.0.4",
]
[[package]]
@@ -1509,13 +1509,13 @@ dependencies = [
[[package]]
name = "bb8"
-version = "0.8.6"
+version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d89aabfae550a5c44b43ab941844ffcd2e993cb6900b342debf59e9ea74acdb8"
+checksum = "457d7ed3f888dfd2c7af56d4975cade43c622f74bdcddfed6d4352f57acc6310"
dependencies = [
- "async-trait",
"futures-util",
"parking_lot 0.12.3",
+ "portable-atomic",
"tokio 1.48.0",
]
@@ -2776,6 +2776,16 @@ dependencies = [
"darling_macro 0.20.11",
]
+[[package]]
+name = "darling"
+version = "0.21.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0"
+dependencies = [
+ "darling_core 0.21.3",
+ "darling_macro 0.21.3",
+]
+
[[package]]
name = "darling_core"
version = "0.14.4"
@@ -2804,6 +2814,20 @@ dependencies = [
"syn 2.0.101",
]
+[[package]]
+name = "darling_core"
+version = "0.21.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4"
+dependencies = [
+ "fnv",
+ "ident_case",
+ "proc-macro2",
+ "quote",
+ "strsim 0.11.1",
+ "syn 2.0.101",
+]
+
[[package]]
name = "darling_macro"
version = "0.14.4"
@@ -2826,6 +2850,17 @@ dependencies = [
"syn 2.0.101",
]
+[[package]]
+name = "darling_macro"
+version = "0.21.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81"
+dependencies = [
+ "darling_core 0.21.3",
+ "quote",
+ "syn 2.0.101",
+]
+
[[package]]
name = "dashmap"
version = "5.5.3"
@@ -2875,7 +2910,7 @@ checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b"
[[package]]
name = "deja"
version = "0.1.0"
-source = "git+https://github.com/juspay/deja?rev=9230641b943a469ef4b506c05e3e9201363f3d10#9230641b943a469ef4b506c05e3e9201363f3d10"
+source = "git+https://github.com/juspay/deja?rev=6ace82f8d37c7c5703f9636a608dd8d85a8f6953#6ace82f8d37c7c5703f9636a608dd8d85a8f6953"
dependencies = [
"deja-context",
"deja-core",
@@ -2892,7 +2927,7 @@ dependencies = [
[[package]]
name = "deja-context"
version = "0.1.0"
-source = "git+https://github.com/juspay/deja?rev=9230641b943a469ef4b506c05e3e9201363f3d10#9230641b943a469ef4b506c05e3e9201363f3d10"
+source = "git+https://github.com/juspay/deja?rev=6ace82f8d37c7c5703f9636a608dd8d85a8f6953#6ace82f8d37c7c5703f9636a608dd8d85a8f6953"
dependencies = [
"pin-project-lite",
]
@@ -2900,7 +2935,7 @@ dependencies = [
[[package]]
name = "deja-core"
version = "0.1.0"
-source = "git+https://github.com/juspay/deja?rev=9230641b943a469ef4b506c05e3e9201363f3d10#9230641b943a469ef4b506c05e3e9201363f3d10"
+source = "git+https://github.com/juspay/deja?rev=6ace82f8d37c7c5703f9636a608dd8d85a8f6953#6ace82f8d37c7c5703f9636a608dd8d85a8f6953"
dependencies = [
"serde",
"serde_json",
@@ -2910,7 +2945,7 @@ dependencies = [
[[package]]
name = "deja-derive"
version = "0.1.0"
-source = "git+https://github.com/juspay/deja?rev=9230641b943a469ef4b506c05e3e9201363f3d10#9230641b943a469ef4b506c05e3e9201363f3d10"
+source = "git+https://github.com/juspay/deja?rev=6ace82f8d37c7c5703f9636a608dd8d85a8f6953#6ace82f8d37c7c5703f9636a608dd8d85a8f6953"
dependencies = [
"proc-macro2",
"quote",
@@ -2920,7 +2955,7 @@ dependencies = [
[[package]]
name = "deja-diesel"
version = "0.1.0"
-source = "git+https://github.com/juspay/deja?rev=9230641b943a469ef4b506c05e3e9201363f3d10#9230641b943a469ef4b506c05e3e9201363f3d10"
+source = "git+https://github.com/juspay/deja?rev=6ace82f8d37c7c5703f9636a608dd8d85a8f6953#6ace82f8d37c7c5703f9636a608dd8d85a8f6953"
dependencies = [
"async-bb8-diesel",
"deja-runtime",
@@ -2931,7 +2966,7 @@ dependencies = [
[[package]]
name = "deja-runtime"
version = "0.1.0"
-source = "git+https://github.com/juspay/deja?rev=9230641b943a469ef4b506c05e3e9201363f3d10#9230641b943a469ef4b506c05e3e9201363f3d10"
+source = "git+https://github.com/juspay/deja?rev=6ace82f8d37c7c5703f9636a608dd8d85a8f6953#6ace82f8d37c7c5703f9636a608dd8d85a8f6953"
dependencies = [
"async-trait",
"deja-context",
@@ -3083,13 +3118,14 @@ checksum = "dc55fe0d1f6c107595572ec8b107c0999bb1a2e0b75e37429a4fb0d6474a0e7d"
[[package]]
name = "diesel"
-version = "2.2.10"
+version = "2.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ff3e1edb1f37b4953dd5176916347289ed43d7119cc2e6c7c3f7849ff44ea506"
+checksum = "715377c6e464cb44bb89bd8487584240516c8d5052bc645d6babc50bb8be46c3"
dependencies = [
"bitflags 2.9.0",
"byteorder",
"diesel_derives",
+ "downcast-rs",
"itoa",
"pq-sys",
"r2d2",
@@ -3099,9 +3135,9 @@ dependencies = [
[[package]]
name = "diesel_derives"
-version = "2.2.3"
+version = "2.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e7f2c3de51e2ba6bf2a648285696137aaf0f5f487bcbea93972fe8a364e131a4"
+checksum = "d1817b7f4279b947fc4cafddec12b0e5f8727141706561ce3ac94a60bddd1cf5"
dependencies = [
"diesel_table_macro_syntax",
"dsl_auto_type",
@@ -3112,9 +3148,9 @@ dependencies = [
[[package]]
name = "diesel_migrations"
-version = "2.2.0"
+version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8a73ce704bad4231f001bff3314d91dce4aba0770cee8b233991859abc15c1f6"
+checksum = "28d0f4a98124ba6d4ca75da535f65984badec16a003b6e2f94a01e31a79490b8"
dependencies = [
"diesel",
"migrations_internals",
@@ -3146,9 +3182,9 @@ dependencies = [
[[package]]
name = "diesel_table_macro_syntax"
-version = "0.2.0"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25"
+checksum = "fe2444076b48641147115697648dc743c2c00b61adade0f01ce67133c7babe8c"
dependencies = [
"syn 2.0.101",
]
@@ -3212,6 +3248,12 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1"
+[[package]]
+name = "downcast-rs"
+version = "2.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "117240f60069e65410b3ae1bb213295bd828f707b5bec6596a1afc8793ce0cbc"
+
[[package]]
name = "drainer"
version = "0.1.0"
@@ -3244,11 +3286,11 @@ dependencies = [
[[package]]
name = "dsl_auto_type"
-version = "0.1.2"
+version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c5d9abe6314103864cc2d8901b7ae224e0ab1a103a0a416661b4097b0779b607"
+checksum = "dd122633e4bef06db27737f21d3738fb89c8f6d5360d6d9d7635dda142a7757e"
dependencies = [
- "darling 0.20.11",
+ "darling 0.21.3",
"either",
"heck 0.5.0",
"proc-macro2",
@@ -5945,19 +5987,19 @@ dependencies = [
[[package]]
name = "migrations_internals"
-version = "2.2.0"
+version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fd01039851e82f8799046eabbb354056283fb265c8ec0996af940f4e85a380ff"
+checksum = "36c791ecdf977c99f45f23280405d7723727470f6689a5e6dbf513ac547ae10d"
dependencies = [
"serde",
- "toml 0.8.22",
+ "toml 0.9.6",
]
[[package]]
name = "migrations_macros"
-version = "2.2.0"
+version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ffb161cc72176cb37aa47f1fc520d3ef02263d67d661f44f05d05a079e1237fd"
+checksum = "36fc5ac76be324cfd2d3f2cf0fdf5d5d3c4f14ed8aaebadb09e304ba42282703"
dependencies = [
"migrations_internals",
"proc-macro2",
@@ -7411,6 +7453,12 @@ dependencies = [
"miniz_oxide 0.7.4",
]
+[[package]]
+name = "portable-atomic"
+version = "1.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
+
[[package]]
name = "powerfmt"
version = "0.2.0"
@@ -9337,6 +9385,15 @@ dependencies = [
"serde",
]
+[[package]]
+name = "serde_spanned"
+version = "1.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
+dependencies = [
+ "serde_core",
+]
+
[[package]]
name = "serde_urlencoded"
version = "0.7.1"
@@ -10285,9 +10342,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "3.0.9"
+version = "3.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
+checksum = "e6275cddf4610d1775e6d1fe9469b2e77d0f39fd98fb7450901b821e0c53649f"
dependencies = [
"proc-macro2",
"quote",
@@ -11038,8 +11095,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257"
dependencies = [
"serde",
- "serde_spanned",
- "toml_datetime",
+ "serde_spanned 0.6.8",
+ "toml_datetime 0.6.9",
"toml_edit 0.19.15",
]
@@ -11051,11 +11108,24 @@ checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae"
dependencies = [
"indexmap 2.9.0",
"serde",
- "serde_spanned",
- "toml_datetime",
+ "serde_spanned 0.6.8",
+ "toml_datetime 0.6.9",
"toml_edit 0.22.26",
]
+[[package]]
+name = "toml"
+version = "0.9.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae2a4cf385da23d1d53bc15cdfa5c2109e93d8d362393c801e87da2f72f0e201"
+dependencies = [
+ "serde_core",
+ "serde_spanned 1.1.1",
+ "toml_datetime 0.7.5+spec-1.1.0",
+ "toml_parser",
+ "winnow 0.7.10",
+]
+
[[package]]
name = "toml_datetime"
version = "0.6.9"
@@ -11065,6 +11135,15 @@ dependencies = [
"serde",
]
+[[package]]
+name = "toml_datetime"
+version = "0.7.5+spec-1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347"
+dependencies = [
+ "serde_core",
+]
+
[[package]]
name = "toml_edit"
version = "0.19.15"
@@ -11073,8 +11152,8 @@ checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
dependencies = [
"indexmap 2.9.0",
"serde",
- "serde_spanned",
- "toml_datetime",
+ "serde_spanned 0.6.8",
+ "toml_datetime 0.6.9",
"winnow 0.5.40",
]
@@ -11086,12 +11165,21 @@ checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e"
dependencies = [
"indexmap 2.9.0",
"serde",
- "serde_spanned",
- "toml_datetime",
+ "serde_spanned 0.6.8",
+ "toml_datetime 0.6.9",
"toml_write",
"winnow 0.7.10",
]
+[[package]]
+name = "toml_parser"
+version = "1.1.3+spec-1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56"
+dependencies = [
+ "winnow 1.0.4",
+]
+
[[package]]
name = "toml_write"
version = "0.1.1"
@@ -12746,6 +12834,12 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "winnow"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81"
+
[[package]]
name = "winreg"
version = "0.50.0"
diff --git a/Cargo.toml b/Cargo.toml
index a52d724dcf..c6480e5dac 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,7 +2,7 @@
resolver = "2"
members = ["crates/*"]
package.edition = "2021"
-package.rust-version = "1.85.0"
+package.rust-version = "1.92.0"
package.license = "Apache-2.0"
[workspace.dependencies]
diff --git a/INSTALL_dependencies.sh b/INSTALL_dependencies.sh
index 8e21bf119b..bbee9845f8 100755
--- a/INSTALL_dependencies.sh
+++ b/INSTALL_dependencies.sh
@@ -9,7 +9,7 @@ if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
-RUST_MSRV="1.85.0"
+RUST_MSRV="1.92.0"
_DB_NAME="hyperswitch_db"
_DB_USER="db_user"
_DB_PASS="db_password"
diff --git a/crates/analytics/Cargo.toml b/crates/analytics/Cargo.toml
index 218fdaf8ca..41b8ee0646 100644
--- a/crates/analytics/Cargo.toml
+++ b/crates/analytics/Cargo.toml
@@ -19,7 +19,7 @@ common_utils = { version = "0.1.0", path = "../common_utils" }
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"], default-features = false }
hyperswitch_interfaces = { version = "0.1.0", path = "../hyperswitch_interfaces", default-features = false }
hyperswitch_masking = "0.0.1"
-deja = { git = "https://github.com/juspay/deja", rev = "9230641b943a469ef4b506c05e3e9201363f3d10", optional = true, default-features = false, features = ["error-stack"] }
+deja = { git = "https://github.com/juspay/deja", rev = "6ace82f8d37c7c5703f9636a608dd8d85a8f6953", optional = true, default-features = false, features = ["error-stack"] }
router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] }
storage_impl = { version = "0.1.0", path = "../storage_impl", default-features = false }
currency_conversion = { version = "0.1.0", path = "../currency_conversion" }
diff --git a/crates/common_enums/Cargo.toml b/crates/common_enums/Cargo.toml
index f4758c96ac..f20ea31395 100644
--- a/crates/common_enums/Cargo.toml
+++ b/crates/common_enums/Cargo.toml
@@ -14,7 +14,7 @@ payouts = []
v2 = []
[dependencies]
-diesel = { version = "2.2.10", features = ["postgres", "128-column-tables"] }
+diesel = { version = "2.3.12", features = ["postgres", "128-column-tables"] }
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
strum = { version = "0.26", features = ["derive"] }
diff --git a/crates/common_types/Cargo.toml b/crates/common_types/Cargo.toml
index d0ee8887c5..ba2bc7107d 100644
--- a/crates/common_types/Cargo.toml
+++ b/crates/common_types/Cargo.toml
@@ -13,7 +13,7 @@ v2 = ["common_utils/v2"]
tokenization_v2 = ["common_utils/tokenization_v2"]
[dependencies]
-diesel = "2.2.10"
+diesel = "2.3.12"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
utoipa = { version = "4.2.3", features = ["preserve_order", "preserve_path_order"] }
diff --git a/crates/common_utils/Cargo.toml b/crates/common_utils/Cargo.toml
index 45bdb4e1ce..5e65195f1b 100644
--- a/crates/common_utils/Cargo.toml
+++ b/crates/common_utils/Cargo.toml
@@ -31,8 +31,8 @@ base64 = "0.22.1"
base64-serde = "0.8.0"
blake3 = { version = "1.8.2", features = ["serde"] }
bytes = { version = "1.10.1", features = ["serde"] }
-diesel = "2.2.10"
-deja = { git = "https://github.com/juspay/deja", rev = "9230641b943a469ef4b506c05e3e9201363f3d10", optional = true, default-features = false, features = ["error-stack"] }
+diesel = "2.3.12"
+deja = { git = "https://github.com/juspay/deja", rev = "6ace82f8d37c7c5703f9636a608dd8d85a8f6953", optional = true, default-features = false }
error-stack = "0.4.1"
futures = { version = "0.3.31", optional = true }
globset = "0.4.16"
diff --git a/crates/common_utils/src/synth_shape.rs b/crates/common_utils/src/synth_shape.rs
index b617e6e821..ffcaac1e7f 100644
--- a/crates/common_utils/src/synth_shape.rs
+++ b/crates/common_utils/src/synth_shape.rs
@@ -194,8 +194,6 @@ fn mix(seed: u64, index: u64) -> u64 {
#[cfg(test)]
mod tests {
- use super::*;
-
const HEX: [char; 16] = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
];
diff --git a/crates/diesel_models/Cargo.toml b/crates/diesel_models/Cargo.toml
index 4ed5a11998..00be7b947a 100644
--- a/crates/diesel_models/Cargo.toml
+++ b/crates/diesel_models/Cargo.toml
@@ -16,10 +16,10 @@ tokenization_v2 = []
deja = ["dep:deja", "deja/diesel-pg"]
[dependencies]
-async-bb8-diesel = "0.2.1"
+async-bb8-diesel = "0.3.0"
base64 = "0.22.1"
-bb8 = "0.8.6"
-diesel = { version = "2.2.10", features = ["postgres", "serde_json", "time", "128-column-tables", "i-implement-a-third-party-backend-and-opt-into-breaking-changes"] }
+bb8 = "0.9.1"
+diesel = { version = "2.3.12", features = ["postgres", "serde_json", "time", "128-column-tables", "i-implement-a-third-party-backend-and-opt-into-breaking-changes"] }
error-stack = "0.4.1"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
@@ -34,7 +34,7 @@ common_types = { version = "0.1.0", path = "../common_types" }
hyperswitch_masking = "0.0.1"
router_derive = { version = "0.1.0", path = "../router_derive" }
router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] }
-deja = { git = "https://github.com/juspay/deja", rev = "9230641b943a469ef4b506c05e3e9201363f3d10", optional = true, default-features = false, features = ["error-stack"] }
+deja = { git = "https://github.com/juspay/deja", rev = "6ace82f8d37c7c5703f9636a608dd8d85a8f6953", optional = true, default-features = false, features = ["error-stack"] }
[lints]
workspace = true
diff --git a/crates/diesel_models/src/kv/pg_type_metadata.rs b/crates/diesel_models/src/kv/pg_type_metadata.rs
index dbcb721d8d..9d4fe7c269 100644
--- a/crates/diesel_models/src/kv/pg_type_metadata.rs
+++ b/crates/diesel_models/src/kv/pg_type_metadata.rs
@@ -13,6 +13,6 @@ pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<Vec<PgTypeMetadata
let pairs: Vec<(u32, u32)> = Vec::deserialize(d)?;
Ok(pairs
.into_iter()
- .map(|(oid, array_oid)| PgTypeMetadata::from_result(Ok((oid, array_oid))))
+ .map(|(oid, array_oid)| PgTypeMetadata::new(oid, array_oid))
.collect())
}
diff --git a/crates/diesel_models/src/query/generics.rs b/crates/diesel_models/src/query/generics.rs
index 8a90374338..bce047b2be 100644
--- a/crates/diesel_models/src/query/generics.rs
+++ b/crates/diesel_models/src/query/generics.rs
@@ -115,9 +115,16 @@ pub mod db_metrics {
let table_name = std::any::type_name::<T>().rsplit("::").nth(1);
+ let outcome = if output.is_success() {
+ "success"
+ } else {
+ "error"
+ };
+
let attributes = router_env::metric_attributes!(
("table", table_name.unwrap_or("undefined")),
- ("operation", format!("{:?}", operation))
+ ("operation", format!("{:?}", operation)),
+ ("outcome", outcome)
);
crate::metrics::DATABASE_CALLS_COUNT.add(1, attributes);
diff --git a/crates/drainer/Cargo.toml b/crates/drainer/Cargo.toml
index 88eddbd1eb..b3fcd821ef 100644
--- a/crates/drainer/Cargo.toml
+++ b/crates/drainer/Cargo.toml
@@ -20,12 +20,12 @@ redis-rs = ["redis_interface/redis-rs", "redis_interface/metrics", "storage_impl
[dependencies]
actix-web = "4.11.0"
-async-bb8-diesel = "0.2.1"
+async-bb8-diesel = "0.3.0"
async-trait = "0.1.92"
-bb8 = "0.8"
+bb8 = "0.9.1"
clap = { version = "4.5.38", default-features = false, features = ["std", "derive", "help", "usage"] }
config = { version = "0.14.1", features = ["toml"] }
-diesel = { version = "2.2.10", features = ["postgres"] }
+diesel = { version = "2.3.12", features = ["postgres"] }
error-stack = "0.4.1"
mime = "0.3.17"
reqwest = { version = "0.11.27" }
diff --git a/crates/drainer/src/connection.rs b/crates/drainer/src/connection.rs
index c6694db655..71b8511b43 100644
--- a/crates/drainer/src/connection.rs
+++ b/crates/drainer/src/connection.rs
@@ -20,6 +20,8 @@ pub async fn diesel_make_pg_pool(
database: &Database,
_test_transaction: bool,
schema: &str,
+ db_pool: storage_impl::database::pool_metrics::DbPool,
+ tenant_id: &common_utils::id_type::TenantId,
) -> PgPool {
let database_url = database.get_database_url(schema);
let manager = async_bb8_diesel::ConnectionManager::<DejaPgConnection>::new(database_url);
@@ -32,16 +34,31 @@ pub async fn diesel_make_pg_pool(
.await
.expect("Failed to create PostgreSQL connection pool");
- PgPool::new_without_event_emitter(raw_pool)
+ let pool_metrics = storage_impl::database::pool_metrics::PgPoolMetrics::new(
+ raw_pool.clone(),
+ db_pool,
+ tenant_id,
+ );
+
+ PgPool::new(
+ raw_pool,
+ std::sync::Arc::new(common_utils::external_service::NoOpEventEmitter),
+ tenant_id.clone(),
+ pool_metrics,
+ )
}
#[allow(clippy::expect_used)]
pub async fn pg_connection<'a>(pool: &'a PgPool) -> DatabaseConnectionWithContext<'a> {
- let connection = pool
- .pg_pool
- .get()
- .await
- .expect("Couldn't retrieve PostgreSQL connection");
+ let tenant_id = pool.tenant_id.get_string_repr();
+
+ let connection = storage_impl::metrics::record_db_connection_acquire_duration(
+ pool.pg_pool.get(),
+ storage_impl::database::pool_metrics::DbPool::Master,
+ tenant_id,
+ )
+ .await
+ .expect("Couldn't retrieve PostgreSQL connection");
// The drainer serves no API request, so its queries carry no request id and emit no external
// service call events.
diff --git a/crates/drainer/src/services.rs b/crates/drainer/src/services.rs
index 258b88ad11..2bafc08941 100644
--- a/crates/drainer/src/services.rs
+++ b/crates/drainer/src/services.rs
@@ -41,6 +41,8 @@ impl Store {
config.master_database.get_inner(),
test_transaction,
&tenant.schema,
+ storage_impl::database::pool_metrics::DbPool::Master,
+ &tenant.tenant_id,
)
.await,
redis_conn: Arc::new(RedisConnectionPool::clone(
diff --git a/crates/euclid/Cargo.toml b/crates/euclid/Cargo.toml
index 72d860ec98..b1d4b932fe 100644
--- a/crates/euclid/Cargo.toml
+++ b/crates/euclid/Cargo.toml
@@ -14,7 +14,7 @@ serde_json = "1.0.140"
strum = { version = "0.26", features = ["derive"] }
thiserror = "1.0.69"
utoipa = { version = "4.2.3", features = ["preserve_order", "preserve_path_order"] }
-diesel = { version = "2.2.10", features = ["postgres", "128-column-tables"] }
+diesel = { version = "2.3.12", features = ["postgres", "128-column-tables"] }
# First party dependencies
common_enums = { version = "0.1.0", path = "../common_enums" }
diff --git a/crates/external_services/Cargo.toml b/crates/external_services/Cargo.toml
index a8d81d86ad..b7dd0d473c 100644
--- a/crates/external_services/Cargo.toml
+++ b/crates/external_services/Cargo.toml
@@ -68,7 +68,7 @@ aws-smithy-types = "1.3.1"
base64 = "0.22.1"
dyn-clone = "1.0.19"
google-cloud-kms = { version = "0.6.0", optional = true }
-deja = { git = "https://github.com/juspay/deja", rev = "9230641b943a469ef4b506c05e3e9201363f3d10", optional = true, default-features = false }
+deja = { git = "https://github.com/juspay/deja", rev = "6ace82f8d37c7c5703f9636a608dd8d85a8f6953", optional = true, default-features = false }
error-stack = "0.4.1"
hex = "0.4.3"
hyper = "0.14.32"
diff --git a/crates/hsdev/Cargo.toml b/crates/hsdev/Cargo.toml
index 42ec51ec90..bd55e22857 100644
--- a/crates/hsdev/Cargo.toml
+++ b/crates/hsdev/Cargo.toml
@@ -10,7 +10,7 @@ readme = "README.md"
[dependencies]
clap = { version = "4.5.38", features = ["derive"] }
-diesel = { version = "2.2.10", features = ["postgres"] }
+diesel = { version = "2.3.12", features = ["postgres"] }
diesel_migrations = "2.2.0"
serde = { version = "1.0", features = ["derive"] }
toml = "0.5"
diff --git a/crates/redis_interface/Cargo.toml b/crates/redis_interface/Cargo.toml
index ef89f88caf..d702e9ccd8 100644
--- a/crates/redis_interface/Cargo.toml
+++ b/crates/redis_interface/Cargo.toml
@@ -35,7 +35,7 @@ fred = { version = "8.0.6", optional = true, features = [
# First party crates
common_utils = { version = "0.1.0", path = "../common_utils", features = ["async_ext"] }
-deja = { git = "https://github.com/juspay/deja", rev = "9230641b943a469ef4b506c05e3e9201363f3d10", optional = true, default-features = false, features = ["error-stack", "fred"] }
+deja = { git = "https://github.com/juspay/deja", rev = "6ace82f8d37c7c5703f9636a608dd8d85a8f6953", optional = true, default-features = false, features = ["error-stack"] }
hyperswitch_masking = "0.0.1"
router_env = { version = "0.1.0", path = "../router_env", optional = true }
diff --git a/crates/redis_interface/src/metrics.rs b/crates/redis_interface/src/metrics.rs
index 990cd26135..d4bec1fe1b 100644
--- a/crates/redis_interface/src/metrics.rs
+++ b/crates/redis_interface/src/metrics.rs
@@ -132,7 +132,15 @@ where
#[cfg(feature = "metrics")]
{
- let attributes = router_env::metric_attributes!(("operation", format!("{operation:?}")));
+ let outcome = if output.is_success() {
+ "success"
+ } else {
+ "error"
+ };
+ let attributes = router_env::metric_attributes!(
+ ("operation", format!("{operation:?}")),
+ ("outcome", outcome)
+ );
REDIS_CALL_TIME.record(time_elapsed.as_secs_f64(), attributes);
}
diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml
index 395f09f4ae..de346834a3 100644
--- a/crates/router/Cargo.toml
+++ b/crates/router/Cargo.toml
@@ -196,10 +196,10 @@ actix-multipart = "0.6.2"
actix-rt = "2.10.0"
actix-web = "4.11.0"
argon2 = { version = "0.5.3", features = ["std"] }
-async-bb8-diesel = "0.2.1"
+async-bb8-diesel = "0.3.0"
async-trait = "0.1.92"
base64 = "0.22.1"
-bb8 = "0.8"
+bb8 = "0.9.1"
heck = "0.5.0"
open-feature = { version = "0.2.5" }
blake3 = "1.8.2"
@@ -214,7 +214,7 @@ config = { version = "0.14.1", features = ["toml"] }
prost-types = { version = "0.14", optional = true }
cookie = "0.18.1"
csv = "1.3.1"
-diesel = { version = "2.2.10", features = ["postgres"] }
+diesel = { version = "2.3.12", features = ["postgres"] }
dyn-clone = "1.0.19"
error-stack = "0.4.1"
futures = "0.3.31"
@@ -309,8 +309,8 @@ common_utils = { version = "0.1.0", path = "../common_utils", features = [
"keymanager",
] }
common_types = { version = "0.1.0", path = "../common_types" }
-deja = { git = "https://github.com/juspay/deja", rev = "9230641b943a469ef4b506c05e3e9201363f3d10", optional = true, default-features = false, features = ["error-stack"] }
-deja-core = { git = "https://github.com/juspay/deja", rev = "9230641b943a469ef4b506c05e3e9201363f3d10", optional = true }
+deja = { git = "https://github.com/juspay/deja", rev = "6ace82f8d37c7c5703f9636a608dd8d85a8f6953", optional = true, default-features = false }
+deja-core = { git = "https://github.com/juspay/deja", rev = "6ace82f8d37c7c5703f9636a608dd8d85a8f6953", optional = true }
connector_configs = { version = "0.1.0", path = "../connector_configs" }
currency_conversion = { version = "0.1.0", path = "../currency_conversion" }
diesel_models = { version = "0.1.0", path = "../diesel_models", features = [
diff --git a/crates/router/src/core/payments/flows/external_proxy_flow.rs b/crates/router/src/core/payments/flows/external_proxy_flow.rs
index 1ab4ac0c80..5ba790bf26 100644
--- a/crates/router/src/core/payments/flows/external_proxy_flow.rs
+++ b/crates/router/src/core/payments/flows/external_proxy_flow.rs
@@ -213,15 +213,6 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>
.await
}
- async fn postprocessing_steps<'a>(
- self,
- _state: &SessionState,
- _connector: &api::ConnectorData,
- ) -> RouterResult<Self> {
- // TODO: Implement external vault proxy postprocessing.
- Ok(self)
- }
-
async fn create_connector_customer<'a>(
&self,
state: &SessionState,
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index b545c14be0..71e562178c 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -163,6 +163,9 @@ impl scheduler::SchedulerSessionState for SessionState {
fn get_application_source(&self) -> common_enums::ApplicationSource {
self.conf.application_source
}
+ fn get_tenant_id(&self) -> &id_type::TenantId {
+ &self.tenant.tenant_id
+ }
fn get_request_id(&self) -> Option<RequestId> {
self.request_id.clone()
}
@@ -373,6 +376,9 @@ impl scheduler::SchedulerAppState for AppState {
fn get_tenants(&self) -> Vec<id_type::TenantId> {
self.conf.multitenancy.get_tenant_ids()
}
+ fn get_application_source(&self) -> common_enums::ApplicationSource {
+ self.conf.application_source
+ }
}
pub trait AppStateInfo {
fn conf(&self) -> settings::Settings<RawSecret>;
diff --git a/crates/router/src/services/jwt.rs b/crates/router/src/services/jwt.rs
index 6e8dd6abf0..e4e73f94b9 100644
--- a/crates/router/src/services/jwt.rs
+++ b/crates/router/src/services/jwt.rs
@@ -17,7 +17,6 @@ use crate::{configs::Settings, core::errors::UserErrors};
// Typed codec so a recorded `UserErrors` replays as the same error.
codec = deja::codec::ResultCodec::<std::time::Duration, UserErrors>,
on_miss = {
- use common_utils::synth_shape::Synthesize as _;
Ok(
std::time::Duration::from_nanos(
u64::try_from(__deja_miss.epoch_nanos()).unwrap_or(0),
diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rs
index 10d846a03d..787eaaec5d 100644
--- a/crates/router/src/utils/user/sample_data.rs
+++ b/crates/router/src/utils/user/sample_data.rs
@@ -216,8 +216,10 @@ pub async fn generate_sample_data(
created_at.saturating_add(time::Duration::seconds(consts::DEFAULT_SESSION_EXPIRY));
// After some set of payments sample data will have a failed attempt
- let is_failed_payment =
- (random_array.get(num - 1).unwrap_or(&0) % failure_after_attempts) == 0;
+ let is_failed_payment = random_array
+ .get(num - 1)
+ .unwrap_or(&0)
+ .is_multiple_of(failure_after_attempts);
let payment_intent = PaymentIntent {
payment_id: payment_id.clone(),
diff --git a/crates/router_derive/Cargo.toml b/crates/router_derive/Cargo.toml
index d1d3314f81..199fc6e9ef 100644
--- a/crates/router_derive/Cargo.toml
+++ b/crates/router_derive/Cargo.toml
@@ -20,7 +20,7 @@ strum = { version = "0.26.3", features = ["derive"] }
syn = { version = "2.0.101", features = ["full", "extra-traits"] } # the full feature does not seem to encompass all the features
[dev-dependencies]
-diesel = { version = "2.2.10", features = ["postgres"] }
+diesel = { version = "2.3.12", features = ["postgres"] }
error-stack = "0.4.1"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
diff --git a/crates/router_env/Cargo.toml b/crates/router_env/Cargo.toml
index b420345f86..0d47217fb9 100644
--- a/crates/router_env/Cargo.toml
+++ b/crates/router_env/Cargo.toml
@@ -10,8 +10,8 @@ license.workspace = true
[dependencies]
cargo_metadata = "0.18.1"
config = { version = "0.14.1", features = ["toml"] }
-deja = { git = "https://github.com/juspay/deja", rev = "9230641b943a469ef4b506c05e3e9201363f3d10", optional = true, default-features = false }
-deja-core = { git = "https://github.com/juspay/deja", rev = "9230641b943a469ef4b506c05e3e9201363f3d10", optional = true }
+deja = { git = "https://github.com/juspay/deja", rev = "6ace82f8d37c7c5703f9636a608dd8d85a8f6953", optional = true, default-features = false }
+deja-core = { git = "https://github.com/juspay/deja", rev = "6ace82f8d37c7c5703f9636a608dd8d85a8f6953", optional = true }
error-stack = "0.4.1"
gethostname = "0.4.3"
# Optional (deja-only): types the captured request/response payloads as `Secret`
diff --git a/crates/router_env/src/metrics.rs b/crates/router_env/src/metrics.rs
index 5de49d41ba..e1db5e4929 100644
--- a/crates/router_env/src/metrics.rs
+++ b/crates/router_env/src/metrics.rs
@@ -6,11 +6,11 @@
#[macro_export]
macro_rules! global_meter {
($name:ident) => {
- static $name: ::std::sync::LazyLock<$crate::opentelemetry::metrics::Meter> =
+ pub(crate) static $name: ::std::sync::LazyLock<$crate::opentelemetry::metrics::Meter> =
::std::sync::LazyLock::new(|| $crate::opentelemetry::global::meter(stringify!($name)));
};
($meter:ident, $name:literal) => {
- static $meter: ::std::sync::LazyLock<$crate::opentelemetry::metrics::Meter> =
+ pub(crate) static $meter: ::std::sync::LazyLock<$crate::opentelemetry::metrics::Meter> =
::std::sync::LazyLock::new(|| $crate::opentelemetry::global::meter(stringify!($name)));
};
}
diff --git a/crates/scheduler/src/consumer.rs b/crates/scheduler/src/consumer.rs
index e26361c942..2cde84246f 100644
--- a/crates/scheduler/src/consumer.rs
+++ b/crates/scheduler/src/consumer.rs
@@ -172,6 +172,7 @@ pub async fn consumer_operations<T: SchedulerSessionState + 'static>(
workflow_selector: impl workflows::ProcessTrackerWorkflows<T> + 'static + Copy + std::fmt::Debug,
consumer_name: &str,
) -> CustomResult<(), errors::ProcessTrackerError> {
+ let start_time = std::time::Instant::now();
let stream_name = match state.get_application_source() {
enums::ApplicationSource::Main => settings.stream.clone(),
enums::ApplicationSource::Cug => settings.cug_stream.clone(),
@@ -210,6 +211,21 @@ pub async fn consumer_operations<T: SchedulerSessionState + 'static>(
}
future::join_all(handler).await;
+ let duration = start_time.elapsed().as_secs_f64();
+ metrics::CONSUMER_OPERATION_DURATION.record(
+ duration,
+ router_env::metric_attributes!(
+ (
+ "application_source",
+ state.get_application_source().to_string()
+ ),
+ (
+ "tenant_id",
+ state.get_tenant_id().get_string_repr().to_owned()
+ )
+ ),
+ );
+
Ok(())
}
@@ -287,12 +303,31 @@ where
}
}
+ let workflow_start = std::time::Instant::now();
let res = workflow_selector
.trigger_workflow(&state, process.clone())
.await
.inspect_err(|error| {
logger::error!(?error, "Failed to trigger workflow");
});
+ let workflow_duration = workflow_start.elapsed().as_secs_f64();
+
+ let runner = process.runner.unwrap_or_else(|| "unknown".to_string());
+ metrics::WORKFLOW_EXECUTION_DURATION.record(
+ workflow_duration,
+ router_env::metric_attributes!(
+ ("runner", runner),
+ (
+ "application_source",
+ state.get_application_source().to_string()
+ ),
+ (
+ "tenant_id",
+ state.get_tenant_id().get_string_repr().to_owned()
+ )
+ ),
+ );
+
metrics::TASK_PROCESSED.add(1, &[]);
res
}
diff --git a/crates/scheduler/src/metrics.rs b/crates/scheduler/src/metrics.rs
index 27ac860d07..f150f4e823 100644
--- a/crates/scheduler/src/metrics.rs
+++ b/crates/scheduler/src/metrics.rs
@@ -3,6 +3,8 @@ use router_env::{counter_metric, global_meter, histogram_metric_f64};
global_meter!(PT_METER, "PROCESS_TRACKER");
histogram_metric_f64!(CONSUMER_OPS, PT_METER);
+histogram_metric_f64!(CONSUMER_OPERATION_DURATION, PT_METER);
+histogram_metric_f64!(WORKFLOW_EXECUTION_DURATION, PT_METER);
counter_metric!(PAYMENT_COUNT, PT_METER); // No. of payments created
counter_metric!(TASKS_PICKED_COUNT, PT_METER); // Tasks picked by
diff --git a/crates/scheduler/src/scheduler.rs b/crates/scheduler/src/scheduler.rs
index 76b1384ac3..5fc67a565a 100644
--- a/crates/scheduler/src/scheduler.rs
+++ b/crates/scheduler/src/scheduler.rs
@@ -53,10 +53,12 @@ impl SchedulerInterface for MockDb {}
#[async_trait::async_trait]
pub trait SchedulerAppState: Send + Sync + Clone {
fn get_tenants(&self) -> Vec<id_type::TenantId>;
+ fn get_application_source(&self) -> diesel_models::enums::ApplicationSource;
}
#[async_trait::async_trait]
pub trait SchedulerSessionState: Send + Sync + Clone {
fn get_application_source(&self) -> diesel_models::enums::ApplicationSource;
+ fn get_tenant_id(&self) -> &id_type::TenantId;
fn get_db(&self) -> Box<dyn SchedulerInterface>;
fn get_request_id(&self) -> Option<router_env::RequestId>;
fn add_request_id(&mut self, request_id: router_env::RequestId);
diff --git a/crates/storage_impl/Cargo.toml b/crates/storage_impl/Cargo.toml
index 3f15df2105..5aeee0af51 100644
--- a/crates/storage_impl/Cargo.toml
+++ b/crates/storage_impl/Cargo.toml
@@ -29,7 +29,7 @@ api_models = { version = "0.1.0", path = "../api_models" }
common_enums = { version = "0.1.0", path = "../common_enums" }
common_utils = { version = "0.1.0", path = "../common_utils" }
common_types = { version = "0.1.0", path = "../common_types" }
-deja = { git = "https://github.com/juspay/deja", rev = "9230641b943a469ef4b506c05e3e9201363f3d10", optional = true, default-features = false }
+deja = { git = "https://github.com/juspay/deja", rev = "6ace82f8d37c7c5703f9636a608dd8d85a8f6953", optional = true, default-features = false }
diesel_models = { version = "0.1.0", path = "../diesel_models", default-features = false }
hyperswitch_domain_models = { version = "0.1.0", path = "../hyperswitch_domain_models", default-features = false }
hyperswitch_masking = "0.0.1"
@@ -38,13 +38,13 @@ router_derive = { version = "0.1.0", path = "../router_derive" }
router_env = { version = "0.1.0", path = "../router_env" }
# Third party crates
-async-bb8-diesel = "0.2.1"
+async-bb8-diesel = "0.3.0"
async-trait = "0.1.92"
-bb8 = "0.8.6"
+bb8 = "0.9.1"
bytes = "1.10.1"
config = { version = "0.14.1", features = ["toml"] }
crc32fast = "1.4.2"
-diesel = { version = "2.2.10", default-features = false, features = ["postgres"] }
+diesel = { version = "2.3.12", default-features = false, features = ["postgres"] }
dyn-clone = "1.0.19"
error-stack = "0.4.1"
futures = "0.3.31"
diff --git a/crates/storage_impl/src/connection.rs b/crates/storage_impl/src/connection.rs
index cadcb86602..cae28e1aaf 100644
--- a/crates/storage_impl/src/connection.rs
+++ b/crates/storage_impl/src/connection.rs
@@ -2,34 +2,38 @@ use common_utils::errors;
use error_stack::ResultExt;
use crate::{
- database::store::DatabaseConnectionWithContext, errors::StorageError, DatabaseStore,
- RequestContext,
+ database::{pool_metrics, store::DatabaseConnectionWithContext},
+ errors::StorageError,
+ metrics, DatabaseStore, RequestContext,
};
pub async fn pg_connection_read<'a, T: DatabaseStore + RequestContext>(
store: &'a T,
) -> errors::CustomResult<DatabaseConnectionWithContext<'a>, StorageError> {
- // If only OLAP is enabled get replica pool.
+ // If only OLAP is enabled, get the replica pool.
#[cfg(all(feature = "olap", not(feature = "oltp")))]
- let pool = store.get_replica_pool();
+ let (pool, db_pool_label) = (store.get_replica_pool(), pool_metrics::DbPool::Replica);
- // If either one of these are true we need to get master pool.
+ // If either one of these is true, get the master pool:
// 1. Only OLTP is enabled.
- // 2. Both OLAP and OLTP is enabled.
- // 3. Both OLAP and OLTP is disabled.
+ // 2. Both OLAP and OLTP are enabled.
+ // 3. Both OLAP and OLTP are disabled.
#[cfg(any(
all(not(feature = "olap"), feature = "oltp"),
all(feature = "olap", feature = "oltp"),
all(not(feature = "olap"), not(feature = "oltp"))
))]
- let pool = store.get_master_pool();
+ let (pool, db_pool_label) = (store.get_master_pool(), pool_metrics::DbPool::Master);
+ let tenant_id = pool.tenant_id.get_string_repr();
#[cfg_attr(not(feature = "deja"), allow(unused_mut))]
- let mut connection = pool
- .pg_pool
- .get()
- .await
- .change_context(StorageError::DatabaseConnectionError)?;
+ let mut connection = metrics::record_db_connection_acquire_duration(
+ pool.pg_pool.get(),
+ db_pool_label,
+ tenant_id,
+ )
+ .await
+ .change_context(StorageError::DatabaseConnectionError)?;
#[cfg(feature = "deja")]
crate::utils::deja_route_replay_schema(&mut connection, store).await;
@@ -46,13 +50,16 @@ pub async fn pg_connection_write<'a, T: DatabaseStore + RequestContext>(
) -> errors::CustomResult<DatabaseConnectionWithContext<'a>, StorageError> {
// Since all writes should happen to master DB only choose master DB.
let pool = store.get_master_pool();
+ let tenant_id = pool.tenant_id.get_string_repr();
#[cfg_attr(not(feature = "deja"), allow(unused_mut))]
- let mut connection = pool
- .pg_pool
- .get()
- .await
- .change_context(StorageError::DatabaseConnectionError)?;
+ let mut connection = metrics::record_db_connection_acquire_duration(
+ pool.pg_pool.get(),
+ pool_metrics::DbPool::Master,
+ tenant_id,
+ )
+ .await
+ .change_context(StorageError::DatabaseConnectionError)?;
#[cfg(feature = "deja")]
crate::utils::deja_route_replay_schema(&mut connection, store).await;
diff --git a/crates/storage_impl/src/database.rs b/crates/storage_impl/src/database.rs
index 55c88cbf3d..fad7c3fa22 100644
--- a/crates/storage_impl/src/database.rs
+++ b/crates/storage_impl/src/database.rs
@@ -1 +1,2 @@
+pub mod pool_metrics;
pub mod store;
diff --git a/crates/storage_impl/src/database/pool_metrics.rs b/crates/storage_impl/src/database/pool_metrics.rs
new file mode 100644
index 0000000000..cf8ba79e02
--- /dev/null
+++ b/crates/storage_impl/src/database/pool_metrics.rs
@@ -0,0 +1,158 @@
+//! Observable instruments for database pool state.
+
+use common_utils::id_type::TenantId;
+use router_env::opentelemetry::metrics::{ObservableCounter, ObservableGauge};
+
+use super::store::RawPgPool;
+
+#[derive(Debug, Clone, Copy)]
+pub enum DbPool {
+ Master,
+ Replica,
+ AccountsMaster,
+ AccountsReplica,
+}
+
+impl DbPool {
+ pub(crate) fn as_str(self) -> &'static str {
+ match self {
+ Self::Master => "master",
+ Self::Replica => "replica",
+ Self::AccountsMaster => "accounts_master",
+ Self::AccountsReplica => "accounts_replica",
+ }
+ }
+}
+
+// The fields are underscore-prefixed because the handles are never read directly.
+// They exist only to keep the callbacks alive.
+#[derive(Clone)]
+pub struct PgPoolMetrics {
+ _pool_size: ObservableGauge<u64>,
+ _pool_available: ObservableGauge<u64>,
+ _pool_waiting: ObservableGauge<u64>,
+ _created_connections: ObservableCounter<u64>,
+ _closed_connections: ObservableCounter<u64>,
+}
+
+impl std::fmt::Debug for PgPoolMetrics {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("PgPoolMetrics").finish_non_exhaustive()
+ }
+}
+
+impl PgPoolMetrics {
+ pub fn new(pool: RawPgPool, db_pool: DbPool, tenant_id: &TenantId) -> Self {
+ let _pool_size = Self::build_pool_gauge(
+ "database.pool.size",
+ "Total number of connections in the database pool",
+ "{connection}",
+ db_pool,
+ pool.clone(),
+ tenant_id,
+ |p| u64::from(p.state().connections),
+ );
+
+ let _pool_available = Self::build_pool_gauge(
+ "database.pool.available",
+ "Number of idle connections in the database pool",
+ "{connection}",
+ db_pool,
+ pool.clone(),
+ tenant_id,
+ |p| u64::from(p.state().idle_connections),
+ );
+
+ let _pool_waiting = Self::build_pool_gauge(
+ "database.pool.waiting",
+ "Number of callers waiting for a database connection",
+ "{connection}",
+ db_pool,
+ pool.clone(),
+ tenant_id,
+ |p| p.state().statistics.pending_gets(),
+ );
+
+ let _created_connections = {
+ let pool_clone = pool.clone();
+ let tenant_id_clone = tenant_id.to_owned();
+ crate::metrics::GLOBAL_METER
+ .u64_observable_counter("database.pool.created")
+ .with_description("Total database connections created")
+ .with_unit("{connection}")
+ .with_callback(move |observer| {
+ let stats = pool_clone.state().statistics;
+ observer.observe(
+ stats.connections_created,
+ router_env::metric_attributes!(
+ ("pool", db_pool.as_str()),
+ ("tenant_id", tenant_id_clone.get_string_repr().to_owned())
+ ),
+ );
+ })
+ .build()
+ };
+
+ let _closed_connections = {
+ let tenant_id_clone = tenant_id.to_owned();
+ crate::metrics::GLOBAL_METER
+ .u64_observable_counter("database.pool.closed")
+ .with_description("Total database connections closed")
+ .with_unit("{connection}")
+ .with_callback(move |observer| {
+ let stats = pool.state().statistics;
+ let tenant_id_str = tenant_id_clone.get_string_repr().to_owned();
+ for (value, reason) in [
+ (stats.connections_closed_broken, "broken"),
+ (stats.connections_closed_invalid, "invalid"),
+ (stats.connections_closed_max_lifetime, "max_lifetime"),
+ (stats.connections_closed_idle_timeout, "idle_timeout"),
+ ] {
+ observer.observe(
+ value,
+ router_env::metric_attributes!(
+ ("pool", db_pool.as_str()),
+ ("tenant_id", tenant_id_str.clone()),
+ ("reason", reason)
+ ),
+ );
+ }
+ })
+ .build()
+ };
+
+ Self {
+ _pool_size,
+ _pool_available,
+ _pool_waiting,
+ _created_connections,
+ _closed_connections,
+ }
+ }
+
+ fn build_pool_gauge(
+ name: &'static str,
+ description: &'static str,
+ unit: &'static str,
+ db_pool: DbPool,
+ pool: RawPgPool,
+ tenant_id: &TenantId,
+ read: impl Fn(&RawPgPool) -> u64 + Send + Sync + 'static,
+ ) -> ObservableGauge<u64> {
+ let tenant_id = tenant_id.to_owned();
+ crate::metrics::GLOBAL_METER
+ .u64_observable_gauge(name)
+ .with_description(description)
+ .with_unit(unit)
+ .with_callback(move |observer| {
+ observer.observe(
+ read(&pool),
+ router_env::metric_attributes!(
+ ("pool", db_pool.as_str()),
+ ("tenant_id", tenant_id.get_string_repr().to_owned())
+ ),
+ );
+ })
+ .build()
+ }
+}
diff --git a/crates/storage_impl/src/database/store.rs b/crates/storage_impl/src/database/store.rs
index 0629290c8a..40ba24f43b 100644
--- a/crates/storage_impl/src/database/store.rs
+++ b/crates/storage_impl/src/database/store.rs
@@ -1,9 +1,10 @@
-use std::sync::Arc;
+use std::{future::Future, pin::Pin, sync::Arc};
use async_bb8_diesel::{AsyncConnection, ConnectionError};
use bb8::CustomizeConnection;
use common_utils::{
external_service::{ExternalServiceEventEmitter, NoOpEventEmitter},
+ id_type,
types::{keymanager, TenantConfig},
DbConnectionParams,
};
@@ -22,18 +23,31 @@ pub type RawPgPool = bb8::Pool<async_bb8_diesel::ConnectionManager<DejaPgConnect
pub struct PgPool {
pub pg_pool: RawPgPool,
pub event_emitter: Arc<dyn ExternalServiceEventEmitter>,
+ pub tenant_id: id_type::TenantId,
+ pub pool_metrics: super::pool_metrics::PgPoolMetrics,
}
impl PgPool {
- pub fn new(pg_pool: RawPgPool, event_emitter: Arc<dyn ExternalServiceEventEmitter>) -> Self {
+ pub fn new(
+ pg_pool: RawPgPool,
+ event_emitter: Arc<dyn ExternalServiceEventEmitter>,
+ tenant_id: id_type::TenantId,
+ pool_metrics: super::pool_metrics::PgPoolMetrics,
+ ) -> Self {
Self {
pg_pool,
event_emitter,
+ tenant_id,
+ pool_metrics,
}
}
- pub fn new_without_event_emitter(pool: RawPgPool) -> Self {
- Self::new(pool, Arc::new(NoOpEventEmitter))
+ pub fn new_without_event_emitter(
+ pool: RawPgPool,
+ tenant_id: id_type::TenantId,
+ pool_metrics: super::pool_metrics::PgPoolMetrics,
+ ) -> Self {
+ Self::new(pool, Arc::new(NoOpEventEmitter), tenant_id, pool_metrics)
}
}
@@ -89,6 +103,8 @@ impl DatabaseStore for Store {
tenant_config.get_schema(),
test_transaction,
Arc::clone(&event_emitter),
+ super::pool_metrics::DbPool::Master,
+ tenant_config.get_tenant_id(),
)
.await?,
accounts_pool: diesel_make_pg_pool(
@@ -96,6 +112,8 @@ impl DatabaseStore for Store {
tenant_config.get_accounts_schema(),
test_transaction,
event_emitter,
+ super::pool_metrics::DbPool::AccountsMaster,
+ tenant_config.get_tenant_id(),
)
.await?,
})
@@ -144,6 +162,8 @@ impl DatabaseStore for ReplicaStore {
tenant_config.get_schema(),
test_transaction,
Arc::clone(&event_emitter),
+ super::pool_metrics::DbPool::Master,
+ tenant_config.get_tenant_id(),
)
.await
.attach_printable("failed to create master pool")?;
@@ -152,6 +172,8 @@ impl DatabaseStore for ReplicaStore {
tenant_config.get_accounts_schema(),
test_transaction,
Arc::clone(&event_emitter),
+ super::pool_metrics::DbPool::AccountsMaster,
+ tenant_config.get_tenant_id(),
)
.await
.attach_printable("failed to create accounts master pool")?;
@@ -160,6 +182,8 @@ impl DatabaseStore for ReplicaStore {
tenant_config.get_schema(),
test_transaction,
Arc::clone(&event_emitter),
+ super::pool_metrics::DbPool::Replica,
+ tenant_config.get_tenant_id(),
)
.await
.attach_printable("failed to create replica pool")?;
@@ -169,6 +193,8 @@ impl DatabaseStore for ReplicaStore {
tenant_config.get_accounts_schema(),
test_transaction,
event_emitter,
+ super::pool_metrics::DbPool::AccountsReplica,
+ tenant_config.get_tenant_id(),
)
.await
.attach_printable("failed to create accounts pool")?;
@@ -202,6 +228,8 @@ pub async fn diesel_make_pg_pool(
schema: &str,
test_transaction: bool,
event_emitter: Arc<dyn ExternalServiceEventEmitter>,
+ db_pool: super::pool_metrics::DbPool,
+ tenant_id: &id_type::TenantId,
) -> StorageResult<PgPool> {
let database_url = database.get_database_url(schema);
let manager = async_bb8_diesel::ConnectionManager::<DejaPgConnection>::new(database_url);
@@ -254,22 +282,34 @@ pub async fn diesel_make_pg_pool(
}
}
- Ok(PgPool::new(raw_pool, event_emitter))
+ let pool_metrics =
+ super::pool_metrics::PgPoolMetrics::new(raw_pool.clone(), db_pool, tenant_id);
+
+ Ok(PgPool::new(
+ raw_pool,
+ event_emitter,
+ tenant_id.clone(),
+ pool_metrics,
+ ))
}
#[derive(Debug)]
struct TestTransaction;
-#[async_trait::async_trait]
impl CustomizeConnection<RawPgConnection, ConnectionError> for TestTransaction {
#[allow(clippy::unwrap_used)]
- async fn on_acquire(&self, conn: &mut RawPgConnection) -> Result<(), ConnectionError> {
- use diesel::Connection;
+ fn on_acquire<'a>(
+ &'a self,
+ conn: &'a mut RawPgConnection,
+ ) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'a>> {
+ Box::pin(async move {
+ use diesel::Connection;
- conn.run(|conn| {
- conn.begin_test_transaction().unwrap();
- Ok(())
+ conn.run(|conn| {
+ conn.begin_test_transaction().unwrap();
+ Ok(())
+ })
+ .await
})
- .await
}
}
diff --git a/crates/storage_impl/src/metrics.rs b/crates/storage_impl/src/metrics.rs
index e79b49d16a..105a626242 100644
--- a/crates/storage_impl/src/metrics.rs
+++ b/crates/storage_impl/src/metrics.rs
@@ -1,4 +1,4 @@
-use router_env::{counter_metric, gauge_metric, global_meter};
+use router_env::{counter_metric, gauge_metric, global_meter, histogram_metric_f64};
global_meter!(GLOBAL_METER, "ROUTER_API");
@@ -29,3 +29,32 @@ counter_metric!(IN_MEMORY_CACHE_INVARIANT_VIOLATION, GLOBAL_METER); // Unreachab
// Metrics for cache invalidation
counter_metric!(CACHE_REDACTION_FAILURE_COUNT, GLOBAL_METER);
+
+// Metrics for database
+histogram_metric_f64!(DATABASE_CONNECTION_ACQUIRE_DURATION, GLOBAL_METER);
+
+pub async fn record_db_connection_acquire_duration<Fut, T, E>(
+ future: Fut,
+ db_pool: crate::database::pool_metrics::DbPool,
+ tenant_id: &str,
+) -> Result<T, E>
+where
+ Fut: std::future::Future<Output = Result<T, E>>,
+{
+ let start = std::time::Instant::now();
+ let result = future.await;
+ let duration = start.elapsed();
+ let outcome = if result.is_ok() { "success" } else { "error" };
+ let tenant_id = tenant_id.to_owned();
+
+ DATABASE_CONNECTION_ACQUIRE_DURATION.record(
+ duration.as_secs_f64(),
+ router_env::metric_attributes!(
+ ("pool", db_pool.as_str()),
+ ("outcome", outcome),
+ ("tenant_id", tenant_id)
+ ),
+ );
+
+ result
+}
diff --git a/crates/storage_impl/src/utils.rs b/crates/storage_impl/src/utils.rs
index 0383b5404f..3ac793b628 100644
--- a/crates/storage_impl/src/utils.rs
+++ b/crates/storage_impl/src/utils.rs
@@ -5,7 +5,7 @@ use diesel_models::DejaPgConnection;
use error_stack::ResultExt;
use crate::{
- database::store::DatabaseConnectionWithContext,
+ database::{pool_metrics, store::DatabaseConnectionWithContext},
errors::{RedisErrorExt, StorageError},
metrics, DatabaseStore, RequestContext,
};
@@ -132,27 +132,30 @@ fn deja_replay_route_warn_no_correlation() {
pub async fn pg_connection_read<'a, T: DatabaseStore + RequestContext>(
store: &'a T,
) -> error_stack::Result<DatabaseConnectionWithContext<'a>, StorageError> {
- // If only OLAP is enabled get replica pool.
+ // If only OLAP is enabled, get the replica pool.
#[cfg(all(feature = "olap", not(feature = "oltp")))]
- let pool = store.get_replica_pool();
+ let (pool, db_pool_label) = (store.get_replica_pool(), pool_metrics::DbPool::Replica);
- // If either one of these are true we need to get master pool.
+ // If either one of these is true, get the master pool:
// 1. Only OLTP is enabled.
- // 2. Both OLAP and OLTP is enabled.
- // 3. Both OLAP and OLTP is disabled.
+ // 2. Both OLAP and OLTP are enabled.
+ // 3. Both OLAP and OLTP are disabled.
#[cfg(any(
all(not(feature = "olap"), feature = "oltp"),
all(feature = "olap", feature = "oltp"),
all(not(feature = "olap"), not(feature = "oltp"))
))]
- let pool = store.get_master_pool();
+ let (pool, db_pool_label) = (store.get_master_pool(), pool_metrics::DbPool::Master);
+ let tenant_id = pool.tenant_id.get_string_repr();
#[cfg_attr(not(feature = "deja"), allow(unused_mut))]
- let mut connection = pool
- .pg_pool
- .get()
- .await
- .change_context(StorageError::DatabaseConnectionError)?;
+ let mut connection = metrics::record_db_connection_acquire_duration(
+ pool.pg_pool.get(),
+ db_pool_label,
+ tenant_id,
+ )
+ .await
+ .change_context(StorageError::DatabaseConnectionError)?;
#[cfg(feature = "deja")]
deja_route_replay_schema(&mut connection, store).await;
@@ -175,13 +178,16 @@ pub async fn pg_connection_read_replica<'a, T: DatabaseStore + RequestContext>(
store: &'a T,
) -> error_stack::Result<DatabaseConnectionWithContext<'a>, StorageError> {
let pool = store.get_replica_pool();
+ let tenant_id = pool.tenant_id.get_string_repr();
#[cfg_attr(not(feature = "deja"), allow(unused_mut))]
- let mut connection = pool
- .pg_pool
- .get()
- .await
- .change_context(StorageError::DatabaseConnectionError)?;
+ let mut connection = metrics::record_db_connection_acquire_duration(
+ pool.pg_pool.get(),
+ pool_metrics::DbPool::Replica,
+ tenant_id,
+ )
+ .await
+ .change_context(StorageError::DatabaseConnectionError)?;
#[cfg(feature = "deja")]
deja_route_replay_schema(&mut connection, store).await;
@@ -198,13 +204,16 @@ pub async fn pg_connection_write<'a, T: DatabaseStore + RequestContext>(
) -> error_stack::Result<DatabaseConnectionWithContext<'a>, StorageError> {
// Since all writes should happen to master DB only choose master DB.
let pool = store.get_master_pool();
+ let tenant_id = pool.tenant_id.get_string_repr();
#[cfg_attr(not(feature = "deja"), allow(unused_mut))]
- let mut connection = pool
- .pg_pool
- .get()
- .await
- .change_context(StorageError::DatabaseConnectionError)?;
+ let mut connection = metrics::record_db_connection_acquire_duration(
+ pool.pg_pool.get(),
+ pool_metrics::DbPool::Master,
+ tenant_id,
+ )
+ .await
+ .change_context(StorageError::DatabaseConnectionError)?;
#[cfg(feature = "deja")]
deja_route_replay_schema(&mut connection, store).await;
@@ -219,27 +228,36 @@ pub async fn pg_connection_write<'a, T: DatabaseStore + RequestContext>(
pub async fn pg_accounts_connection_read<'a, T: DatabaseStore + RequestContext>(
store: &'a T,
) -> error_stack::Result<DatabaseConnectionWithContext<'a>, StorageError> {
- // If only OLAP is enabled get replica pool.
+ // If only OLAP is enabled, get the replica pool.
#[cfg(all(feature = "olap", not(feature = "oltp")))]
- let pool = store.get_accounts_replica_pool();
+ let (pool, db_pool_label) = (
+ store.get_accounts_replica_pool(),
+ pool_metrics::DbPool::AccountsReplica,
+ );
- // If either one of these are true we need to get master pool.
+ // If either one of these is true, get the master pool:
// 1. Only OLTP is enabled.
- // 2. Both OLAP and OLTP is enabled.
- // 3. Both OLAP and OLTP is disabled.
+ // 2. Both OLAP and OLTP are enabled.
+ // 3. Both OLAP and OLTP are disabled.
#[cfg(any(
all(not(feature = "olap"), feature = "oltp"),
all(feature = "olap", feature = "oltp"),
all(not(feature = "olap"), not(feature = "oltp"))
))]
- let pool = store.get_accounts_master_pool();
+ let (pool, db_pool_label) = (
+ store.get_accounts_master_pool(),
+ pool_metrics::DbPool::AccountsMaster,
+ );
+ let tenant_id = pool.tenant_id.get_string_repr();
#[cfg_attr(not(feature = "deja"), allow(unused_mut))]
- let mut connection = pool
- .pg_pool
- .get()
- .await
- .change_context(StorageError::DatabaseConnectionError)?;
+ let mut connection = metrics::record_db_connection_acquire_duration(
+ pool.pg_pool.get(),
+ db_pool_label,
+ tenant_id,
+ )
+ .await
+ .change_context(StorageError::DatabaseConnectionError)?;
#[cfg(feature = "deja")]
deja_route_replay_schema(&mut connection, store).await;
@@ -257,12 +275,16 @@ pub async fn pg_accounts_connection_write<'a, T: DatabaseStore + RequestContext>
// Since all writes should happen to master DB only choose master DB.
let pool = store.get_accounts_master_pool();
+ let tenant_id = pool.tenant_id.get_string_repr();
+
#[cfg_attr(not(feature = "deja"), allow(unused_mut))]
- let mut connection = pool
- .pg_pool
- .get()
- .await
- .change_context(StorageError::DatabaseConnectionError)?;
+ let mut connection = metrics::record_db_connection_acquire_duration(
+ pool.pg_pool.get(),
+ pool_metrics::DbPool::AccountsMaster,
+ tenant_id,
+ )
+ .await
+ .change_context(StorageError::DatabaseConnectionError)?;
#[cfg(feature = "deja")]
deja_route_replay_schema(&mut connection, store).await;