Переглянути джерело

docs: logrotate was never installed on prod - now installed, configured and verified

The unrotated access log had a cause nobody looked for: logrotate was not
installed at all, so nginx-common's config had no runner for a year. Installed
3.22.0, timer active, first rotation forced and verified by the check that
matters - nginx writes into the NEW file while the rotated one stays frozen,
which a leftover policy-rc.d would have broken silently. The eleven months of
history are archived compressed outside the rotation glob (245 MB -> 18.6 MB)
with a positive control proving the evidence is still recoverable. Future
sweeps need zgrep, and the shipped config keeps only 14 days.
fszontagh 1 місяць тому
батько
коміт
8777ec37a6
1 змінених файлів з 3 додано та 1 видалено
  1. 3 1
      CLAUDE.md

+ 3 - 1
CLAUDE.md

@@ -360,7 +360,9 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **The one way this switch bites: a wrong base returns HTML, not JSON.** Outside `/api/` the new host answers nginx's own branded 404 page, so a base string that still contains `/rag` gives the caller `text/html` and a JSON parse failure rather than our `{"error":{...}}` envelope. On the old host everything under `/rag/` reaches vectorapi, so a bad path there still returns JSON. The failure therefore does not name its own cause, and it lands at CONFIG time - which is why the advice to a consumer is to test one real write against the new base before flipping prod, and never to flip it the day before a go-live.
   **THE ACCESS LOG NOW CARRIES TIMING, AND IT IS `combined` PLUS THREE APPENDED FIELDS RATHER THAN A NEW SHAPE.** Done 2026-10-16 (task #84), after a consumer's latency question turned out to be unanswerable retrospectively: the built-in `combined` format records no time at all, so "was it slow yesterday" had no evidence in either direction. `/etc/nginx/conf.d/log-format-timing.conf` defines `log_format timing` as combined plus `host=$host rt=$request_time urt=$upstream_response_time`, and the two API server blocks set `access_log ... timing`. Appended, never reshaped, so anything parsing the combined prefix keeps working - the same additive discipline as `details.unsupported`.
   **`host=` is the field that is easy to leave out and then need**: prod serves two hostnames with different surfaces, so without it a line cannot be attributed to either. And **the GAP between `rt` and `urt` is usually the answer**, because it is the part a consumer cannot see from their own side: a slow client or a large body rather than a slow backend. `urt` is `-` when nothing was proxied, which is correct rather than zero.
-  **AND THE ACCESS LOG IS NOT ROTATED - IT RUNS BACK TO 2025-11-24, SO ANY "BY HOUR" AGGREGATE OVER IT IS ELEVEN MONTHS BUCKETED BY HOUR-OF-DAY.** Met 2026-10-22: asked how a consumer's 429s were distributed, I grouped by the hour field and produced a clean, plausible histogram peaking at 09:00 with 305 refusals. It was every 09:00 since November. Scoped to the actual day the answer was **44**. The artefact is convincing precisely because the shape looks like a working day. Scope the date first (`grep 22/Oct`), and check `head -1` for the log's real start before quoting any total as "today".
+  **THE ACCESS LOG IS ROTATED FROM 2026-10-22, AND THE TRAP BELOW IS KEPT BECAUSE THE SHAPE OUTLIVES THE FIX - BUT THE CAUSE WAS WORTH FINDING: `logrotate` WAS NEVER INSTALLED ON PROD AT ALL.** `nginx-common` ships `/etc/logrotate.d/nginx`, so the config sat there for a year with no runner, no `/etc/logrotate.conf`, no binary and no timer. Installed 3.22.0, timer enabled and active, and the first rotation was forced and verified: the new `access.log` is created `0640 www-data adm`, nginx writes into it (0 to 186 bytes across two requests) while the rotated file stays frozen, which is the check that matters because the postrotate goes through `invoke-rc.d nginx rotate` and a leftover `policy-rc.d` would have made it fail SILENTLY - nginx would have kept its handle on the renamed file and the new log would have stayed empty forever. Verified `policy-rc.d` was absent and that `invoke-rc.d nginx rotate` returns 0 BEFORE switching rotation on.
+  **The eleven months were archived rather than rotated away, because this box has repeatedly needed them:** `/var/log/nginx/archive/{access,error}-until-20261022.log.gz`, 245 MB to 18.6 MB and 79 MB to 3.6 MB, named `.gz` so they sit OUTSIDE the `*.log` glob logrotate manages (confirmed - it considers only `access.log` and `error.log`). Positive control on the archive rather than trusting gzip: the three key-DELETE lines are still recoverable through `zcat`, against three in the original, and the span still reads 24/Nov/2025 to 22/Oct/2026. **Two consequences for any future sweep: use `zgrep`/`zcat` for anything older than today, and note the shipped config keeps only `rotate 14` DAILY** - so from now on the live log holds a fortnight, which is thin given how often this file's answers have come out of it, and lengthening it means not editing a dpkg conffile.
+  The original trap, still worth recognising anywhere a log has no rotation: **AN UNROTATED ACCESS LOG MAKES ANY "BY HOUR" AGGREGATE ELEVEN MONTHS BUCKETED BY HOUR-OF-DAY.** Met 2026-10-22: asked how a consumer's 429s were distributed, I grouped by the hour field and produced a clean, plausible histogram peaking at 09:00 with 305 refusals. It was every 09:00 since November. Scoped to the actual day the answer was **44**. The artefact is convincing precisely because the shape looks like a working day. Scope the date first (`grep 22/Oct`), and check `head -1` for the log's real start before quoting any total as "today".
   **Two more traps in the same file, both of which produced wrong numbers before anything caught them.** `grep " 503 "` matches the BODY-SIZE field as well as the status, so it counts `200 503` lines as failures - it reported 1685 where `awk '$9==503'` reports 1. And a request count is not a concurrency measurement: 126 requests in a minute is what explained a timeout here, while the same count spread evenly would have explained nothing, so read the per-second clustering rather than the per-minute total.
 
   **It went in `conf.d` and in the SITE files, never in `nginx.conf`, which is an nginx-common CONFFILE** - `dpkg -S` first, per the trap above. `conf.d` is included at line 60 and `sites-enabled` at 61, so a format defined there is visible to the site files. A second `access_log` at the http level would have DOUBLE-logged every request rather than replacing the default, which is why it is set per server block.