Commit Graph

17 Commits

Author SHA1 Message Date
Pim van Pelt
e1f8bc5eb4 fix: UDP listener parses batched datagrams
nginx-ipng-stats-plugin's ipng_stats_logtail directive buffers many log
lines into a single UDP datagram (default buffer=64k flush=1s). The
listener was treating each datagram as exactly one log line, so any
datagram with N>1 lines failed the v1 field-count check and dropped
silently. In production this showed up as logtail_udp_packets_received_total
roughly 4x logtail_udp_loglines_success_total — matching typical
burst-coalesced 4-lines-per-batch ratios.

Fix: strip trailing CRLF, split the payload on '\n', parse each
non-empty line independently. Counter semantics now match the names:

  packets_received  — datagrams off the socket (one per recvfrom)
  loglines_success  — log lines parsed OK (may be many per datagram)
  loglines_consumed — log lines forwarded to the store (not dropped)

After the fix, loglines_success ≈ packets_received × avg_lines_per_batch.

Regression test TestUDPListenerBatchedDatagram sends one datagram with
three '\n'-separated v1 lines and asserts all three LogRecords arrive,
plus loglines_success >= 3 * packets_received.

Docs (user-guide.md, design.md) now explain the datagram-vs-line unit
distinction so operators don't misread the ratio.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 11:59:43 +02:00
Pim van Pelt
589030cb00 doc-fix: clarify UDP listener handles multi-source peers
No runtime change — the listener already uses net.ListenUDP +
ReadFromUDP, which is the unconnected-socket pattern that accepts
datagrams from any source. nginx reloads (new workers with fresh
ephemeral source ports) are handled transparently.

- udp.go: expanded comment on Run() explaining the design choice and
  contrasting with the `nc -k -u -l` latching quirk (which is an nc
  bug, not a kernel behaviour).
- udp_test.go: new TestUDPListenerMultipleSources regresses against
  the multi-worker scenario by sending from three independent
  ListenPacket sockets (three different ephemeral source ports).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 10:39:34 +02:00
Pim van Pelt
143aad9063 PRE-RELEASE 0.9.1: Makefile, Debian packaging, versioned UDP
Build and release tooling:
- Makefile with help as default; targets: build/build-amd64/build-arm64,
  test, lint, proto, pkg-deb, docker, docker-push, clean, plus
  install-deps (+ three sub-targets for apt / Go toolchain / Go tools).
- internal/version package; -ldflags -X injects Version/Commit/Date into
  every binary. -version flag on all four binaries (nginx-logtail version
  for the CLI).
- Dockerfile takes VERSION/COMMIT/DATE build-args and forwards them.
- .deb output lands in build/; .gitignore ignores /build/.

Debian package:
- debian/build-deb.sh packages all four static binaries into a single
  nginx-logtail_<ver>_<arch>.deb using dpkg-deb.
- Binary layout: /usr/sbin/nginx-logtail-{collector,aggregator,frontend}
  and /usr/bin/nginx-logtail.
- nginx-logtail(8) manpage.
- Three systemd units (collector, aggregator, frontend) shipped under
  /lib/systemd/system/. Installed but never enabled or started — the
  operator opts in per host.
- Collector runs as _logtail:www-data (log access); aggregator and
  frontend as _logtail:_logtail. postinst creates the system user/group
  idempotently.
- Single shared env file /etc/default/nginx-logtail rendered from a
  template at first install with %HOSTNAME% substituted. Sensible
  defaults for every COLLECTOR_*, AGGREGATOR_*, FRONTEND_* variable;
  plus COLLECTOR_ARGS / AGGREGATOR_ARGS / FRONTEND_ARGS escape hatches
  appended to ExecStart. Not a dpkg conffile: operator edits survive
  upgrades and dpkg --purge removes it.

Versioned UDP wire format:
- ParseUDPLine dispatches on a leading "v<N>\t" tag; v1 routes to the
  existing 12-field parser. Unknown/missing versions fail closed so
  future v2 parsers can land before emitters are upgraded.
- Tests updated; design.md FR-2.2 rewritten to make the version tag
  normative.

Docs:
- README.md gains a Quick Start (Debian / Docker Compose / from source).
- user-guide.md rewritten around Installation and Configuration: full
  env-var table, UDP-only default explained, precise file/UDP log_format
  layouts, note that operators can emit "0" for unknown \$is_tor / \$asn.
- Drilldown cycle, frontend filter table, and CLI --group-by list all
  include source_tag. UDP counters documented in the Prometheus section.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 10:35:08 +02:00
Pim van Pelt
577ed3dad5 Refactor docs; Add 'ipng_source_tag', add udp listener for nginx-ipng-stats plugin 2026-04-17 09:50:54 +02:00
Pim van Pelt
eddb04ced4 Add aggregator backfill, pulling fine+coarse buckets from collectors 2026-03-25 07:06:03 +01:00
Pim van Pelt
d2dcd88c4b Add Docker setup, add environment vars for each flag 2026-03-25 06:41:13 +01:00
Pim van Pelt
91eb56a64c Add prometheus exporter on :9100 2026-03-24 03:49:22 +01:00
Pim van Pelt
c7f8455188 go fmt 2026-03-24 02:30:18 +01:00
Pim van Pelt
30c8c40157 Add ASN to logtail, collector, aggregator, frontend and CLI 2026-03-24 02:28:29 +01:00
Pim van Pelt
0fb84813a5 Enable lame-duck on exit, so systemctl can 'restart' collectors 2026-03-23 22:18:05 +01:00
Pim van Pelt
cd7f15afaf Add is_tor plumbing from collector->aggregator->frontend/cli 2026-03-23 22:17:39 +01:00
Pim van Pelt
b89caa594c Auto-rediscover new glob patterns 2026-03-23 20:39:12 +01:00
Pim van Pelt
d3160c7dd4 Print peer address 2026-03-16 02:45:47 +01:00
Pim van Pelt
7f93466645 Implement target selection, autodiscovery via aggregator, implement listTargets 2026-03-15 05:04:46 +01:00
Pim van Pelt
afa65a2b29 Implement filter in status, website and uri in CLI and Frontend 2026-03-14 21:59:30 +01:00
Pim van Pelt
76612c1cb8 Execute PLAN_AGGREGATOR.md 2026-03-14 20:22:16 +01:00
Pim van Pelt
6ca296b2e8 Collector implementation 2026-03-14 20:07:32 +01:00