Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4bf781c
feat(context): add PhaseTiming struct for performance breakdown
tobyhede Jan 22, 2026
309528c
feat(context): add StatementMetadata for diagnostic tracking
tobyhede Jan 22, 2026
91f386c
feat(log): add SLOW_STATEMENTS log target
tobyhede Jan 22, 2026
64ac236
feat(config): add slow statement logging configuration
tobyhede Jan 22, 2026
e4fd48f
fix(log): export SLOW_STATEMENTS from log module
tobyhede Jan 22, 2026
f9bca38
feat(context): integrate PhaseTiming and StatementMetadata into session
tobyhede Jan 22, 2026
ed54387
feat(metrics): add keyset_cipher_init_duration_seconds histogram
tobyhede Jan 22, 2026
2bb7346
feat(config): add slow_statements_enabled() and slow_statement_min_du…
tobyhede Jan 22, 2026
31dcccf
fix(tests): fix duplicate #[test] attribute in tandem tests
tobyhede Jan 22, 2026
07e7685
feat(context): add phase timing and metadata helper methods
tobyhede Jan 22, 2026
ca0824a
feat(io): record server/client IO durations for diagnostics
tobyhede Jan 22, 2026
fc3f653
feat(io): record server write duration in frontend
tobyhede Jan 22, 2026
e5dbc0b
feat(frontend): instrument extended protocol with timing and metadata
tobyhede Jan 22, 2026
d054c79
feat(frontend): record encrypt phase timing for diagnostics
tobyhede Jan 22, 2026
d8695a4
feat(frontend): instrument query_handler with parse timing and metadata
tobyhede Jan 22, 2026
9f497e1
feat(frontend): complete instrumentation for diagnostics
tobyhede Jan 22, 2026
6683afa
docs: add SLOW_STATEMENTS.md for performance troubleshooting
tobyhede Jan 22, 2026
b356dec
feat(metrics): add statement_type, protocol, mapped labels and slow s…
tobyhede Jan 22, 2026
e98eac5
test: add automated diagnostics log and metrics label checks
tobyhede Jan 22, 2026
da5c193
chore: update Cargo.lock with reqwest dependency
tobyhede Jan 22, 2026
41e1349
fix(metrics): correct diagnostics timing and metadata recording
tobyhede Jan 22, 2026
47af9db
style: apply cargo fmt formatting
tobyhede Jan 22, 2026
45193f1
test(metrics): update prometheus assertions to be label-aware
tobyhede Jan 22, 2026
13c49c4
Fix diagnostics attribution for pipelined sessions
tobyhede Jan 22, 2026
7e5007a
Improve diagnostics metadata and integration metrics fetch
tobyhede Jan 22, 2026
6959c1f
Format diagnostics frontend changes
tobyhede Jan 22, 2026
321701f
test(integration): expose prometheus port for proxy-tls
tobyhede Jan 22, 2026
9f07ad1
docs(context): document two-phase timing pattern in ExecuteContext
tobyhede Jan 22, 2026
7808462
refactor(diagnostics): extract retry configuration to named constants
tobyhede Jan 22, 2026
061bd29
refactor(frontend): improve session ID handling and reduce duplication
tobyhede Jan 22, 2026
e6bf1de
refactor(frontend): remove unused session_id parameter from write_to_…
tobyhede Jan 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 167 additions & 4 deletions Cargo.lock

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

84 changes: 84 additions & 0 deletions docs/SLOW_STATEMENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Slow Statement Logging

CipherStash Proxy includes built-in slow statement logging for troubleshooting performance issues.

## Configuration

Enable slow statement logging via environment variables:

```bash
# Enable slow statement logging (required)
CS_LOG__SLOW_STATEMENTS=true

# Optional: Set minimum duration threshold (default: 2000ms)
CS_LOG__SLOW_STATEMENT_MIN_DURATION_MS=500

# Optional: Set log level (default: warn when enabled)
CS_LOG__SLOW_STATEMENTS_LEVEL=warn

# Recommended: Use structured logging for parsing
CS_LOG__FORMAT=structured
```

## Slow Statement Logs

When a statement exceeds the threshold, the proxy logs a detailed breakdown:

```json
{
"client_id": 1,
"duration_ms": 10500,
"statement_type": "INSERT",
"protocol": "extended",
"encrypted": true,
"encrypted_values_count": 3,
"param_bytes": 1024,
"query_fingerprint": "a1b2c3d4",
"keyset_id": "uuid",
"mapping_disabled": false,
"breakdown": {
"parse_ms": 5,
"encrypt_ms": 450,
"server_write_ms": 12,
"server_wait_ms": 9800,
"server_response_ms": 233
}
}
```

## Prometheus Metrics

### Labeled Histograms

Duration histograms now include labels for filtering:

- `statement_type`: insert, update, delete, select, other
- `protocol`: simple, extended
- `mapped`: true, false
- `multi_statement`: true, false

Example queries:
```promql
# Average INSERT duration
histogram_quantile(0.5, rate(cipherstash_proxy_statements_session_duration_seconds_bucket{statement_type="insert"}[5m]))

# Compare encrypted vs passthrough
histogram_quantile(0.99, rate(cipherstash_proxy_statements_session_duration_seconds_bucket{mapped="true"}[5m]))
```

### ZeroKMS Cipher Init

```
cipherstash_proxy_keyset_cipher_init_duration_seconds
```

Measures time for cipher initialization including ZeroKMS network call. High values indicate ZeroKMS connectivity issues.

## Interpreting Results

| Symptom | Likely Cause |
|---------|--------------|
| High `encrypt_ms` | ZeroKMS latency or large payload |
| High `server_wait_ms` | Database latency |
| High `cipher_init_duration` | ZeroKMS cold start or network |
| High `parse_ms` | Complex SQL or schema lookup |
1 change: 1 addition & 0 deletions packages/cipherstash-proxy-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ tokio-postgres-rustls = "0.13.0"
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
uuid = { version = "1.11.0", features = ["serde", "v4"] }
reqwest = { version = "0.12", features = ["rustls-tls"] }
Loading