Documentation
¶
Overview ¶
Package diagnostics records bounded, content-free collection diagnostics. Callers supply metadata and structured events, never argv, output or error text.
Index ¶
- Constants
- Variables
- func Export(directory, id string, latest bool, output string) error
- func Save(directory string, report Report) error
- func ValidID(id string) bool
- type CommandInfo
- type CommandRecord
- type CommandResult
- type Failure
- type Metadata
- type Outcome
- type Recorder
- type Report
- type StageInfo
- type StageRecord
- type StageTotal
- type Totals
- type Workload
Constants ¶
const ( SchemaVersion = 1 MaxCommands = 128 MaxSlowest = 20 MaxStages = 128 MaxStageTotals = 512 MaxReportBytes = 1 << 20 MaxReports = 5 )
Variables ¶
Functions ¶
func Export ¶
Export copies one validated schema-1 report to a newly created private output file. latest and id are mutually exclusive. Existing output is never replaced, including symlinks. Reads reject report symlinks and files over 1 MiB.
func Save ¶
Save atomically stores a report under directory and retains the five newest reports. Every reader/writer uses the same persistent process lock. The caller decides whether a save error should be logged; it must not replace collection's primary result. No configuration or application services are consulted here.
Types ¶
type CommandInfo ¶
type CommandRecord ¶
type CommandRecord struct {
CommandInfo
Sequence uint64 `json:"sequence"`
StartedMS int64 `json:"startedMs"`
ElapsedMS int64 `json:"elapsedMs"`
QueueWaitMS int64 `json:"queueWaitMs"`
StdoutBytes int64 `json:"stdoutBytes"`
StderrBytes int64 `json:"stderrBytes"`
ExitStatus *int `json:"exitStatus,omitempty"`
DeadlineKind string `json:"deadlineKind"`
InFlight bool `json:"inFlight"`
Failure *Failure `json:"failure,omitempty"`
}
type CommandResult ¶
type CommandResult struct {
QueueWait time.Duration
Elapsed time.Duration
StdoutBytes int64
StderrBytes int64
ExitStatus *int
DeadlineKind string
Failure *Failure
}
CommandResult includes queue wait separately from process execution time. ExitStatus is nil when a process never produced an exit status.
type Failure ¶
type Failure struct {
Kind string `json:"kind"`
Detail string `json:"detail,omitempty"`
Phase string `json:"phase,omitempty"`
Code string `json:"code,omitempty"`
}
Failure deliberately has no error/string-message field. Unknown values become "unknown"; Detail is an allowlisted summary code, never exception text.
type Metadata ¶
type Metadata struct {
AppVersion string `json:"appVersion"`
BuildCommit string `json:"buildCommit,omitempty"`
BuildDate string `json:"buildDate,omitempty"`
BuildModified bool `json:"buildModified"`
Platform string `json:"platform"`
Architecture string `json:"architecture"`
GoVersion string `json:"goVersion"`
GitVersion string `json:"gitVersion"`
GitPath string `json:"gitPath,omitempty"`
Operation string `json:"operation"`
}
Metadata contains build/runtime facts only. GitPath is pseudonymized by New. Unrecognized versions/platforms/operations are replaced with "unknown".
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder is safe for concurrent workers. A snapshot includes active commands; it cannot survive a process crash unless the caller saves it before the crash.
func (*Recorder) AddWorkload ¶
AddWorkload adds nonnegative deltas; counters survive event truncation.
func (*Recorder) BeginCommand ¶
func (r *Recorder) BeginCommand(info CommandInfo) func(CommandResult)
BeginCommand starts before queue admission. Complete it even on cancellation. At most 128 active commands are retained, independently of the latest list.
func (*Recorder) BeginStage ¶
BeginStage returns an idempotent completion callback. Active stages remain in the bounded latest stage list; totals count even stages omitted from that list.
type Report ¶
type Report struct {
SchemaVersion int `json:"schemaVersion"`
ID string `json:"id"`
Metadata Metadata `json:"metadata"`
StartedAt time.Time `json:"startedAt"`
ElapsedMS int64 `json:"elapsedMs"`
Outcome Outcome `json:"outcome"`
Totals Totals `json:"totals"`
Stages []StageRecord `json:"stages"`
LatestCommands []CommandRecord `json:"latestCommands"`
SlowestCommands []CommandRecord `json:"slowestCommands"`
InFlightCommands []CommandRecord `json:"inFlightCommands"`
DroppedCommands uint64 `json:"droppedCommands"`
DroppedStages uint64 `json:"droppedStages"`
DroppedInFlight uint64 `json:"droppedInFlight"`
}
type StageInfo ¶
type StageInfo struct {
Name string `json:"name"`
Scope string `json:"scope,omitempty"`
Attempt int `json:"attempt"`
Repository string `json:"repository,omitempty"`
Ref string `json:"ref,omitempty"`
URL string `json:"url,omitempty"`
}
StageInfo and CommandInfo use fixed category names. Repository, Ref and URL accept raw identifiers only to hash them immediately, with a report-local key.
type StageRecord ¶
type StageTotal ¶
type StageTotal struct {
Name string `json:"name"`
Scope string `json:"scope,omitempty"`
Started uint64 `json:"started"`
Completed uint64 `json:"completed"`
Failed uint64 `json:"failed"`
Attempts uint64 `json:"attempts"`
ElapsedMS int64 `json:"elapsedMs"`
}
StageTotal aggregates every event by its fixed stage and scope categories, independently of the bounded individual stage list.
type Totals ¶
type Totals struct {
Commands uint64 `json:"commands"`
CompletedCommands uint64 `json:"completedCommands"`
FailedCommands uint64 `json:"failedCommands"`
CommandElapsedMS int64 `json:"commandElapsedMs"`
QueueWaitMS int64 `json:"queueWaitMs"`
StdoutBytes int64 `json:"stdoutBytes"`
StderrBytes int64 `json:"stderrBytes"`
Stages uint64 `json:"stages"`
Workload Workload `json:"workload"`
StageTotals []StageTotal `json:"stageTotals"`
}