Skip to content

Add Query Guard feature to reject expensive queries and update documentation - #9

Open
matheusandre1 wants to merge 1 commit into
prest:mainfrom
matheusandre1:query-quard-doc
Open

Add Query Guard feature to reject expensive queries and update documentation#9
matheusandre1 wants to merge 1 commit into
prest:mainfrom
matheusandre1:query-quard-doc

Conversation

@matheusandre1

@matheusandre1 matheusandre1 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

This is related to the issue and the PR, and should only be merged later.

Summary by CodeRabbit

  • Documentation
    • Added comprehensive Query Guard documentation and navigation links.
    • Documented configuration options for rejecting expensive queries based on execution plans.
    • Added guidance on scan, cost, row, index, and join limits.
    • Documented supported API paths, database-specific policies, error responses, startup behavior, and observability.
    • Included configuration examples, tuning guidance, and exception handling details.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Query Guard documentation

Layer / File(s) Summary
Navigation and overview
SUMMARY.md, get-started/README.md, get-started/query-guard.md
Adds Query Guard to Get Started navigation and documents plan inspection, policy rejection, and response behavior.
Configuration and policy rules
get-started/configuring-prest.md, get-started/query-guard.md
Documents TOML and environment-variable settings, rule evaluation, table exemptions, and per-database overrides.
Operational behavior and references
get-started/configuring-prest.md, get-started/query-guard.md
Documents guarded paths, adapter requirements, startup and error handling, logging, tuning, and related links.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: arxdsilva

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: adding Query Guard documentation for rejecting expensive queries.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@get-started/configuring-prest.md`:
- Around line 57-60: Expand the Query Guard entries in the main configuration
table to include PREST_QUERY_GUARD_REJECT_PARALLEL_SEQ_SCAN,
PREST_QUERY_GUARD_REQUIRE_INDEX_USAGE, and PREST_QUERY_GUARD_MAX_JOINS, with
their defaults and descriptions matching get-started/query-guard.md;
alternatively, add a clear link to that complete environment-variable table.

In `@get-started/query-guard.md`:
- Line 43: Update the 422 explanation in the documentation sentence by replacing
“used on purpose” with “used deliberately” and changing “well formed” to
“well-formed”; leave the surrounding status-code explanation unchanged.
- Line 145: Update the log-output fenced code block in the query guard
documentation to specify the text language by changing its opening fence to use
the text annotation, while leaving the block contents unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2e58d4db-c916-42ec-be7b-b62900620273

📥 Commits

Reviewing files that changed from the base of the PR and between e0a4c27 and 8ae551e.

📒 Files selected for processing (4)
  • SUMMARY.md
  • get-started/README.md
  • get-started/configuring-prest.md
  • get-started/query-guard.md

Comment on lines +57 to +60
| `PREST_QUERY_GUARD_ENABLED` | `false` | rejects queries by execution plan. See [Query Guard](query-guard.md) |
| `PREST_QUERY_GUARD_REJECT_SEQ_SCAN` | `false` | refuses plans containing a sequential scan. See [Query Guard](query-guard.md) |
| `PREST_QUERY_GUARD_MAX_COST` | `0` | ceiling on the estimated total cost (`0` disables). See [Query Guard](query-guard.md) |
| `PREST_QUERY_GUARD_MAX_ROWS` | `0` | ceiling on the estimated row count (`0` disables). See [Query Guard](query-guard.md) |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Document all Query Guard environment variables here.

The main configuration table lists only four settings, while get-started/query-guard.md also defines PREST_QUERY_GUARD_REJECT_PARALLEL_SEQ_SCAN, PREST_QUERY_GUARD_REQUIRE_INDEX_USAGE, and PREST_QUERY_GUARD_MAX_JOINS. Add those entries or explicitly link to the complete environment-variable table so this reference does not hide supported controls.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@get-started/configuring-prest.md` around lines 57 - 60, Expand the Query
Guard entries in the main configuration table to include
PREST_QUERY_GUARD_REJECT_PARALLEL_SEQ_SCAN,
PREST_QUERY_GUARD_REQUIRE_INDEX_USAGE, and PREST_QUERY_GUARD_MAX_JOINS, with
their defaults and descriptions matching get-started/query-guard.md;
alternatively, add a clear link to that complete environment-variable table.

}
```

`422` is used on purpose: the request is well formed and authorized (that would be `400` and `403`), but its execution plan is not acceptable.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use standard wording for the 422 explanation.

Replace “used on purpose” with “used deliberately” and hyphenate “well-formed” to resolve the documentation lint findings.

🧰 Tools
🪛 LanguageTool

[style] ~43-~43: Try using a descriptive adverb here.
Context: ... "reject_seq_scan" } ``` 422 is used on purpose: the request is well formed and authori...

(ON_PURPOSE_DELIBERATELY)


[grammar] ~43-~43: Use a hyphen to join words.
Context: ... is used on purpose: the request is well formed and authorized (that would be `40...

(QB_NEW_EN_HYPHEN)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@get-started/query-guard.md` at line 43, Update the 422 explanation in the
documentation sentence by replacing “used on purpose” with “used deliberately”
and changing “well formed” to “well-formed”; leave the surrounding status-code
explanation unchanged.

Source: Linters/SAST tools


Rejections are logged at `warn` level with the rule, the reason, the plan estimates and a compact plan shape:

```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Specify the log fence language.

Use a text language annotation for this log-output code block so Markdown linting can identify its contents correctly.

Proposed fix
-```
+```text
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```
🧰 Tools
🪛 markdownlint-cli2 (0.23.0)

[warning] 145-145: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@get-started/query-guard.md` at line 145, Update the log-output fenced code
block in the query guard documentation to specify the text language by changing
its opening fence to use the text annotation, while leaving the block contents
unchanged.

Source: Linters/SAST tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant