Skip to content

Commit

Permalink
chore(qe): update mobc to include importcjj/mobc#86 (#4379)
Browse files Browse the repository at this point in the history
* chore(qe) update mobc after to include importcjj/mobc#86

Fixes prisma/prisma#21221

* Add unit test

---------

Co-authored-by: Jan Piotrowski <[email protected]>
  • Loading branch information
Miguel Fernández and janpio authored Nov 13, 2023
1 parent e0f0b06 commit e95e739
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
5 changes: 3 additions & 2 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 query-engine/black-box-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ user-facing-errors.workspace = true
insta = "1.7.1"
enumflags2 = "0.7"
query-engine-metrics = {path = "../metrics"}
regex = "1.9.3"
25 changes: 24 additions & 1 deletion query-engine/black-box-tests/tests/metrics/smoke_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use query_engine_tests::*;
/// Asserts common basics for composite type writes.
#[test_suite(schema(schema))]
mod smoke_tests {
use regex::Regex;
fn schema() -> String {
let schema = indoc! {
r#"model Person {
Expand All @@ -14,6 +15,24 @@ mod smoke_tests {
schema.to_owned()
}

fn assert_value_in_range(metrics: &str, metric: &str, low: f64, high: f64) {
let regex = Regex::new(format!(r"{metric}\s+([+-]?\d+(\.\d+)?)").as_str()).unwrap();
match regex.captures(&metrics) {
Some(capture) => {
let value = capture.get(1).unwrap().as_str().parse::<f64>().unwrap();
assert!(
value >= low && value <= high,
"expected {} value of {} to be between {} and {}",
metric,
value,
low,
high
);
}
None => panic!("Metric {} not found in metrics text", metric),
}
}

#[connector_test]
#[rustfmt::skip]
async fn expected_metrics_rendered(r: Runner) -> TestResult<()> {
Expand Down Expand Up @@ -62,6 +81,8 @@ mod smoke_tests {
// counters
assert_eq!(metrics.matches("# HELP prisma_client_queries_total The total number of Prisma Client queries executed").count(), 1);
assert_eq!(metrics.matches("# TYPE prisma_client_queries_total counter").count(), 1);
assert_eq!(metrics.matches("prisma_client_queries_total 1").count(), 1);


assert_eq!(metrics.matches("# HELP prisma_datasource_queries_total The total number of datasource queries executed").count(), 1);
assert_eq!(metrics.matches("# TYPE prisma_datasource_queries_total counter").count(), 1);
Expand All @@ -81,13 +102,15 @@ mod smoke_tests {

assert_eq!(metrics.matches("# HELP prisma_pool_connections_busy The number of pool connections currently executing datasource queries").count(), 1);
assert_eq!(metrics.matches("# TYPE prisma_pool_connections_busy gauge").count(), 1);
assert_value_in_range(&metrics, "prisma_pool_connections_busy", 0f64, 1f64);

assert_eq!(metrics.matches("# HELP prisma_pool_connections_idle The number of pool connections that are not busy running a query").count(), 1);
assert_eq!(metrics.matches("# TYPE prisma_pool_connections_idle gauge").count(), 1);

assert_eq!(metrics.matches("# HELP prisma_pool_connections_open The number of pool connections currently open").count(), 1);
assert_eq!(metrics.matches("# TYPE prisma_pool_connections_open gauge").count(), 1);

assert_value_in_range(&metrics, "prisma_pool_connections_open", 0f64, 1f64);

// histograms
assert_eq!(metrics.matches("# HELP prisma_client_queries_duration_histogram_ms The distribution of the time Prisma Client queries took to run end to end").count(), 1);
assert_eq!(metrics.matches("# TYPE prisma_client_queries_duration_histogram_ms histogram").count(), 1);
Expand Down

0 comments on commit e95e739

Please sign in to comment.