Skip to content

feat(apidocs): Add a shared scan and owner lookup for API rule findings - #131117

Merged
akhilp117 merged 2 commits into
masterfrom
akhilpindiprolu/eng-8866-add-api-findings-scan
Nov 18, 2026
Merged

akhilp117 merged 2 commits into
masterfrom
akhilpindiprolu/eng-8866-add-api-findings-scan

Conversation

@akhilp117

@akhilp117 akhilp117 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Linear issue

This PR adds the logic of scanning files in src and running flake on them, regardless of however the existing findings end up being stored (an exceptions.json file or inline comments). The upcoming API report card is built on these

What's added

  • tools/api_guidelines/scan.py: collect_findings scans every file under src/ with the plugin's structured output (get_api_violations) and returns (path, finding) pairs with repo-relative paths
  • tools/api_guidelines/rules.py: BASELINED_RULES (S025-S028), the rules whose existing findings are kept as legacy debt. The scan doesn't use it: it returns every rule's findings, and each caller picks the rules it needs. The baselined rules keeps only these, while the report card will show every rule
  • tools/api_guidelines/owners.py: owner_for finds the team that owns a finding from the owner map (make api-owner-map). A finding in a module-level helper, or on a base class that isn't routed, gets its owner through caller, the public method that reached it. It falls back to unowned

On master f362f374645, collect_findings gives 293 findings, the same total as flake8 --select=S025,S026,S027,S028 with SENTRY_INPUT_LINT_ALL=1

Once this merges, #131088 will import collect_findings from here and only keep the exceptions.json writing

@akhilp117
akhilp117 requested a review from a team as a code owner November 13, 2026 20:25
@linear-code

linear-code Bot commented Nov 13, 2026

Copy link
Copy Markdown

ENG-8866

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 13, 2026
@akhilp117
akhilp117 force-pushed the akhilpindiprolu/eng-8866-add-api-findings-scan branch from c6c6d74 to 159ede7 Compare November 18, 2026 03:53
@akhilp117
akhilp117 merged commit bfab79d into master Nov 18, 2026
63 checks passed
@akhilp117
akhilp117 deleted the akhilpindiprolu/eng-8866-add-api-findings-scan branch November 18, 2026 04:33
akhilp117 added a commit that referenced this pull request Nov 18, 2026
…131088)

This PR introduces `make api-baseline`, a new make command that writes
every S025-S028 finding to `api_exceptions/exceptions.json`. The report
card and the upcoming CI job will read from this file. The scan and
owner lookup it uses are in #131117. Each entry is one finding (an error
founds by flake) signature (rule, path, scope, key) with its count,
owner, status, reason and when it was first seen

Here's a list of the arguments that can be passed in:
- `--files` only rescans the files you pass and keeps everything else as
is. Existing entries keep their status, reason and first_seen. It prints
what's new, fixed, or changed
- `--root` scans another checkout (i.e, an older commit) with the
current rules (used for demoing)
- `--force` is needed to regenerate the whole file since that resets
statuses

Renames, deletions, and bad paths with --files:
- Entries for a file that's no longer in the checkout are removed and
reported as fixed, whether or not that file was listed. So a plain `git
diff --name-only` works and `--no-renames` isn't needed anymore
- If a removed entry and a new one share the same rule, scope and key,
it warns "Possibly moved", since the status and reason don't carry over
to the new path
- If a file is gone and wasn't listed, it warns that its new path
probably needs a rescan, or those findings will show up as new on the
next run
- Paths that can't be rescanned (outside src/, not .py, or missing with
no entries, like a typo) are printed to stderr, and the run exits 1 if
none of them can be used

If a dev renames a file, its findings show up as fixed under the old
path and new findings under the new path. Devs must use `git diff
--no-renames` to get the file list and pass that into `--files` so the
old path's entries get removed too
akhilp117 added a commit that referenced this pull request Nov 18, 2026
[Linear
issue](https://linear.app/getsentry/issue/ENG-9043/build-a-per-team-api-report-card-v0)

Stacked on #131117 (the shared scan and owner lookup) so that one needs
review firstt.

This adds `make api-report-card`, which shows each team its existing API
lint findings, so every piece of API debt has a visible owner. It scans
`src/` with `collect_findings` and finds each finding's team with
`owner_for`. It doesn't need a baseline or any exceptions.

**What it prints**
- A header with the total, the owner map's date (the file's modification
time, since the map has no date inside it) and how many findings are
`unowned`, so a stale map is easy to spot
- A table with one row per team, sorted by findings, with a column per
rule and the number of files. `unowned` is always its own row, last,
even when it's 0
- The rule columns are S025-S028 always (S027 has 0 findings but is
still checked), plus any other API rule that has findings. So S034 and
S021-S023 show up on their own once they report structured output. Until
then the header lists them as having no structured findings, so nobody
reads them as clean

**Options** (through `ARGS`)

- `ARGS="--team issues-feed"`: that team's findings, one per line
(`file:line rule key in Class.method`), sorted by file and line
- `ARGS="--format markdown"`: the same table as markdown, for docs and
PR comments

**On master today**: 293 findings in 78 files across 18 teams, plus 24
`unowned` findings in 7 files under `src/sentry/core/endpoints/`

**Not in v0:** the legacy vs new split and statuses (they depend on how
exceptions get stored), trends over time, and running in CI (which needs
a decision on where the owner map comes from)
BYK added a commit that referenced this pull request Nov 20, 2026
Refs #131073

Our OpenAPI docs drift from what endpoints actually return, and nothing
catches it. This compares the responses tests get from **public**
operations with the schema drf-spectacular generates from the code:

- **S036**: the status isn't in the operation's `responses`
- **S037**: the JSON body doesn't match that status's schema

304, 429 and 5xx are exempt: a 304 only answers a conditional request,
the rate limiter can return a 429 from any endpoint, and a 5xx is a bug
rather than part of the contract. S035 is taken by
#130924.

This stands alone and doesn't touch the API guidelines work in
#131117 → #131088 →
#131135 → #131407. Findings use the same
signature (endpoint file, `EndpointClass.method`, `status:<code>`,
owner) and entry shape as that stack's `exceptions.json`, which is where
the baseline goes once the stack lands.

The pytest plugin is opt-in, with two modes. Report mode records
findings and annotates endpoints whose findings aren't baselined. Strict
mode also fails the test that got one. The schema is generated while
xdist workers start, so it always matches the code and doesn't need
node.

A new baseline tool adds a run's findings to a baseline file. It only
touches the endpoint methods that run called, and keeps reviewed
statuses.

Backend CI runs in report mode, so nothing blocks merges. CI moves to
strict mode together with the baseline.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3A3bcd89ea85721d16b9af505e -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/local%3Aweb%3A3bcd89ea85721d16b9af505e)
[[Sentry]](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A3bcd89ea85721d16b9af505e/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants