Skip to content

Commit

Permalink
Update mobc and metrics crates
Browse files Browse the repository at this point in the history
mobc update includes fixes from importcjj/mobc#99
Rest of the PR is update to new api of the `metrics` crate.

Close prisma/team-orm#1317
  • Loading branch information
SevInf authored and aqrln committed Oct 21, 2024
1 parent 4fe298b commit 3373e87
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 158 deletions.
124 changes: 74 additions & 50 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 2 additions & 2 deletions quaint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = { git="https://github.com/SevInf/mobc.git", branch = "metrics-guards", optional = true }
serde = { version = "1.0" }
sqlformat = { version = "0.2.3", optional = true }
uuid.workspace = true
Expand Down
8 changes: 4 additions & 4 deletions quaint/src/connector/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -74,7 +74,7 @@ where
result,
);

histogram!("pool.check_out", start.elapsed_time());
histogram!("pool.check_out").record(start.elapsed_time());

res
}
Expand Down
8 changes: 4 additions & 4 deletions quaint/src/connector/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -71,15 +71,15 @@ 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(())
}

/// 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(())
Expand Down
Loading

0 comments on commit 3373e87

Please sign in to comment.