Repository navigation
Add per-tenant SQL query budget with slow-query classification - #2314
Merged
github-actions[bot] merged 1 commit intoNov 24, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2270
Summary
Adds a per-tenant SQL query budget with slow-query auto-classification, implemented entirely under the issue's Technical Scope:
backend/src/lib/queryBudget.ts— zero-dependency, zero-I/O pure budget engine.backend/src/lib/db.ts— thin adapter wiring the budget into an injected query executor.queryBudget.tsQueryBudgetErrorwith stable codes (INVALID_CONFIG,INVALID_TENANT,INVALID_QUERY,BUDGET_EXCEEDED).maxQueriesPerWindow,windowMs) plus duration/rows-scanned thresholds; validated with documented defaults.classifyQuery()auto-classifies queries asFAST/SLOW/CRITICALusing the most severe duration or rows-scanned signal.createQueryBudget()controller:check,record,reset,snapshot,prune,nowwith per-tenant isolation and lazy/eager expiry.db.tscreateBudgetedQueryRunner({ budget, execute, metrics, logger, extractRowsScanned })performs a strict pre-flightbudget.check(tenantId), throwsBUDGET_EXCEEDEDbefore the database is touched, times execution, records and classifies the completed query, and emits execution/failure metrics and logs.Tests
backend/src/lib/__tests__/queryBudget.test.ts— 25 tests covering defaults, config validation, classification, sliding-window expiry, tenant isolation, budget denial, failure modes and observability.backend/src/lib/__tests__/db.test.ts— 13 tests covering runner configuration, happy path, budget rejection before execution, tenant/SQL validation, executor-error propagation, timing, classification and rows extraction.Observability
Budget denials, slow/critical classifications and executor failures emit structured logger warnings; metrics hooks cover accepted/rejected/recorded queries, slow/critical queries, pruning, resets, executed queries and failed queries.
Documentation
Public API is documented with JSDoc on every exported symbol. No new
.md/.jsonfiles were added.Payout addresses
Base Mainnet (USDC/ETH): 0xC5dD2Ea54FF138bb3f71D3466092eA31eF115868
Solana (USDC/SOL): DN3pfYEvdkoTBP4oaEVvemsr98fZPhDSAbfVfmewRGQ5
PayPal: ivanzenteno3@gmail.com