mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-10-11 20:17:35 +00:00
Rebase of #1881 by @SaarMesh-Bot onto current master. Their three commits are preserved, two of them cherry-picked with authorship intact; the sweep itself had to be regenerated. Opened as a new PR rather than force-pushing their branch. Closes #1881 once merged. Addresses parts 1 and 3 of #1859; part 2 landed as #1937. ## Why regenerated rather than merged The sweep in #1881 was cut on 2026-09-02 07:13 and roughly forty PRs landed after it, so it went `CONFLICTING/DIRTY`. Re-running `gofmt` on current master is cheaper and less error-prone than resolving 72 conflicts that are all whitespace. The drift it fixes also grew in the meantime: 66 files now, against 72 then, but spread differently. ## The three commits 1. **`style(#1859)`** — `gofmt -w` across the 14 modules. 66 files. 2. **`test(#1859)`** — @SaarMesh-Bot's fix for the one `go vet` copylocks finding, `cmd/ingestor/coverage_boost_test.go`: the range variable copied a `Config` embedding `sync.Once`. Cherry-picked unchanged. 3. **`ci(#1859)`** — @SaarMesh-Bot's CI step that fails on gofmt drift or vet findings, plus `.git-blame-ignore-revs`. Cherry-picked with one change, noted in the commit message: the ignore file pointed at `04bc80ee`, the sweep commit on their branch, which does not exist on this base and would make `git blame --ignore-revs-file` error. Repointed at `d3a02599`, the sweep here. ## Verification The claim "formatting only" is checked twice rather than asserted: - Every changed file is byte-identical to `gofmt(previous content)`. 0 of 66 deviate. - With line comments and all whitespace stripped, 0 of 66 files differ, so no code outside comments changed. 14 of the 66 also show doc-comment reflow. Since Go 1.19 `gofmt` re-indents indented comment blocks to tabs and inserts a blank comment line before them; the behavior matrix above `resolveHopWithContext` in `cmd/ingestor/path_resolver.go` is a clear example. That is gofmt's own output, not an edit, but it is worth naming because it makes the diff look larger than "whitespace" suggests. The gate was run locally exactly as the workflow runs it: `gofmt` clean, and `go vet` clean in all 14 modules, including `cmd/ingestor` which is what commit 2 fixes. Suites: `cmd/server` ok (80.7s), `internal/packetpath` ok (2.3s), `cmd/ingestor` passes except `TestWriteStatsAtomic_SymlinkAtDestIsReplaced`, which fails identically on bare master with "A required privilege is not held by the client" (Windows symlink privilege on my host, not code). ## Sequencing This should go last in the queue. The sweep touches 66 files, so merging it before the remaining open Go PRs gives each of them a conflict about nothing but formatting. After it lands the gate is active, and any PR with drift fails CI until it runs `gofmt -w`. Excluded from the sweep: the misnamed `Dockerfile.go`, which is a Dockerfile that gofmt cannot parse (the workflow excludes it too), and `docs/DEPLOYMENT.md`, which a case-insensitive filesystem surfaces as a spurious modification against `docs/deployment.md` and is unrelated. --------- Co-authored-by: SaarMesh-Bot <300107934+SaarMesh-Bot@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
80 lines
2.7 KiB
Go
80 lines
2.7 KiB
Go
// Package perfio holds the canonical PerfIOSample type shared between the
|
|
// ingestor (which publishes /proc/self/io rate samples to its on-disk stats
|
|
// file) and the server (which reads that file and surfaces the sample under
|
|
// /api/perf/io's `ingestor` block). Sharing the type prevents silent JSON
|
|
// contract drift if a field is added on one side only.
|
|
//
|
|
// The /proc/self/io key:value parser also lives here (Carmack #1167
|
|
// must-fix #7) so the two binaries don't carry divergent copies of the
|
|
// same parser — past divergence already produced a real bug (see must-fix
|
|
// #6: the parsedAny empty-key gate was added on one side only).
|
|
package perfio
|
|
|
|
import (
|
|
"bufio"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Sample is the per-process I/O rate sample written by the ingestor and
|
|
// consumed by the server. Field names + json tags MUST be considered the
|
|
// stable on-disk contract — adding/renaming a field is a breaking change.
|
|
type Sample struct {
|
|
ReadBytesPerSec float64 `json:"readBytesPerSec"`
|
|
WriteBytesPerSec float64 `json:"writeBytesPerSec"`
|
|
CancelledWriteBytesPerSec float64 `json:"cancelledWriteBytesPerSec"`
|
|
SyscallsRead float64 `json:"syscallsRead"`
|
|
SyscallsWrite float64 `json:"syscallsWrite"`
|
|
SampledAt string `json:"sampledAt,omitempty"`
|
|
}
|
|
|
|
// Counters is the raw /proc/self/io counter snapshot. Both the ingestor's
|
|
// procIOSnapshot and the server's procIOSample are thin wrappers around
|
|
// these fields plus a sampled-at timestamp; the parser populates Counters
|
|
// directly so there's exactly ONE implementation of the key:value walker.
|
|
type Counters struct {
|
|
ReadBytes int64
|
|
WriteBytes int64
|
|
CancelledWriteBytes int64
|
|
SyscR int64
|
|
SyscW int64
|
|
}
|
|
|
|
// ParseProcIO reads /proc/self/io-shaped key:value lines from sc and
|
|
// populates c. Returns true iff at least one recognised key was
|
|
// successfully parsed (Carmack must-fix #6 — empty / no-known-keys input
|
|
// must NOT be treated as a valid sample, otherwise the next tick computes
|
|
// a phantom delta against zero counters).
|
|
func ParseProcIO(sc *bufio.Scanner, c *Counters) bool {
|
|
parsedAny := false
|
|
for sc.Scan() {
|
|
parts := strings.SplitN(sc.Text(), ":", 2)
|
|
if len(parts) != 2 {
|
|
continue
|
|
}
|
|
key := strings.TrimSpace(parts[0])
|
|
val, err := strconv.ParseInt(strings.TrimSpace(parts[1]), 10, 64)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
switch key {
|
|
case "read_bytes":
|
|
c.ReadBytes = val
|
|
parsedAny = true
|
|
case "write_bytes":
|
|
c.WriteBytes = val
|
|
parsedAny = true
|
|
case "cancelled_write_bytes":
|
|
c.CancelledWriteBytes = val
|
|
parsedAny = true
|
|
case "syscr":
|
|
c.SyscR = val
|
|
parsedAny = true
|
|
case "syscw":
|
|
c.SyscW = val
|
|
parsedAny = true
|
|
}
|
|
}
|
|
return parsedAny
|
|
}
|