Skip to content

Commit

Permalink
fix(qe). Metrics: fix metrics duplicates (#4234)
Browse files Browse the repository at this point in the history
* Remove duplicates from metrics listing

* Instead of whitelisting prisma metrics to have an initial value, we are
only whitelisting mobc metrics, and assigning an initial value to them.

Then on the renaming phase (see `METRIC_RENAMES`) these metrics will be
renamed from the mobc name to the internal prisma name, and no duplicates will
appear.

Fixes prisma/prisma#21069
  • Loading branch information
Miguel Fernández committed Sep 14, 2023
1 parent b90a820 commit d4650df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
28 changes: 14 additions & 14 deletions query-engine/black-box-tests/tests/metrics/smoke_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod smoke_tests {
}

#[connector_test]
#[rustfmt::skip]
async fn expected_metrics_rendered(r: Runner) -> TestResult<()> {
let mut qe_cmd = query_engine_cmd(r.prisma_dml(), "57582");
qe_cmd.arg("--enable-metrics");
Expand Down Expand Up @@ -56,21 +57,20 @@ mod smoke_tests {
.unwrap();

// counters
assert!(metrics.contains("prisma_client_queries_total counter"));
assert!(metrics.contains("prisma_datasource_queries_total counter"));
assert!(metrics.contains("prisma_pool_connections_opened_total counter"));
assert!(metrics.contains("prisma_pool_connections_closed_total counter"));
assert_eq!(metrics.matches("prisma_client_queries_total counter").count(), 1);
assert_eq!(metrics.matches("prisma_datasource_queries_total counter").count(), 1);
assert_eq!(metrics.matches("prisma_pool_connections_opened_total counter").count(), 1);
assert_eq!(metrics.matches("prisma_pool_connections_closed_total counter").count(), 1);
// gauges
assert!(metrics.contains("prisma_pool_connections_open gauge"));
assert!(metrics.contains("prisma_pool_connections_busy gauge"));
assert!(metrics.contains("prisma_pool_connections_idle gauge"));
assert!(metrics.contains("prisma_client_queries_active gauge"));
assert!(metrics.contains("prisma_client_queries_wait gauge"));
assert_eq!(metrics.matches("prisma_pool_connections_open gauge").count(), 1);
assert_eq!(metrics.matches("prisma_pool_connections_busy gauge").count(), 1);
assert_eq!(metrics.matches("prisma_pool_connections_idle gauge").count(), 1);
assert_eq!(metrics.matches("prisma_client_queries_active gauge").count(), 1);
assert_eq!(metrics.matches("prisma_client_queries_wait gauge").count(), 1);
// histograms
assert!(metrics.contains("prisma_client_queries_duration_histogram_ms histogram"));
assert!(metrics.contains("prisma_client_queries_wait_histogram_ms histogram"));
assert!(metrics.contains("prisma_datasource_queries_duration_histogram_ms histogram"));
})
.await
assert_eq!(metrics.matches("prisma_client_queries_duration_histogram_ms histogram").count(), 1);
assert_eq!(metrics.matches("prisma_client_queries_wait_histogram_ms histogram").count(), 1);
assert_eq!(metrics.matches("prisma_datasource_queries_duration_histogram_ms histogram").count(), 1)
}).await
}
}
17 changes: 5 additions & 12 deletions query-engine/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,8 @@ const ACCEPT_LIST: &[&str] = &[
MOBC_POOL_WAIT_DURATION,
PRISMA_CLIENT_QUERIES_TOTAL,
PRISMA_DATASOURCE_QUERIES_TOTAL,
PRISMA_POOL_CONNECTIONS_OPENED_TOTAL,
PRISMA_POOL_CONNECTIONS_CLOSED_TOTAL,
PRISMA_POOL_CONNECTIONS_OPEN,
PRISMA_POOL_CONNECTIONS_BUSY,
PRISMA_POOL_CONNECTIONS_IDLE,
PRISMA_CLIENT_QUERIES_WAIT,
PRISMA_CLIENT_QUERIES_ACTIVE,
PRISMA_CLIENT_QUERIES_DURATION_HISTOGRAM_MS,
PRISMA_CLIENT_QUERIES_WAIT_HISTOGRAM_MS,
PRISMA_DATASOURCE_QUERIES_DURATION_HISTOGRAM_MS,
];

Expand Down Expand Up @@ -148,8 +141,8 @@ pub fn describe_metrics() {

absolute_counter!(PRISMA_CLIENT_QUERIES_TOTAL, 0);
absolute_counter!(PRISMA_DATASOURCE_QUERIES_TOTAL, 0);
absolute_counter!(PRISMA_POOL_CONNECTIONS_OPENED_TOTAL, 0);
absolute_counter!(PRISMA_POOL_CONNECTIONS_CLOSED_TOTAL, 0);
absolute_counter!(MOBC_POOL_CONNECTIONS_OPENED_TOTAL, 0);
absolute_counter!(MOBC_POOL_CONNECTIONS_CLOSED_TOTAL, 0);

// gauges
describe_gauge!(
Expand All @@ -173,9 +166,9 @@ pub fn describe_metrics() {
"Number of currently active Prisma Client queries"
);

gauge!(PRISMA_POOL_CONNECTIONS_OPEN, 0.0);
gauge!(PRISMA_POOL_CONNECTIONS_BUSY, 0.0);
gauge!(PRISMA_POOL_CONNECTIONS_IDLE, 0.0);
gauge!(MOBC_POOL_CONNECTIONS_OPEN, 0.0);
gauge!(MOBC_POOL_CONNECTIONS_BUSY, 0.0);
gauge!(MOBC_POOL_CONNECTIONS_IDLE, 0.0);
gauge!(PRISMA_CLIENT_QUERIES_WAIT, 0.0);
gauge!(PRISMA_CLIENT_QUERIES_ACTIVE, 0.0);

Expand Down

0 comments on commit d4650df

Please sign in to comment.