Write per-crawl stats: HTTP status counts + sitemap accounting for auditing - #9
Write per-crawl stats: HTTP status counts + sitemap accounting for auditing#9MirjamOdile wants to merge 3 commits into
Conversation
Every completed crawl now persists its own numbers to data/<project>/_audit/crawl_stats/<spider>.json: - BaseDBSpiderMixin.closed() dumps item count, request count, and the HTTP status histogram Scrapy already tracks — giving an audit EXACT page liveness for free instead of a slow sampled re-fetch pass. Only on reason=="finished", so partial/test (--limit) runs can't overwrite a real crawl's numbers. - Sitemap spiders additionally count, while parsing, the sitemap's page URLs (sitemap_total) and those that survive date/deny filters AND match an allow rule (eligible) — the coverage denominator, recorded from the real crawl so nothing re-fetches the sitemap. <sitemapindex> entries (sub-sitemap refs) are never counted as pages. See docs/requests/06-per-crawl-stats.md (ships with the quality tool PR) for the full write-up.
9c290a8 to
6e07c21
Compare
aee745e to
774ff44
Compare
|
Heads-up: one fix-up commit appended since you last looked ( What was broken: the sitemap page-counter this PR introduces (it records "how many pages does the sitemap list" for the audit's coverage target) over-counted in two ways — What it does now: the counter counts each real page once — unique locs only, media extensions excluded (mirroring the audit's fetched-path filter). Measurement-only: nothing about The commit also updates one test expectation in the writer tests for an audit-side change riding on the quality-tool PR (5xx no longer count as dead in liveness); the test skips cleanly Request doc: |
The crawl-recorded coverage denominator (_sm_total/_sm_eligible) summed raw locs across sub-sitemap files with no dedup and counted image/attachment locs as content pages — one site showed 3,742 phantom 'missing' pages from attachment images alone. Count unique non-media page locs instead (measurement-only; nothing about the crawl itself changes). Also updates the liveness expectation in the writer tests for the audit-side 5xx fix (docs/requests/22 Fix A; skips cleanly when the quality tool is absent). docs/requests/23-sitemap-crawl-denominator.md
774ff44 to
1523a65
Compare
3c71c70 to
309aaa9
Compare
Problem
Assessing a fleet's health needs each crawl's page liveness (HTTP status mix)
and a coverage denominator (how many URLs the sitemap declared, how many were
rule-eligible). Sampling that after the fact is slow (re-fetching ~1000 URLs
per spider) and drifts — the sitemap you fetch today isn't the one the crawl
saw. Scrapy already counts every response status during the crawl; the data
just isn't persisted anywhere.
Change
Every completed production crawl persists its own numbers to
data/<project>/_audit/crawl_stats/<spider>.json:BaseDBSpiderMixin.closed()dumps item count, request count, and the HTTPstatus histogram Scrapy already tracks (filtered on the
downloader/response_status_count/prefix so nothing else leaks in).(
sitemap_total) and those that survive date/deny filters AND match anallow rule (
eligible) — the coverage denominator, recorded from the realcrawl at the crawl's own point in time.
<sitemapindex>entries (sub-sitemaprefs) are never counted as pages.
Guards, so a wrong number can never masquerade as a right one:
CLOSESPIDER_ITEMCOUNTsetting, not the close reason: a
--limit/health run that finishes UNDERits cap still closes with
reason == "finished"and must not overwrite areal crawl's stats.
the request queue from disk but every in-memory counter restarts at zero.
Detection reads the scheduler's own persisted state
(
JOBDIR/requests.queue/active.json— non-empty exactly when a runcontinues an interrupted crawl); the writer then withholds
sitemap_total/eligibleand stamps"resumed": true, keeping leg-onlyitems/status.
Verification
17 unit tests: writer happy-path and negative paths (non-finished reasons,
item-capped runs, resumed runs, write failure), sitemap counter fidelity
(match-all fallback, sitemapindex exclusion, relative-loc resolution), and
resume detection state matrix. Two additional round-trip tests (auto-skipped
in trees without a consumer) prove the file parses back into liveness/coverage
readings. Full unit suite green.
Known limitations (documented, deliberate)
items/status(marked"resumed": true).The full fix — accumulating counters across legs in the checkpoint dir — is
a worthwhile follow-up, but must handle the dupefilter-clearing corruption
recovery (which makes a resumed leg re-parse sitemaps → double-count risk).
only newly fetched URLs.