You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> The project is currently under development. Keep an eye out for its release!
1
+
# QueryWatch
2
2
3
-
# KeelMatrix.QueryWatch
3
+
Guardrail your **database queries** in tests & CI. Capture executed SQL, enforce **budgets** (counts & timings), and fail builds on regressions. Works with **ADO.NET**, **Dapper**, and **EF Core**.
4
4
5
-
> Catch N+1 queries and slow SQL in tests. Fail builds when query budgets are exceeded.
At **test time** (scope) you can enforce `maxQueries`, `maxAverage`, `maxTotal`. At **CI time** use the CLI for stronger rules including **per‑pattern budgets**. Patterns support wildcards (`*`, `?`) or `regex:` prefix.
120
+
121
+
Example per‑pattern budgets:
122
+
123
+
```bash
124
+
--budget "SELECT * FROM Users*=1"
125
+
--budget "regex:^UPDATE Orders SET=3"
126
+
```
127
+
128
+
> If your JSON is **top‑N sampled**, budgets evaluate only over those events. Increase `sampleTop` in your export to tighten guarantees.
129
+
130
+
---
49
131
50
132
## CLI
51
133
@@ -67,40 +149,22 @@ var options = new DbContextOptionsBuilder<MyDbContext>()
67
149
<!-- END:CLI_FLAGS -->
68
150
69
151
### Multi‑file support
70
-
71
152
Repeat `--input` to aggregate multiple JSONs (e.g., per‑project reports in a mono‑repo). Budgets evaluate on the aggregate.
72
153
73
154
### GitHub PR summary
155
+
When run inside GitHub Actions, the CLI writes a Markdown table to the **Step Summary** automatically.
74
156
75
-
When run inside GitHub Actions, the CLI writes a Markdown table to the **Step Summary** automatically, so reviewers see metrics and any violations at a glance.
76
-
77
-
### Note on per‑pattern budgets
78
-
79
-
Budgets match against the `events` captured in the JSON file(s). These are the top‑N slowest events by duration to keep files small. If you want strict coverage, export with a higher `sampleTop` in `QueryWatchJson.ExportToFile`, or pass a larger `sampleTop` to `QueryWatchScope.Start(...)`.
80
-
81
-
## Redactor ordering tips
82
-
83
-
If you use multiple redactors, **order matters**. A safe, effective default is:
84
-
85
-
1.**Whitespace normalizer** – make SQL text stable across environments/providers.
86
-
2.**High‑entropy token masks** – long hex tokens, JWTs, API keys.
87
-
3.**PII masks** – emails, phone numbers, IPs.
88
-
4.**Custom rules** – your app–specific patterns (use `AddRegexRedactor(...)`).
89
-
90
-
> Put *broad* rules (like whitespace) first, and *specific* rules (like PII) after. This lowers the chance one rule prevents another from matching.
91
-
92
-
## Typical budgets for Dapper‑heavy solutions
93
-
94
-
Dapper often issues *fewer, more targeted* commands than ORMs. Reasonable starting points (tune per project):
157
+
---
95
158
96
-
-**End‑to‑end web test:**`--max-queries 40`, `--max-average-ms 50`, `--max-total-ms 1500`.
-**Per‑pattern budgets:** cap hot spots explicitly, e.g.:
159
+
## Troubleshooting
99
160
100
-
```
101
-
--budget "SELECT * FROM Users*=5" --budget "regex:^UPDATE Orders SET=3"
102
-
```
161
+
-**“Budget violations:” but no pattern table** → you didn’t pass any `--budget`, or your JSON was **heavily sampled**. Re‑export with higher `sampleTop` (e.g., 200–500).
162
+
-**Baselines seem too strict** → tolerances are **percent of baseline**. Ensure your baseline is representative; use `--baseline-allow-percent` to allow small drift.
163
+
-**CLI help in README looks stale** → run `./build/Update-ReadmeFlags.ps1` (or `--print-flags-md`) to refresh the block between markers.
164
+
-**Hot path text capture** → disable per‑adapter: `QueryWatchOptions.Disable{Ado|Dapper|EfCore}TextCapture=true`.
165
+
-**Parameter metadata** → set `QueryWatchOptions.CaptureParameterShape=true` (emits `event.meta.parameters`), never values.
103
166
104
-
- Increase `sampleTop` in code (`QueryWatchScope.Start(..., sampleTop: 200)`) if you rely on many per‑pattern budgets.
167
+
---
105
168
106
-
Treat these as **guardrails**: keep design flexible but catch accidental N+1s or slow queries early.
0 commit comments