Documentation
¶
Overview ¶
Package runarchive assembles one agent run's long-term record and decides what a run's status keeps when archival is configured.
A controller sees an agent's full output exactly once, when it collects the finished Job's log. Archive turns that output into immutable objects under one prefix per run attempt:
<prefix>/<namespace>/<finding>/<run-name>/<run-uid>/
transcript.jsonl.gz every streamed turn, uncompacted
report.md the full raw report, frontmatter included
patch.mbox remediation: git format-patch --binary
changeset.json.gz remediation: the changeset patchy pushes
manifest.json written last: the run, its accounting, and the
sha256 and size of every object above
push.json remediation: branch, commit and PR, after the push
The run UID is in the path because finding and run names are reused after the TTL. Every object's bytes are a pure function of the run's output (no wall clock), so a re-collected run rewrites identical bytes and the create-only store accepts the retry.
Collector is the decision both run controllers share: archive and record references (no ConfigMap), retry within a window while the pod log is still readable, and past the window either fall back to the ConfigMap transcript (fail-open, the default) or fail the run (required).
Index ¶
Constants ¶
const DefaultRetryWindow = 45 * time.Minute
DefaultRetryWindow is the retry window when none is configured: well inside the default one-hour Job TTL.
const ManifestVersion = 1
ManifestVersion is the manifest.json schema version.
const OutcomeArchiveFailed = "archive_failed"
OutcomeArchiveFailed is the run outcome when a required archive could not be written: the run fails and nothing downstream (verdict, push) happens.
Variables ¶
This section is empty.
Functions ¶
func RegisterFlags ¶
RegisterFlags declares the run controllers' archive flags: the shared store location plus the failure policy.
Types ¶
type Archiver ¶
type Archiver struct {
// Store receives the objects.
Store archive.Store
// Config is where Store points (provider, bucket, prefix), recorded on
// each reference so a reader needs no configuration of its own.
Config archive.Config
// Required fails a run whose archive cannot be written, instead of
// falling back to the ConfigMap transcript.
Required bool
// RetryWindow bounds how long after the Job finished a failed upload is
// retried. It must stay below the Job TTL, after which the log is gone.
RetryWindow time.Duration
// Now tells time; nil means time.Now.
Now func() time.Time
}
Archiver writes runs to an archive store.
func FromOptions ¶
FromOptions opens the configured archive, or returns nil when archival is disabled. The retry window must close before the Job TTL removes the pod log the retry re-reads, so a window at or beyond jobTTL is refused.
func (*Archiver) Archive ¶
func (a *Archiver) Archive(ctx context.Context, run Run, out jobs.RunOutput) (*v1alpha1.ArchiveRef, error)
Archive uploads the run's objects, the manifest last, and returns the reference to record on the run. Every object is create-only, so calling it again for the same output is safe.
func (*Archiver) RecordPush ¶
RecordPush writes push.json beside an archived remediation, linking the archive to the branch and pull request it became.
type Collector ¶
type Collector struct {
// Client writes ConfigMap transcripts.
Client client.Client
// Archiver is nil when archival is disabled.
Archiver *Archiver
// Events receives the Warning for an abandoned archive; nil discards.
Events events.EventRecorder
// Log receives diagnostics; nil discards.
Log *slog.Logger
}
Collector persists what a finished run said: to the archive when one is configured, otherwise (or on fail-open fallback) as a ConfigMap transcript.
func (*Collector) Collect ¶
func (c *Collector) Collect(ctx context.Context, run Run, out jobs.RunOutput, t Target) (*Record, time.Duration)
Collect decides the run's record. A positive retry duration means the archive upload failed but the window is still open: the caller should requeue after it and change nothing, since the next pass re-reads the same pod log and rewrites identical objects. Collect itself never fails the reconcile: a transcript that cannot be stored is logged and dropped, because losing the explanation must never cost the result it explains.
func (*Collector) RecordPush ¶
RecordPush writes push.json for an archived remediation, best-effort: the pull request is already open, so a failure is logged and counted only.
type Manifest ¶
type Manifest struct {
Version int `json:"version"`
Kind string `json:"kind"`
Run struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
UID string `json:"uid"`
Attempt int32 `json:"attempt"`
CreatedAt string `json:"createdAt,omitempty"`
} `json:"run"`
Finding *ManifestFinding `json:"finding,omitempty"`
BaseSHA string `json:"baseSHA,omitempty"`
FinishedAt string `json:"finishedAt,omitempty"`
// Stage is the agent's own stage block, verbatim from the envelope.
Stage *envelope.Stage `json:"stage,omitempty"`
// Fatal carries a runner that could not produce a stage at all.
Fatal string `json:"fatal,omitempty"`
Transcript *struct {
Turns int `json:"turns"`
Truncated bool `json:"truncated"`
} `json:"transcript,omitempty"`
// Objects digests every other object in the run's prefix.
Objects []v1alpha1.ArchiveObject `json:"objects"`
}
Manifest describes one archived run. It is written last; its presence means every object it lists is complete.
type ManifestFinding ¶
type ManifestFinding struct {
Name string `json:"name"`
UID string `json:"uid,omitempty"`
Source string `json:"source,omitempty"`
Integration string `json:"integration,omitempty"`
RuleID string `json:"ruleID,omitempty"`
Title string `json:"title,omitempty"`
Severity v1alpha1.Level `json:"severity,omitempty"`
Advisories []string `json:"advisories,omitempty"`
Repository *v1alpha1.FindingRepository `json:"repository,omitempty"`
CloudResource *v1alpha1.FindingCloudResource `json:"cloudResource,omitempty"`
Alerts []v1alpha1.Alert `json:"alerts,omitempty"`
}
ManifestFinding is what the manifest records about the finding, so the archive explains itself after the Finding resource has expired.
type Options ¶
type Options interface {
String(key string) string
Bool(key string) bool
Duration(key string) time.Duration
}
Options reads resolved flag values.
type Push ¶
type Push struct {
Branch string `json:"branch"`
Commit string `json:"commit,omitempty"`
PullRequest struct {
Number int64 `json:"number"`
URL string `json:"url"`
} `json:"pullRequest"`
}
Push is push.json: what a remediation's archive produced on the forge.
type Record ¶
type Record struct {
// Transcript locates the conversation: an archive object or a ConfigMap.
Transcript *v1alpha1.TranscriptRef
// Archive locates the run's archive, when the upload succeeded.
Archive *v1alpha1.ArchiveRef
// Condition is the Archived condition; nil when archival is off.
Condition *metav1.Condition
// FailDetail is non-empty when a required archive failed: the run must
// fail with OutcomeArchiveFailed and this detail.
FailDetail string
}
Record is what collection decided a run's status should carry.
type Run ¶
type Run struct {
// Kind is investigation or remediation.
Kind v1alpha1.RunKind
// Object is the Investigation or Remediation.
Object client.Object
// Attempt ordinal of the run.
Attempt int32
// Finding the run belongs to; nil when it is already gone.
Finding *v1alpha1.Finding
// BaseSHA is the commit the agent's workspace was pinned to.
BaseSHA string
// FinishedAt is when the agent Job finished; zero when unknown.
FinishedAt time.Time
}
Run identifies the run being archived and what it ran against.