Skip to content

Commit b293cf8

Browse files
authored
Merge pull request #367 from cipherstash/slow-db-config
feat: add configurable logging thresholds for slow db response logging
2 parents 92623ce + 061146a commit b293cf8

9 files changed

Lines changed: 39 additions & 6 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ tests/benchmark/results/*.csv
2626
tests/benchmark/benchmark-*.png
2727

2828
## Local helm chart testing
29-
testing-chart.yaml
29+
testing-chart.yaml
30+
31+
.env.proxy.dev

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to CipherStash Proxy will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [2.1.22] - 2026-02-05
8+
9+
### Added
10+
11+
- **Configurable slow database response threshold**: The "Slow database response" log threshold is now configurable via `CS_LOG__SLOW_DB_RESPONSE_MIN_DURATION_MS` (default: 100ms). This controls per-message logging for individual slow reads from the PostgreSQL server.
12+
713
## [2.1.21] - 2026-02-04
814

915
### Changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolver = "2"
33
members = ["packages/*"]
44

55
[workspace.package]
6-
version = "2.1.21"
6+
version = "2.1.22"
77
edition = "2021"
88

99
[profile.dev]

packages/cipherstash-proxy/src/config/log.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ pub struct LogConfig {
2828
#[serde(default = "LogConfig::default_slow_statement_min_duration_ms")]
2929
pub slow_statement_min_duration_ms: u64,
3030

31+
/// Threshold in milliseconds for slow database response logging (default: 100ms)
32+
#[serde(default = "LogConfig::default_slow_db_response_min_duration_ms")]
33+
pub slow_db_response_min_duration_ms: u64,
34+
3135
// All log target levels - automatically generated and flattened from LogTargetLevels
3236
// To add a new target: just add it to the define_log_targets! macro in log/targets.rs
3337
#[serde(flatten)]
@@ -100,6 +104,7 @@ impl LogConfig {
100104
level,
101105
slow_statements: false,
102106
slow_statement_min_duration_ms: Self::default_slow_statement_min_duration_ms(),
107+
slow_db_response_min_duration_ms: Self::default_slow_db_response_min_duration_ms(),
103108
// All target levels automatically set using generated LogTargetLevels
104109
targets: LogTargetLevels::with_level(level),
105110
}
@@ -133,6 +138,16 @@ impl LogConfig {
133138
pub const fn default_slow_statement_min_duration_ms() -> u64 {
134139
2000
135140
}
141+
142+
/// Default threshold for slow database response logging (100 milliseconds).
143+
///
144+
/// This value represents the threshold for logging individual slow messages from
145+
/// the PostgreSQL server. Unlike slow statement logging which tracks total query
146+
/// time, this tracks per-message read latency from the server connection.
147+
/// Operators can adjust via CS_LOG__SLOW_DB_RESPONSE_MIN_DURATION_MS.
148+
pub const fn default_slow_db_response_min_duration_ms() -> u64 {
149+
100
150+
}
136151
}
137152

138153
#[cfg(test)]

packages/cipherstash-proxy/src/config/tandem.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ impl TandemConfig {
311311
pub fn slow_statement_min_duration(&self) -> std::time::Duration {
312312
std::time::Duration::from_millis(self.log.slow_statement_min_duration_ms)
313313
}
314+
315+
/// Returns the slow database response minimum duration as a Duration
316+
pub fn slow_db_response_min_duration(&self) -> std::time::Duration {
317+
std::time::Duration::from_millis(self.log.slow_db_response_min_duration_ms)
318+
}
314319
#[cfg(test)]
315320
pub fn for_testing() -> Self {
316321
Self {

packages/cipherstash-proxy/src/log/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ mod tests {
114114
level: LogLevel::Info,
115115
slow_statements: false,
116116
slow_statement_min_duration_ms: LogConfig::default_slow_statement_min_duration_ms(),
117+
slow_db_response_min_duration_ms: LogConfig::default_slow_db_response_min_duration_ms(),
117118
targets: LogTargetLevels {
118119
development_level: LogLevel::Info,
119120
authentication_level: LogLevel::Debug,

packages/cipherstash-proxy/src/postgresql/backend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ where
162162
let sent: u64 = bytes.len() as u64;
163163
counter!(SERVER_BYTES_RECEIVED_TOTAL).increment(sent);
164164

165-
// Log slow database responses (>100ms is concerning)
166-
if read_duration.as_millis() > 100 {
165+
// Log slow database responses (configurable threshold, default 100ms)
166+
if read_duration > self.context.slow_db_response_min_duration() {
167167
warn!(
168168
client_id = self.context.client_id,
169169
msg = "Slow database response",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,10 @@ where
816816
self.config.mapping_errors_enabled()
817817
}
818818

819+
pub fn slow_db_response_min_duration(&self) -> std::time::Duration {
820+
self.config.slow_db_response_min_duration()
821+
}
822+
819823
pub fn prometheus_enabled(&self) -> bool {
820824
self.config.prometheus_enabled()
821825
}

0 commit comments

Comments
 (0)