Skip to content

Commit e0ad3b3

Browse files
committed
docs(diagnostics): address code review suggestions
- Add note about ephemeral query fingerprints (change on restart) - Make default 2000ms threshold more prominent in docs - Use display formatting for cleaner warning logs in production
1 parent c18806e commit e0ad3b3

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

docs/SLOW_STATEMENTS.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Enable slow statement logging via environment variables:
1010
# Enable slow statement logging (required)
1111
CS_LOG__SLOW_STATEMENTS=true
1212

13-
# Optional: Set minimum duration threshold (default: 2000ms)
13+
# Optional: Set minimum duration threshold
14+
# Default is 2000ms (2 seconds) - only set this if you want a different threshold
1415
CS_LOG__SLOW_STATEMENT_MIN_DURATION_MS=500
1516

1617
# Optional: Set log level (default: warn when enabled)
@@ -46,6 +47,10 @@ When a statement exceeds the threshold, the proxy logs a detailed breakdown:
4647
}
4748
```
4849

50+
### Query Fingerprints
51+
52+
**Note:** Query fingerprints are ephemeral and instance-local. Each proxy instance generates a unique random key at startup used to compute `query_fingerprint` values. This means fingerprints will change when the proxy restarts and cannot be correlated across different proxy instances. This is intentional for security (prevents dictionary attacks on query patterns). Use fingerprints for correlation within a single proxy instance's runtime only.
53+
4954
## Prometheus Metrics
5055

5156
### Labeled Histograms

packages/cipherstash-proxy-integration/src/diagnostics.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,32 @@ mod tests {
7777
"Metrics should include multi_statement=false label"
7878
);
7979
}
80+
81+
#[tokio::test]
82+
async fn slow_statement_metrics_and_logs() {
83+
let client = connect_with_tls(PROXY).await;
84+
85+
clear().await;
86+
87+
// Execute a query that takes longer than the default 2s threshold
88+
// We use pg_sleep(2.1) to ensure it's considered slow
89+
client.query("SELECT pg_sleep(2.1)", &[]).await.unwrap();
90+
91+
// Fetch metrics with retry logic
92+
let body =
93+
fetch_metrics_with_retry(METRICS_FETCH_MAX_RETRIES, METRICS_FETCH_RETRY_DELAY_MS).await;
94+
95+
// Assert that the slow statements counter incremented
96+
assert!(
97+
body.contains("cipherstash_proxy_slow_statements_total 1"),
98+
"Metrics should include slow statement counter incremented to 1. Found: {}",
99+
body
100+
);
101+
102+
// Verify that duration histograms also reflect the slow query
103+
assert!(
104+
body.contains("cipherstash_proxy_statements_session_duration_seconds_bucket"),
105+
"Metrics should include session duration histogram"
106+
);
107+
}
80108
}

packages/cipherstash-proxy/src/postgresql/context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ where
444444
warn!(
445445
target: CONTEXT,
446446
client_id = self.client_id,
447-
prepared_statement = ?name,
447+
prepared_statement = %name.as_str(),
448448
msg = "Session lookup failed for prepared statement, using latest session"
449449
);
450450
}

0 commit comments

Comments
 (0)