Skip to content

feat: traffic of each site and each site's own files (contract v0.6.0) - #53

Merged
nabil1440 merged 5 commits into
developfrom
feat/traffic-and-own-files
Oct 19, 2026
Merged

nabil1440 merged 5 commits into
developfrom
feat/traffic-and-own-files

Conversation

@shohag121

@shohag121 shohag121 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

White Label bandwidth and disk for each customer (flywp/flywp-internal-tasks#91, #92). Contract v0.6.0.

What changes

  • Traffic of each site. The agent reads the proxy's second log, ~/.fly/nginx/vhost/flywp-traffic.log ($server_name $bytes_sent), from a saved offset. Each sample gets traffic: [{host, bytes}].
    • The first read starts at the end of the file: old traffic is not counted.
    • The offset is saved before the sample is buffered. A sample that is dropped is not counted again.
    • The file opens with O_NOFOLLOW and must be a regular file. The agent cuts the open file once it read it and it is larger than 64 MiB.
    • A new file (another inode, or other first bytes: Linux can reuse the inode of a deleted file), or a file smaller than the offset, starts again from 0.
  • Own files of each site. sites[].files_bytes is the site's app folder only, from the same disk walk. The disk_bytes figure does not change.
  • Old FlyWP versions ignore the new fields. A new FlyWP reads them as optional.

Tested

  • make check: lint 0 issues, all tests pass, on macOS and on Linux (Go 1.27.2). golangci-lint goes to v2.15.0: v2.13.2 cannot read the export data of Go 1.27.2. New tests in internal/metrics/traffic_test.go.
  • On a real server (19 Oct): the FlyWP app wrote the proxy files, and the proxy wrote the log lines in the format this reader expects. The reader itself is covered by the unit tests only.

Release

  • Release as v0.3.0. The FlyWP app sets up the traffic log only on servers whose agent is v0.3.0 or newer (WHITE_LABEL_TRAFFIC_AGENT_VERSION). For another version number, set that env on FlyWP.
  • Agents update themselves 24 hours after the signature. Until then, bandwidth shows "not measured" on the customer pages.

🤖 Generated with Claude Code

shohag121 and others added 3 commits October 19, 2026 12:52
…files (contract v0.6.0)

- traffic: the bytes the front proxy sent for each site name since the sample before, read from ~/.fly/nginx/logs/traffic.log; null without the file.
- The first read starts at the end; the offset is saved before the sample is buffered; a new or cut file is read from the start; a file past 64 MiB is cut once read; at most 1000 names.
- sites[].files_bytes: the app folder of each project, from the same disk walk.

For flywp/flywp-internal-tasks#91 and #92.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AMtTQGy4K62exCWTJQCTdG
…file

- O_NOFOLLOW and a regular file only: a link in its place must not make the agent cut another file.
- The inode comes from the open file, and the cut is of the open file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AMtTQGy4K62exCWTJQCTdG
…s never re-created for it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AMtTQGy4K62exCWTJQCTdG
@itsrafsanjani
itsrafsanjani marked this pull request as ready for review October 19, 2026 09:53
setup-go now installs Go 1.27.2, and golangci-lint v2.13.2 cannot read its export data: the typecheck of the standard library fails, so make check stops at lint.
…inode only

Linux can give a new file the inode of one that was just deleted. The reader then went on from the old offset, in the middle of a line, and a line cut there can name another site. CI failed on it: TestTrafficReadsANewOrCutFileFromTheStart.
@nabil1440

Copy link
Copy Markdown
Contributor

CI fixes

  • Lint (f959d1a): setup-go now installs Go 1.27.2, and golangci-lint v2.13.2 cannot read its export data (typecheck of the standard library fails). Bumped to v2.15.0.
  • Traffic reader (ae4516d): TestTrafficReadsANewOrCutFileFromTheStart failed on Linux, which can give a new file the inode of one just deleted. The reader then went on from the old offset in the middle of a line, and a line cut there can name another site (shop.example.com → example.com).
    • traffic.json now also keeps a SHA-256 of the file's first bytes (up to 256, not past the offset). If the hash no longer matches, the reader starts from 0.
    • New test TestTrafficKnowsANewFileWithTheSameInode rewrites the file in place (same inode on every OS). It fails without the fix.
    • A negative offset in a corrupt traffic.json also reads from 0.

make check passes on macOS and on Linux (Go 1.27.2).

@nabil1440
nabil1440 merged commit 2adbfb7 into develop Oct 19, 2026
1 check passed
@nabil1440
nabil1440 deleted the feat/traffic-and-own-files branch October 19, 2026 10:18
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.

2 participants