diff --git a/Cargo.lock b/Cargo.lock index a4b6a9cc21d..4d0086b8640 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,9 +30,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.7" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "getrandom 0.2.11", @@ -41,15 +41,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "aho-corasick" -version = "0.7.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" -dependencies = [ - "memchr", -] - [[package]] name = "aho-corasick" version = "1.0.3" @@ -214,15 +205,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "atomic-shim" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67cd4b51d303cf3501c301e8125df442128d3c6d7c69f71b27833d253de47e77" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "atty" version = "0.2.14" @@ -447,7 +429,7 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8a88e82b9106923b5c4d6edfca9e7db958d4e98a478ec115022e81b9b38e2c8" dependencies = [ - "ahash 0.8.7", + "ahash 0.8.11", "base64 0.13.1", "bitvec", "chrono", @@ -512,9 +494,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.4.0" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cast" @@ -543,11 +525,11 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.83" +version = "1.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" dependencies = [ - "libc", + "shlex", ] [[package]] @@ -1101,7 +1083,7 @@ dependencies = [ "hashbrown 0.14.5", "lock_api", "once_cell", - "parking_lot_core 0.9.8", + "parking_lot_core", ] [[package]] @@ -1226,7 +1208,7 @@ dependencies = [ "expect-test", "futures", "js-sys", - "metrics 0.18.1", + "metrics", "napi", "napi-derive", "once_cell", @@ -1631,7 +1613,7 @@ checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" dependencies = [ "futures-core", "lock_api", - "parking_lot 0.12.1", + "parking_lot", ] [[package]] @@ -1781,15 +1763,6 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash 0.7.8", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -1805,7 +1778,7 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ - "ahash 0.8.7", + "ahash 0.8.11", "allocator-api2", ] @@ -1890,7 +1863,7 @@ dependencies = [ "ipconfig", "lru-cache", "once_cell", - "parking_lot 0.12.1", + "parking_lot", "rand 0.8.5", "resolv-conf", "smallvec", @@ -2138,15 +2111,6 @@ dependencies = [ "yaml-rust", ] -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - [[package]] name = "ipconfig" version = "0.3.2" @@ -2444,15 +2408,6 @@ dependencies = [ "url", ] -[[package]] -name = "mach" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" -dependencies = [ - "libc", -] - [[package]] name = "match_cfg" version = "0.1.0" @@ -2500,91 +2455,47 @@ dependencies = [ [[package]] name = "metrics" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e52eb6380b6d2a10eb3434aec0885374490f5b82c8aaf5cd487a183c98be834" -dependencies = [ - "ahash 0.7.8", - "metrics-macros", -] - -[[package]] -name = "metrics" -version = "0.19.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "142c53885123b68d94108295a09d4afe1a1388ed95b54d5dacd9a454753030f2" +checksum = "884adb57038347dfbaf2d5065887b6cf4312330dc8e94bc30a1a839bd79d3261" dependencies = [ - "ahash 0.7.8", - "metrics-macros", + "ahash 0.8.11", + "portable-atomic", ] [[package]] name = "metrics-exporter-prometheus" -version = "0.10.0" +version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953cbbb6f9ba4b9304f4df79b98cdc9d14071ed93065a9fca11c00c5d9181b66" +checksum = "b4f0c8427b39666bf970460908b213ec09b3b350f20c0c2eabcbba51704a08e6" dependencies = [ - "hyper", - "indexmap 1.9.3", - "ipnet", - "metrics 0.19.0", - "metrics-util 0.13.0", - "parking_lot 0.11.2", + "base64 0.22.1", + "indexmap 2.2.2", + "metrics", + "metrics-util", "quanta", "thiserror", - "tokio", - "tracing", -] - -[[package]] -name = "metrics-macros" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49e30813093f757be5cf21e50389a24dc7dbb22c49f23b7e8f51d69b508a5ffa" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", ] [[package]] name = "metrics-util" -version = "0.12.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65a9e83b833e1d2e07010a386b197c13aa199bbd0fca5cf69bfa147972db890a" +checksum = "4259040465c955f9f2f1a4a8a16dc46726169bca0f88e8fb2dbeced487c3e828" dependencies = [ - "aho-corasick 0.7.20", - "atomic-shim", + "aho-corasick", "crossbeam-epoch", "crossbeam-utils", - "hashbrown 0.11.2", - "indexmap 1.9.3", - "metrics 0.18.1", + "hashbrown 0.14.5", + "indexmap 2.2.2", + "metrics", "num_cpus", "ordered-float", - "parking_lot 0.11.2", "quanta", "radix_trie", "sketches-ddsketch", ] -[[package]] -name = "metrics-util" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd1f4b69bef1e2b392b2d4a12902f2af90bb438ba4a66aa222d1023fa6561b50" -dependencies = [ - "atomic-shim", - "crossbeam-epoch", - "crossbeam-utils", - "hashbrown 0.11.2", - "metrics 0.19.0", - "num_cpus", - "parking_lot 0.11.2", - "quanta", - "sketches-ddsketch", -] - [[package]] name = "mime" version = "0.3.17" @@ -2620,9 +2531,9 @@ dependencies = [ [[package]] name = "mobc" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90eb49dc5d193287ff80e72a86f34cfb27aae562299d22fea215e06ea1059dd3" +checksum = "316a7d198b51958a0ab57248bf5f42d8409551203cb3c821d5925819a8d5415f" dependencies = [ "async-trait", "futures-channel", @@ -2630,7 +2541,7 @@ dependencies = [ "futures-timer", "futures-util", "log", - "metrics 0.18.1", + "metrics", "thiserror", "tokio", "tracing", @@ -3217,9 +3128,9 @@ dependencies = [ [[package]] name = "ordered-float" -version = "2.10.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7940cf2ca942593318d07fcf2596cdca60a85c9e7fab408a5e21a4f9dcd40d87" +checksum = "44d501f1a72f71d3c063a6bbc8f7271fa73aa09fe5d6283b6571e2ed176a2537" dependencies = [ "num-traits", ] @@ -3248,17 +3159,6 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.6", -] - [[package]] name = "parking_lot" version = "0.12.1" @@ -3266,21 +3166,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.8", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "winapi", + "parking_lot_core", ] [[package]] @@ -3291,7 +3177,7 @@ checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.3.5", + "redox_syscall", "smallvec", "windows-targets 0.48.1", ] @@ -3515,6 +3401,12 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + [[package]] name = "postgres-native-tls" version = "0.5.0" @@ -3842,7 +3734,7 @@ dependencies = [ "indoc 0.3.6", "itertools 0.12.0", "lru-cache", - "metrics 0.18.1", + "metrics", "mobc", "mysql_async", "names 0.11.0", @@ -3898,16 +3790,15 @@ dependencies = [ [[package]] name = "quanta" -version = "0.9.3" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20afe714292d5e879d8b12740aa223c6a88f118af41870e8b6196e39a02238a8" +checksum = "8e5167a477619228a0b284fac2674e3c388cba90631d7b7de620e6f1fcd08da5" dependencies = [ "crossbeam-utils", "libc", - "mach", "once_cell", "raw-cpuid", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi 0.11.0+wasi-snapshot-preview1", "web-sys", "winapi", ] @@ -4069,11 +3960,11 @@ name = "query-engine-metrics" version = "0.1.0" dependencies = [ "expect-test", - "metrics 0.18.1", + "metrics", "metrics-exporter-prometheus", - "metrics-util 0.12.1", + "metrics-util", "once_cell", - "parking_lot 0.12.1", + "parking_lot", "serde", "serde_json", "tokio", @@ -4388,11 +4279,11 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "10.7.0" +version = "11.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332" +checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.0", ] [[package]] @@ -4426,15 +4317,6 @@ dependencies = [ "rand_core 0.3.1", ] -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.3.5" @@ -4450,7 +4332,7 @@ version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ - "aho-corasick 1.0.3", + "aho-corasick", "memchr", "regex-automata 0.4.5", "regex-syntax 0.8.2", @@ -4471,7 +4353,7 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ - "aho-corasick 1.0.3", + "aho-corasick", "memchr", "regex-syntax 0.8.2", ] @@ -5069,7 +4951,7 @@ dependencies = [ "futures", "lazy_static", "log", - "parking_lot 0.12.1", + "parking_lot", "serial_test_derive", ] @@ -5187,9 +5069,9 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" [[package]] name = "sketches-ddsketch" -version = "0.1.3" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04d2ecae5fcf33b122e2e6bd520a57ccf152d2dde3b38c71039df1a6867264ee" +checksum = "85636c14b73d81f541e525f585c0a2109e6744e1565b5c1668e31c70c10ed65c" [[package]] name = "slab" @@ -5202,9 +5084,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.0" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" @@ -5616,7 +5498,7 @@ checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" dependencies = [ "cfg-if", "fastrand", - "redox_syscall 0.3.5", + "redox_syscall", "rustix", "windows-sys 0.48.0", ] @@ -5820,7 +5702,7 @@ dependencies = [ "libc", "mio", "num_cpus", - "parking_lot 0.12.1", + "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2 0.5.7", @@ -5871,7 +5753,7 @@ dependencies = [ "futures-channel", "futures-util", "log", - "parking_lot 0.12.1", + "parking_lot", "percent-encoding", "phf", "pin-project-lite", @@ -6446,12 +6328,6 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 41b65506b5a..cac859cf4b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ napi = { version = "2.15.1", default-features = false, features = [ "serde-json", ] } napi-derive = "2.15.0" +metrics = "0.23.0" js-sys = { version = "0.3" } rand = { version = "0.8" } regex = { version = "1", features = ["std"] } diff --git a/quaint/Cargo.toml b/quaint/Cargo.toml index ff95dab0a87..cfac06e101d 100644 --- a/quaint/Cargo.toml +++ b/quaint/Cargo.toml @@ -76,7 +76,7 @@ tracing-core = "0.1" async-trait.workspace = true thiserror = "1.0" num_cpus = "1.12" -metrics = "0.18" +metrics.workspace = true futures = "0.3" url.workspace = true hex = "0.4" @@ -92,7 +92,7 @@ serde_json.workspace = true native-tls = { version = "0.2", optional = true } bit-vec = { version = "0.6.1", optional = true } bytes = { version = "1.0", optional = true } -mobc = { version = "0.8", optional = true } +mobc = { version = "0.8.5", optional = true } serde = { version = "1.0" } sqlformat = { version = "0.2.3", optional = true } uuid.workspace = true diff --git a/quaint/src/connector/metrics.rs b/quaint/src/connector/metrics.rs index a0c4ef42698..2e2e4d18922 100644 --- a/quaint/src/connector/metrics.rs +++ b/quaint/src/connector/metrics.rs @@ -46,9 +46,9 @@ where trace_query(query, params, result, &start); } - histogram!(format!("{tag}.query.time"), start.elapsed_time()); - histogram!("prisma_datasource_queries_duration_histogram_ms", start.elapsed_time()); - increment_counter!("prisma_datasource_queries_total"); + histogram!(format!("{tag}.query.time")).record(start.elapsed_time()); + histogram!("prisma_datasource_queries_duration_histogram_ms").record(start.elapsed_time()); + counter!("prisma_datasource_queries_total").increment(1); res } @@ -74,7 +74,7 @@ where result, ); - histogram!("pool.check_out", start.elapsed_time()); + histogram!("pool.check_out").record(start.elapsed_time()); res } diff --git a/quaint/src/connector/transaction.rs b/quaint/src/connector/transaction.rs index df4084883e8..e0fd3cf6179 100644 --- a/quaint/src/connector/transaction.rs +++ b/quaint/src/connector/transaction.rs @@ -4,7 +4,7 @@ use crate::{ error::{Error, ErrorKind}, }; use async_trait::async_trait; -use metrics::{decrement_gauge, increment_gauge}; +use metrics::gauge; use std::{fmt, str::FromStr}; extern crate metrics as metrics; @@ -62,7 +62,7 @@ impl<'a> DefaultTransaction<'a> { inner.server_reset_query(&this).await?; - increment_gauge!("prisma_client_queries_active", 1.0); + gauge!("prisma_client_queries_active").increment(1.0); Ok(this) } } @@ -71,7 +71,7 @@ impl<'a> DefaultTransaction<'a> { impl<'a> Transaction for DefaultTransaction<'a> { /// Commit the changes to the database and consume the transaction. async fn commit(&self) -> crate::Result<()> { - decrement_gauge!("prisma_client_queries_active", 1.0); + gauge!("prisma_client_queries_active").decrement(1.0); self.inner.raw_cmd("COMMIT").await?; Ok(()) @@ -79,7 +79,7 @@ impl<'a> Transaction for DefaultTransaction<'a> { /// Rolls back the changes to the database. async fn rollback(&self) -> crate::Result<()> { - decrement_gauge!("prisma_client_queries_active", 1.0); + gauge!("prisma_client_queries_active").decrement(1.0); self.inner.raw_cmd("ROLLBACK").await?; Ok(()) diff --git a/query-engine/connectors/mongodb-query-connector/src/interface/transaction.rs b/query-engine/connectors/mongodb-query-connector/src/interface/transaction.rs index 2fe5d840fa1..41a5162dad7 100644 --- a/query-engine/connectors/mongodb-query-connector/src/interface/transaction.rs +++ b/query-engine/connectors/mongodb-query-connector/src/interface/transaction.rs @@ -5,7 +5,7 @@ use crate::{ }; use connector_interface::{ConnectionLike, ReadOperations, Transaction, UpdateType, WriteOperations}; use mongodb::options::{Acknowledgment, ReadConcern, TransactionOptions, WriteConcern}; -use query_engine_metrics::{decrement_gauge, increment_gauge, metrics, PRISMA_CLIENT_QUERIES_ACTIVE}; +use query_engine_metrics::{gauge, PRISMA_CLIENT_QUERIES_ACTIVE}; use query_structure::{RelationLoadStrategy, SelectionResult}; use std::collections::HashMap; @@ -31,7 +31,7 @@ impl<'conn> MongoDbTransaction<'conn> { .await .map_err(|err| MongoError::from(err).into_connector_error())?; - increment_gauge!(PRISMA_CLIENT_QUERIES_ACTIVE, 1.0); + gauge!(PRISMA_CLIENT_QUERIES_ACTIVE).increment(1.0); Ok(Self { connection }) } @@ -40,7 +40,7 @@ impl<'conn> MongoDbTransaction<'conn> { #[async_trait] impl<'conn> Transaction for MongoDbTransaction<'conn> { async fn commit(&mut self) -> connector_interface::Result<()> { - decrement_gauge!(PRISMA_CLIENT_QUERIES_ACTIVE, 1.0); + gauge!(PRISMA_CLIENT_QUERIES_ACTIVE).decrement(1.0); utils::commit_with_retry(&mut self.connection.session) .await @@ -50,7 +50,7 @@ impl<'conn> Transaction for MongoDbTransaction<'conn> { } async fn rollback(&mut self) -> connector_interface::Result<()> { - decrement_gauge!(PRISMA_CLIENT_QUERIES_ACTIVE, 1.0); + gauge!(PRISMA_CLIENT_QUERIES_ACTIVE).decrement(1.0); self.connection .session diff --git a/query-engine/connectors/mongodb-query-connector/src/root_queries/mod.rs b/query-engine/connectors/mongodb-query-connector/src/root_queries/mod.rs index 9ee217d62a8..1c25661b234 100644 --- a/query-engine/connectors/mongodb-query-connector/src/root_queries/mod.rs +++ b/query-engine/connectors/mongodb-query-connector/src/root_queries/mod.rs @@ -14,8 +14,7 @@ use bson::Bson; use bson::Document; use futures::Future; use query_engine_metrics::{ - histogram, increment_counter, metrics, PRISMA_DATASOURCE_QUERIES_DURATION_HISTOGRAM_MS, - PRISMA_DATASOURCE_QUERIES_TOTAL, + counter, histogram, PRISMA_DATASOURCE_QUERIES_DURATION_HISTOGRAM_MS, PRISMA_DATASOURCE_QUERIES_TOTAL, }; use query_structure::*; use std::sync::Arc; @@ -76,8 +75,8 @@ where let res = f().instrument(span).await; let elapsed = start.elapsed().as_millis() as f64; - histogram!(PRISMA_DATASOURCE_QUERIES_DURATION_HISTOGRAM_MS, elapsed); - increment_counter!(PRISMA_DATASOURCE_QUERIES_TOTAL); + histogram!(PRISMA_DATASOURCE_QUERIES_DURATION_HISTOGRAM_MS).record(elapsed); + counter!(PRISMA_DATASOURCE_QUERIES_TOTAL).increment(1); // TODO prisma/team-orm#136: fix log subscription. // NOTE: `params` is a part of the interface for query logs. diff --git a/query-engine/core/src/executor/execute_operation.rs b/query-engine/core/src/executor/execute_operation.rs index 6ef445d8364..b68979f1335 100644 --- a/query-engine/core/src/executor/execute_operation.rs +++ b/query-engine/core/src/executor/execute_operation.rs @@ -12,7 +12,7 @@ use futures::future; #[cfg(feature = "metrics")] use query_engine_metrics::{ - histogram, increment_counter, metrics, PRISMA_CLIENT_QUERIES_DURATION_HISTOGRAM_MS, PRISMA_CLIENT_QUERIES_TOTAL, + counter, histogram, PRISMA_CLIENT_QUERIES_DURATION_HISTOGRAM_MS, PRISMA_CLIENT_QUERIES_TOTAL, }; use schema::{QuerySchema, QuerySchemaRef}; @@ -32,10 +32,7 @@ pub async fn execute_single_operation( let result = execute_on(conn, graph, serializer, query_schema.as_ref(), trace_id).await; #[cfg(feature = "metrics")] - histogram!( - PRISMA_CLIENT_QUERIES_DURATION_HISTOGRAM_MS, - operation_timer.elapsed_time() - ); + histogram!(PRISMA_CLIENT_QUERIES_DURATION_HISTOGRAM_MS).record(operation_timer.elapsed_time()); result } @@ -58,10 +55,7 @@ pub async fn execute_many_operations( let result = execute_on(conn, graph, serializer, query_schema.as_ref(), trace_id.clone()).await; #[cfg(feature = "metrics")] - histogram!( - PRISMA_CLIENT_QUERIES_DURATION_HISTOGRAM_MS, - operation_timer.elapsed_time() - ); + histogram!(PRISMA_CLIENT_QUERIES_DURATION_HISTOGRAM_MS).record(operation_timer.elapsed_time()); match result { Ok(result) => results.push(Ok(result)), @@ -115,7 +109,7 @@ pub async fn execute_many_self_contained( let dispatcher = crate::get_current_dispatcher(); for op in operations { #[cfg(feature = "metrics")] - increment_counter!(PRISMA_CLIENT_QUERIES_TOTAL); + counter!(PRISMA_CLIENT_QUERIES_TOTAL).increment(1); let conn_span = info_span!( "prisma:engine:connection", @@ -176,10 +170,7 @@ async fn execute_self_contained( }; #[cfg(feature = "metrics")] - histogram!( - PRISMA_CLIENT_QUERIES_DURATION_HISTOGRAM_MS, - operation_timer.elapsed_time() - ); + histogram!(PRISMA_CLIENT_QUERIES_DURATION_HISTOGRAM_MS).record(operation_timer.elapsed_time()); result } @@ -281,7 +272,7 @@ async fn execute_on<'a>( trace_id: Option, ) -> crate::Result { #[cfg(feature = "metrics")] - increment_counter!(PRISMA_CLIENT_QUERIES_TOTAL); + counter!(PRISMA_CLIENT_QUERIES_TOTAL).increment(1); let interpreter = QueryInterpreter::new(conn); QueryPipeline::new(graph, interpreter, serializer) diff --git a/query-engine/driver-adapters/Cargo.toml b/query-engine/driver-adapters/Cargo.toml index 39a0314a476..767780ff65d 100644 --- a/query-engine/driver-adapters/Cargo.toml +++ b/query-engine/driver-adapters/Cargo.toml @@ -15,7 +15,7 @@ serde.workspace = true serde_json.workspace = true tracing.workspace = true tracing-core = "0.1" -metrics = "0.18" +metrics.workspace = true uuid.workspace = true pin-project = "1" serde_repr.workspace = true diff --git a/query-engine/driver-adapters/src/proxy.rs b/query-engine/driver-adapters/src/proxy.rs index 1c2a5a68240..65447c0b95e 100644 --- a/query-engine/driver-adapters/src/proxy.rs +++ b/query-engine/driver-adapters/src/proxy.rs @@ -7,7 +7,7 @@ use crate::{ use crate::{send_future::UnsafeFuture, transaction::JsTransactionContext}; use futures::Future; -use metrics::increment_gauge; +use metrics::gauge; use std::sync::atomic::{AtomicBool, Ordering}; /// Proxy is a struct wrapping a javascript object that exhibits basic primitives for @@ -121,7 +121,7 @@ impl TransactionContextProxy { // Previously, it was done in JsTransaction::new, similar to the native Transaction. // However, correct Dispatcher is lost there and increment does not register, so we moved // it here instead. - increment_gauge!("prisma_client_queries_active", 1.0); + gauge!("prisma_client_queries_active").increment(1.0); Ok(Box::new(tx)) } diff --git a/query-engine/driver-adapters/src/transaction.rs b/query-engine/driver-adapters/src/transaction.rs index 8d124bd4da0..1578eaf3220 100644 --- a/query-engine/driver-adapters/src/transaction.rs +++ b/query-engine/driver-adapters/src/transaction.rs @@ -1,7 +1,7 @@ use std::future::Future; use async_trait::async_trait; -use metrics::decrement_gauge; +use metrics::gauge; use quaint::{ connector::{DescribedQuery, IsolationLevel, Transaction as QuaintTransaction}, prelude::{Query as QuaintQuery, Queryable, ResultSet}, @@ -107,7 +107,7 @@ impl JsTransaction { impl QuaintTransaction for JsTransaction { async fn commit(&self) -> quaint::Result<()> { // increment of this gauge is done in DriverProxy::startTransaction - decrement_gauge!("prisma_client_queries_active", 1.0); + gauge!("prisma_client_queries_active").decrement(1.0); let commit_stmt = "COMMIT"; @@ -123,7 +123,7 @@ impl QuaintTransaction for JsTransaction { async fn rollback(&self) -> quaint::Result<()> { // increment of this gauge is done in DriverProxy::startTransaction - decrement_gauge!("prisma_client_queries_active", 1.0); + gauge!("prisma_client_queries_active").decrement(1.0); let rollback_stmt = "ROLLBACK"; diff --git a/query-engine/metrics/Cargo.toml b/query-engine/metrics/Cargo.toml index 5593b246c09..0abe32ac845 100644 --- a/query-engine/metrics/Cargo.toml +++ b/query-engine/metrics/Cargo.toml @@ -4,9 +4,9 @@ version = "0.1.0" edition = "2021" [dependencies] -metrics = "0.18" -metrics-util = "0.12.1" -metrics-exporter-prometheus = "0.10.0" +metrics.workspace = true +metrics-util = "0.17.0" +metrics-exporter-prometheus = { version = "0.15.3", default-features = false } once_cell = "1.3" serde.workspace = true serde_json.workspace = true diff --git a/query-engine/metrics/src/lib.rs b/query-engine/metrics/src/lib.rs index 1965b56cb07..9a041102c4b 100644 --- a/query-engine/metrics/src/lib.rs +++ b/query-engine/metrics/src/lib.rs @@ -38,10 +38,7 @@ use std::collections::HashMap; use std::sync::Once; pub extern crate metrics; -pub use metrics::{ - absolute_counter, decrement_gauge, describe_counter, describe_gauge, describe_histogram, gauge, histogram, - increment_counter, increment_gauge, -}; +pub use metrics::{counter, describe_counter, describe_gauge, describe_histogram, gauge, histogram}; // Metrics that we emit from the engines, third party metrics emitted by libraries and that we rename are omitted. pub const PRISMA_CLIENT_QUERIES_TOTAL: &str = "prisma_client_queries_total"; // counter @@ -102,9 +99,7 @@ pub fn setup() { static METRIC_RECORDER: Once = Once::new(); fn set_recorder() { - METRIC_RECORDER.call_once(|| { - metrics::set_boxed_recorder(Box::new(MetricRecorder)).unwrap(); - }); + METRIC_RECORDER.call_once(|| metrics::set_global_recorder(MetricRecorder).unwrap()); } /// Initialize metrics descriptions and values @@ -145,15 +140,15 @@ fn initialize_metrics_descriptions() { /// Histograms are excluded, as their initialization will alter the histogram values. /// (i.e. histograms don't have a neutral value, like counters or gauges) fn initialize_metrics_values() { - absolute_counter!(PRISMA_CLIENT_QUERIES_TOTAL, 0); - absolute_counter!(PRISMA_DATASOURCE_QUERIES_TOTAL, 0); - gauge!(PRISMA_CLIENT_QUERIES_ACTIVE, 0.0); - absolute_counter!(MOBC_POOL_CONNECTIONS_OPENED_TOTAL, 0); - absolute_counter!(MOBC_POOL_CONNECTIONS_CLOSED_TOTAL, 0); - gauge!(MOBC_POOL_CONNECTIONS_OPEN, 0.0); - gauge!(MOBC_POOL_CONNECTIONS_BUSY, 0.0); - gauge!(MOBC_POOL_CONNECTIONS_IDLE, 0.0); - gauge!(MOBC_POOL_WAIT_COUNT, 0.0); + counter!(PRISMA_CLIENT_QUERIES_TOTAL).absolute(0); + counter!(PRISMA_DATASOURCE_QUERIES_TOTAL).absolute(0); + gauge!(PRISMA_CLIENT_QUERIES_ACTIVE).set(0.0); + counter!(MOBC_POOL_CONNECTIONS_OPENED_TOTAL).absolute(0); + counter!(MOBC_POOL_CONNECTIONS_CLOSED_TOTAL).absolute(0); + gauge!(MOBC_POOL_CONNECTIONS_OPEN).set(0.0); + gauge!(MOBC_POOL_CONNECTIONS_BUSY).set(0.0); + gauge!(MOBC_POOL_CONNECTIONS_IDLE).set(0.0); + gauge!(MOBC_POOL_WAIT_COUNT).set(0.0); } // At the moment the histogram is only used for timings. So the bounds are hard coded here @@ -171,10 +166,7 @@ pub enum MetricFormat { #[cfg(test)] mod tests { use super::*; - use metrics::{ - absolute_counter, decrement_gauge, describe_counter, describe_gauge, describe_histogram, gauge, histogram, - increment_counter, increment_gauge, register_counter, register_gauge, register_histogram, - }; + use metrics::{describe_counter, describe_gauge, describe_histogram, gauge, histogram}; use serde_json::json; use std::collections::HashMap; use std::time::Duration; @@ -211,12 +203,12 @@ mod tests { let metrics = MetricRegistry::new_with_accept_list(TESTING_ACCEPT_LIST.to_vec()); let dispatch = Dispatch::new(tracing_subscriber::Registry::default().with(metrics.clone())); async { - let counter1 = register_counter!("test_counter"); + let counter1 = counter!("test_counter"); counter1.increment(1); - increment_counter!("test_counter"); - increment_counter!("test_counter"); + counter!("test_counter").increment(1); + counter!("test_counter").increment(1); - increment_counter!("another_counter"); + counter!("another_counter").increment(1); let val = metrics.counter_value("test_counter").unwrap(); assert_eq!(val, 3); @@ -224,7 +216,7 @@ mod tests { let val2 = metrics.counter_value("another_counter").unwrap(); assert_eq!(val2, 1); - absolute_counter!("test_counter", 5); + counter!("test_counter").absolute(5); let val3 = metrics.counter_value("test_counter").unwrap(); assert_eq!(val3, 5); } @@ -239,11 +231,11 @@ mod tests { let metrics = MetricRegistry::new_with_accept_list(TESTING_ACCEPT_LIST.to_vec()); let dispatch = Dispatch::new(tracing_subscriber::Registry::default().with(metrics.clone())); async { - let gauge1 = register_gauge!("test_gauge"); + let gauge1 = gauge!("test_gauge"); gauge1.increment(1.0); - increment_gauge!("test_gauge", 1.0); - increment_gauge!("test_gauge", 1.0); - increment_gauge!("another_gauge", 1.0); + gauge!("test_gauge").increment(1.0); + gauge!("test_gauge").increment(1.0); + gauge!("another_gauge").increment(1.0); let val = metrics.gauge_value("test_gauge").unwrap(); assert_eq!(val, 3.0); @@ -253,11 +245,11 @@ mod tests { assert_eq!(None, metrics.counter_value("test_gauge")); - gauge!("test_gauge", 5.0); + gauge!("test_gauge").set(5.0); let val3 = metrics.gauge_value("test_gauge").unwrap(); assert_eq!(val3, 5.0); - decrement_gauge!("test_gauge", 2.0); + gauge!("test_gauge").decrement(2.0); let val4 = metrics.gauge_value("test_gauge").unwrap(); assert_eq!(val4, 3.0); } @@ -274,8 +266,8 @@ mod tests { async { trace!("a fake trace"); - increment_gauge!("test_gauge", 1.0); - increment_counter!("test_counter"); + gauge!("test_gauge").set(1.0); + counter!("test_counter").increment(1); trace!("another fake trace"); @@ -293,8 +285,8 @@ mod tests { let metrics = MetricRegistry::new_with_accept_list(TESTING_ACCEPT_LIST.to_vec()); let dispatch = Dispatch::new(tracing_subscriber::Registry::default().with(metrics.clone())); async { - increment_gauge!("not_accepted", 1.0); - increment_gauge!("test_gauge", 1.0); + gauge!("not_accepted").set(1.0); + gauge!("test_gauge").set(1.0); assert_eq!(1.0, metrics.gauge_value("test_gauge").unwrap()); assert_eq!(None, metrics.gauge_value("not_accepted")); @@ -310,15 +302,15 @@ mod tests { let metrics = MetricRegistry::new_with_accept_list(TESTING_ACCEPT_LIST.to_vec()); let dispatch = Dispatch::new(tracing_subscriber::Registry::default().with(metrics.clone())); async { - let hist = register_histogram!("test_histogram"); + let hist = histogram!("test_histogram"); hist.record(Duration::from_millis(9)); - histogram!("test_histogram", Duration::from_millis(100)); - histogram!("test_histogram", Duration::from_millis(1)); + histogram!("test_histogram").record(Duration::from_millis(100)); + histogram!("test_histogram").record(Duration::from_millis(1)); - histogram!("test_histogram", Duration::from_millis(1999)); - histogram!("test_histogram", Duration::from_millis(3999)); - histogram!("test_histogram", Duration::from_millis(610)); + histogram!("test_histogram").record(Duration::from_millis(1999)); + histogram!("test_histogram").record(Duration::from_millis(3999)); + histogram!("test_histogram").record(Duration::from_millis(610)); let hist = metrics.histogram_values("test_histogram").unwrap(); let expected: Vec<(f64, u64)> = Vec::from([ @@ -386,21 +378,21 @@ mod tests { assert_eq!(metrics.to_json(Default::default()), empty); - absolute_counter!("counter_1", 4, "label" => "one"); + counter!("counter_1", "label" => "one").absolute(4); describe_counter!("counter_2", "this is a description for counter 2"); - absolute_counter!("counter_2", 2, "label" => "one", "another_label" => "two"); + counter!("counter_2", "label" => "one", "another_label" => "two").absolute(2); describe_gauge!("gauge_1", "a description for gauge 1"); - gauge!("gauge_1", 7.0); - gauge!("gauge_2", 3.0, "label" => "three"); + gauge!("gauge_1").set(7.0); + gauge!("gauge_2", "label" => "three").set(3.0); describe_histogram!("histogram_1", "a description for histogram"); - let hist = register_histogram!("histogram_1", "label" => "one", "hist_two" => "two"); + let hist = histogram!("histogram_1", "label" => "one", "hist_two" => "two"); hist.record(Duration::from_millis(9)); - histogram!("histogram_2", Duration::from_millis(9)); - histogram!("histogram_2", Duration::from_millis(1000)); - histogram!("histogram_2", Duration::from_millis(40)); + histogram!("histogram_2").record(Duration::from_millis(9)); + histogram!("histogram_2").record(Duration::from_millis(1000)); + histogram!("histogram_2").record(Duration::from_millis(40)); let json = metrics.to_json(Default::default()); let expected = json!({ @@ -459,10 +451,10 @@ mod tests { let metrics = MetricRegistry::new_with_accept_list(TESTING_ACCEPT_LIST.to_vec()); let dispatch = Dispatch::new(tracing_subscriber::Registry::default().with(metrics.clone())); async { - let hist = register_histogram!("test_histogram", "label" => "one", "two" => "another"); + let hist = histogram!("test_histogram", "label" => "one", "two" => "another"); hist.record(Duration::from_millis(9)); - absolute_counter!("counter_1", 1); + counter!("counter_1").absolute(1); let mut global_labels: HashMap = HashMap::new(); global_labels.insert("global_one".to_string(), "one".to_string()); @@ -502,19 +494,19 @@ mod tests { let metrics = MetricRegistry::new_with_accept_list(TESTING_ACCEPT_LIST.to_vec()); let dispatch = Dispatch::new(tracing_subscriber::Registry::default().with(metrics.clone())); async { - absolute_counter!("counter_1", 4, "label" => "one"); + counter!("counter_1", "label" => "one").absolute(4); describe_counter!("counter_2", "this is a description for counter 2"); - absolute_counter!("counter_2", 2, "label" => "one", "another_label" => "two"); + counter!("counter_2", "label" => "one", "another_label" => "two").absolute(2); describe_gauge!("gauge_1", "a description for gauge 1"); - gauge!("gauge_1", 7.0); - gauge!("gauge_2", 3.0, "label" => "three"); + gauge!("gauge_1").set(7.0); + gauge!("gauge_2", "label" => "three").set(3.0); describe_histogram!("histogram_1", "a description for histogram"); - let hist = register_histogram!("histogram_1", "label" => "one", "hist_two" => "two"); + let hist = histogram!("histogram_1", "label" => "one", "hist_two" => "two"); hist.record(Duration::from_millis(9)); - histogram!("histogram_2", Duration::from_millis(1000)); + histogram!("histogram_2").record(Duration::from_millis(1000)); let mut global_labels: HashMap = HashMap::new(); global_labels.insert("global_two".to_string(), "two".to_string()); diff --git a/query-engine/metrics/src/recorder.rs b/query-engine/metrics/src/recorder.rs index 94d2c050f60..25a71967f6a 100644 --- a/query-engine/metrics/src/recorder.rs +++ b/query-engine/metrics/src/recorder.rs @@ -1,7 +1,7 @@ use std::sync::Arc; -use metrics::KeyName; use metrics::{Counter, CounterFn, Gauge, GaugeFn, Histogram, HistogramFn, Key, Recorder, Unit}; +use metrics::{KeyName, Metadata, SharedString}; use tracing::trace; use super::common::KeyLabels; @@ -22,27 +22,27 @@ impl MetricRecorder { } impl Recorder for MetricRecorder { - fn describe_counter(&self, key_name: KeyName, _unit: Option, description: &'static str) { - self.register_description(key_name.as_str(), description); + fn describe_counter(&self, key_name: KeyName, _unit: Option, description: SharedString) { + self.register_description(key_name.as_str(), &description); } - fn describe_gauge(&self, key_name: KeyName, _unit: Option, description: &'static str) { - self.register_description(key_name.as_str(), description); + fn describe_gauge(&self, key_name: KeyName, _unit: Option, description: SharedString) { + self.register_description(key_name.as_str(), &description); } - fn describe_histogram(&self, key_name: KeyName, _unit: Option, description: &'static str) { - self.register_description(key_name.as_str(), description); + fn describe_histogram(&self, key_name: KeyName, _unit: Option, description: SharedString) { + self.register_description(key_name.as_str(), &description); } - fn register_counter(&self, key: &Key) -> Counter { + fn register_counter(&self, key: &Key, _metadata: &Metadata<'_>) -> Counter { Counter::from_arc(Arc::new(MetricHandle(key.clone()))) } - fn register_gauge(&self, key: &Key) -> Gauge { + fn register_gauge(&self, key: &Key, _metadata: &Metadata<'_>) -> Gauge { Gauge::from_arc(Arc::new(MetricHandle(key.clone()))) } - fn register_histogram(&self, key: &Key) -> Histogram { + fn register_histogram(&self, key: &Key, _metadata: &Metadata<'_>) -> Histogram { Histogram::from_arc(Arc::new(MetricHandle(key.clone()))) } }