github.com/rotari-dev/rotari/internal/diagnose

Overview

package diagnose // import "github.com/rotari-dev/rotari/internal/diagnose"

Package diagnose provides rule-based job failure diagnosis.

It matches logs and job state against local diagnosis rules. It should return
diagnosis data to callers without owning run orchestration, persistence layout,
or user-facing command formatting.

Constants

const (
	// NoMatchNext follows a failure that no rule matched.
	NoMatchNext = "Inspect the full job output and scheduler accounting for the failure details."
	// UnavailableNext follows a diagnosis that could not read the output.
	UnavailableNext = "Resolve the read error, then inspect the full job output."
	// OutdatedNote marks a diagnosis saved under earlier rules; see Outdated.
	OutdatedNote = "Saved with earlier diagnosis rules; --filter-diagnosis selects by the current rules."
)
    Guidance shown with a saved rule diagnosis by show and reports.

Functions

func AnalyzeResult(result model.JobResult, log string, readErr error) model.JobResult
    AnalyzeResult saves the default rule-based analysis on a failed result.
    A successful result, or one that already carries an analysis such as a
    result carried from an earlier run, is returned unchanged. A non-nil readErr
    means the job output could not be read, so the analysis is unavailable.

func Diagnose(errorText, log string, rules []Rule) []model.RuleDiagnosis
    Diagnose returns one diagnosis per matching rule, citing the rule's latest
    matching line. Diagnoses are ordered from the latest evidence to the
    earliest, because the error that ended a job is normally reported last and
    earlier matches may be warnings the job recovered from. The scheduler error
    is recorded after the job output, so it ranks as the latest evidence.

func DiagnoseDefault(job Job) []model.RuleDiagnosis
func DiagnoseExitCode(exitCode int, rules []Rule) []model.RuleDiagnosis
    DiagnoseExitCode returns the diagnosis of a job whose error and log nothing
    recognized but whose exit code has a conventional meaning: 127 for a missing
    command, and 128+N for a job that passed on a child's death by signal N.

func LastOutputLine(log string) string
    LastOutputLine returns the last nonblank line of log, without ANSI escapes,
    surrounding whitespace, or text a carriage return overwrote. It skips the
    lines TailLog and the stream headers add, which are not output.

func MatchesAny(value string, patterns []*regexp.Regexp) bool
func MatchesResultSelectors(selectors []string, result model.JobResult, log string) bool
    MatchesResultSelectors reports whether a failed result, diagnosed with the
    current rules from its error and log, matches any selector. Saved diagnoses
    are ignored, and a success never matches.

func MatchesRuleSelectors(selectors []string, job Job) bool
    MatchesRuleSelectors recomputes diagnosis using the current default rules
    and reports whether any diagnosis matches a requested selector.

func Outdated(result model.JobResult) bool
    Outdated reports whether a saved matched or no-match analysis was produced
    by rules other than the current ones. An unavailable analysis never ran the
    rules, and an unanalyzed result has nothing to refresh.

func ResolveRuleSelectors(values []string) error
    ResolveRuleSelectors validates diagnosis filter values. A slug ID is
    preferred; otherwise the display name is matched case-insensitively as a
    substring.

func RuleID(rule Rule) string
    RuleID returns a stable selector ID derived from the public rule name;
    see model.FailureCauseID.

func RulesVersion() string
    RulesVersion identifies the default rules and matcher. It is derived from
    the rule definitions, so any rule change produces a new version.

func TailLog(value string, limit int) string

Types

type Job struct {
	JobID    string
	ExitCode *int
	Error    string
	Log      string
}

type Rule struct {
	Name     string
	Patterns []*regexp.Regexp
	Excludes []*regexp.Regexp
	// ExitCodes are the exit codes that mean this rule's failure when nothing
	// in the error or log is recognized; see DiagnoseExitCode.
	ExitCodes  []int
	Suggestion string
	// Kinds are the failure kinds (model.FailureKindValues) the failure this
	// rule recognizes implies; its diagnoses carry them.
	Kinds []string
}

func DefaultRules() []Rule