store

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	KindNotLogged   = "not-logged"  // a hit could not be written to the database
	KindBackground  = "background"  // a guard left a process holding its output
	KindCapture     = "capture"     // reading guard output failed
	KindTruncated   = "truncated"   // stored output was cut at CaptureCap
	KindPassthrough = "passthrough" // forwarding guard output failed
	KindCanary      = "canary"      // canary lookup failed
	KindPanic       = "panic"       // blotter recovered from an internal failure
	KindOther       = "other"       // lines written before kinds existed
)

Diagnostic kinds let doctor summarize past runtime events.

View Source
const CaptureCap = 64 << 10
View Source
const DiagnosticLogLimit = 1 << 20

DiagnosticLogLimit is the size at which errors.log rotates to errors.log.1.

View Source
const SchemaVersion = 1

Variables

View Source
var Outcomes = []string{"block", "error", "ask", "pass", "canary"}

Outcomes are the recorded results of a guard run.

Functions

func DBPath

func DBPath(override string) string

func DataDir

func DataDir() string

func Diagnostic

func Diagnostic(kind, guard string, err error)

Diagnostic appends "<ts> <kind> <guard|-> <message>" to errors.log.

func DiagnosticLogs added in v0.2.0

func DiagnosticLogs() []string

func Hash

func Hash(text string) string

func Since

func Since(value string, now time.Time) (string, error)

func StateDir

func StateDir() string

func Timestamp

func Timestamp(t time.Time) string

func ValidOutcome

func ValidOutcome(s string) bool

Types

type Canary

type Canary struct {
	Token   string `json:"token"`
	Created string `json:"created"`
}

type DiagnosticEntry added in v0.2.0

type DiagnosticEntry struct{ TS, Kind, Guard, Message string }

func ParseDiagnostic added in v0.2.0

func ParseDiagnostic(line string) (DiagnosticEntry, bool)

ParseDiagnostic reads one errors.log line. Lines without a known kind are reported whole as KindOther.

type Filter

type Filter struct {
	Guard, Project, Harness, Since string
	Outcomes                       []string
	Limit                          int
}

type Hit

type Hit struct {
	ID         int64  `json:"id"`
	TS         string `json:"ts"`
	Guard      string `json:"guard"`
	Harness    string `json:"harness"`
	Outcome    string `json:"outcome"`
	RC         int    `json:"rc"`
	Stdout     string `json:"stdout"`
	Stderr     string `json:"stderr"`
	Truncated  bool   `json:"truncated"`
	DurationMS int64  `json:"duration_ms"`
	Project    string `json:"project"`
	CWD        string `json:"cwd"`
	Session    string `json:"session"`
	Tool       string `json:"tool"`
	Payload    string `json:"payload"`
	Event      string `json:"event"`
	Version    string `json:"blotter_version"`
}

func FromEvent

func FromEvent(raw []byte) Hit

func (Hit) MarshalJSON added in v0.3.0

func (h Hit) MarshalJSON() ([]byte, error)

MarshalJSON writes the stored event as a JSON object when it is one, null when it is empty (hash recording) and a string otherwise, so harness events read as JSON while arbitrary recorded input is still shown as received.

func (*Hit) Prepare

func (h *Hit) Prepare(privacy string)

type Stat

type Stat struct {
	Guard   string `json:"guard,omitempty"`
	Day     string `json:"day,omitempty"`
	Block   int    `json:"block"`
	Error   int    `json:"error"`
	Ask     int    `json:"ask"`
	Pass    int    `json:"pass"`
	Canary  int    `json:"canary"`
	LastHit string `json:"last_hit"`
}

type Store

type Store struct{ DB *sql.DB }

func Open

func Open(ctx context.Context, path string) (*Store, error)

func (*Store) CanaryHits

func (s *Store) CanaryHits(ctx context.Context, token string) ([]Hit, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) Guards added in v0.4.0

func (s *Store) Guards(ctx context.Context) ([]string, error)

Guards lists the guard names that have recorded hits.

func (*Store) Insert

func (s *Store) Insert(ctx context.Context, h Hit) error

func (*Store) KnownCanary

func (s *Store) KnownCanary(ctx context.Context, token string) (bool, error)

func (*Store) LatestCanary

func (s *Store) LatestCanary(ctx context.Context) (c Canary, err error)

func (*Store) List

func (s *Store) List(ctx context.Context, f Filter) ([]Hit, error)

func (*Store) NewCanary

func (s *Store) NewCanary(ctx context.Context, token string) error

func (*Store) Show

func (s *Store) Show(ctx context.Context, id int64) (Hit, error)

func (*Store) Stats

func (s *Store) Stats(ctx context.Context, f Filter, by string) ([]Stat, error)

Jump to

Keyboard shortcuts

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