diagnose

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package diagnose runs an end-to-end sanity check across every Fleetsweeper integration. The intent is operator-grade: before wiring Fleetsweeper into a production pipeline, run `fleetsweeper diagnose` and see at a glance which integrations are wired up, which are off, and which are broken.

Each check produces a Result with one of four statuses:

  • StatusOK: the integration is configured and the local check passes
  • StatusOff: the integration is intentionally not configured
  • StatusWarn: the integration is configured but a soft check failed
  • StatusFail: the integration is configured and a hard check failed

"Local check" is deliberately conservative. We do not call external APIs by default because that would conflate "configured" with "reachable" and make `diagnose` itself a flaky network test. Pass --probe to opt into active probing (Slack ping, GitHub API call, kubeconfig connect).

Index

Constants

This section is empty.

Variables

View Source
var ErrFailures = errors.New("diagnose: one or more checks failed")

ErrFailures is returned by Run wrappers that want to translate the report's failure count into an error suitable for a CLI exit code.

Functions

func FormatText

func FormatText(report Report, isatty bool) string

FormatText renders the report as a human-readable text table suitable for the terminal. Status column uses ANSI when isatty is true.

Types

type Options

type Options struct {
	// KubeconfigPath, when set, is checked for valid contexts.
	KubeconfigPath string
	// DBPath, when set, is opened and queried.
	DBPath string
	// SlackWebhookURL, when set, is checked for syntactic validity. When
	// Probe is true the webhook is also pinged with a test payload.
	SlackWebhookURL string
	// CostCSVPath, when set, is parsed.
	CostCSVPath string
	// PolicyReportOutputDir, when set, is exercised by writing a tiny
	// synthetic report into a tmp subdirectory.
	PolicyReportOutputDir string
	// FleetDriftOutputDir, when set, gets the same treatment.
	FleetDriftOutputDir string
	// GitHubToken, when set, is checked for format. When Probe is true the
	// token is validated by calling /user on the GitHub API.
	GitHubToken string
	// Probe enables active external-call checks (Slack ping, GitHub API).
	// Off by default so diagnose is deterministic and offline-safe.
	Probe bool
	// HTTPClient is used for active probes when Probe is true. Tests can
	// inject a httptest server here.
	HTTPClient *http.Client
}

Options bundles the configuration the diagnose command needs.

type Report

type Report struct {
	// Results is one entry per check, in execution order.
	Results []Result `json:"results"`
}

Report is the full diagnose output.

func Run

func Run(ctx context.Context, opts Options) Report

Run executes every diagnostic and returns the consolidated report. Each check is allowed to fail independently; one failure does not short-circuit the rest.

func (Report) HasFailures

func (r Report) HasFailures() bool

HasFailures reports whether any result is StatusFail.

func (Report) Summary

func (r Report) Summary() map[Status]int

Summary returns counts by status for the report.

type Result

type Result struct {
	// Name is the integration label.
	Name string `json:"name"`
	// Status is the outcome.
	Status Status `json:"status"`
	// Message is a one-line description of what we found.
	Message string `json:"message"`
	// Hint, when present, suggests an action the operator can take.
	Hint string `json:"hint,omitempty"`
	// Duration is how long the check took.
	Duration time.Duration `json:"duration_ns"`
}

Result is one row in the diagnose report.

type Status

type Status string

Status is the four-state outcome of a single diagnostic.

const (
	// StatusOK means the integration is configured and the check passed.
	StatusOK Status = "ok"
	// StatusOff means the integration is intentionally not configured.
	StatusOff Status = "off"
	// StatusWarn means the integration is configured but a soft check failed.
	StatusWarn Status = "warn"
	// StatusFail means the integration is configured and a hard check failed.
	StatusFail Status = "fail"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL