workspace

package
v0.0.0-...-332dcef Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const DiscoveryRunsDirName = "discovery-runs"
View Source
const ImportRunsDirName = "import-runs"

Variables

This section is empty.

Functions

func DiscoveryRunDir

func DiscoveryRunDir(workspaceDir, runID string) string

func DiscoveryRunRecordPath

func DiscoveryRunRecordPath(workspaceDir, runID string) string

func DiscoveryRunsDir

func DiscoveryRunsDir(workspaceDir string) string

func ImportRunDir

func ImportRunDir(workspaceDir, runID string) string

func ImportRunRecordPath

func ImportRunRecordPath(workspaceDir, runID string) string

func ImportRunsDir

func ImportRunsDir(workspaceDir string) string

func ListLogFiles

func ListLogFiles(dir string) ([]string, error)

ListLogFiles returns the basenames of all files in <dir>/logs/.

func ReadAllLogs

func ReadAllLogs(dir string) (map[string][]string, error)

ReadAllLogs reads all log files in <dir>/logs/ and returns a map of filename to lines.

func WriteDiscoveryRunRecord

func WriteDiscoveryRunRecord(workspaceDir string, record DiscoveryRunRecord) error

func WriteImportRunRecord

func WriteImportRunRecord(workspaceDir string, record ImportRunRecord) error

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder creates the structured workspace directory from pre-processed data.

func NewBuilder

func NewBuilder(dir string, taggedLines []TaggedLine, templates []pattern.DrainCluster, labels []semantic.SemanticLabel) *Builder

NewBuilder creates a Builder with pre-processed data.

func (*Builder) BuildAll

func (b *Builder) BuildAll() error

BuildAll orchestrates writing all workspace files.

func (*Builder) LogFiles

func (b *Builder) LogFiles() []string

LogFiles returns source log filenames included in this build.

func (*Builder) Patterns

func (b *Builder) Patterns() []PatternInfo

Patterns returns the pattern results computed during BuildAll.

func (*Builder) Unmatched

func (b *Builder) Unmatched() []TaggedLine

Unmatched returns log lines that did not match any generated pattern.

type DiscoveryConfig

type DiscoveryConfig struct {
	Dir              string
	RunID            string
	APIKey           string
	Model            string
	LabelConcurrency int
	LabelMaxAttempts int
	Labeler          PatternLabeler
}

type DiscoveryLabelBatchProgress

type DiscoveryLabelBatchProgress struct {
	Event          string `json:"event,omitempty"`
	BatchNumber    int    `json:"batch_number"`
	BatchCount     int    `json:"batch_count"`
	BatchSize      int    `json:"batch_size"`
	Attempt        int    `json:"attempt"`
	MaxAttempts    int    `json:"max_attempts"`
	CompletedCount int    `json:"completed_count"`
}

type DiscoveryResult

type DiscoveryResult struct {
	FileCount      int
	LineCount      int
	PatternCount   int
	UnmatchedCount int
	RunID          string
}

DiscoveryResult summarizes a completed discovery run.

func Discover

func Discover(ctx context.Context, config DiscoveryConfig) (DiscoveryResult, error)

Discover starts a DiscoveryRun and writes generated results under discovery-runs/<run-id>/.

type DiscoveryRunError

type DiscoveryRunError struct {
	Code    string        `json:"code"`
	Message string        `json:"message"`
	Step    DiscoveryStep `json:"step,omitempty"`
}

type DiscoveryRunProgress

type DiscoveryRunProgress struct {
	Step       DiscoveryStep                `json:"step,omitempty"`
	LabelBatch *DiscoveryLabelBatchProgress `json:"label_batch,omitempty"`
}

type DiscoveryRunRecord

type DiscoveryRunRecord struct {
	ID              string                `json:"id"`
	State           DiscoveryRunState     `json:"state"`
	CurrentStep     DiscoveryStep         `json:"current_step,omitempty"`
	ProgressMessage string                `json:"progress_message,omitempty"`
	ErrorMessage    string                `json:"error_message,omitempty"`
	Progress        *DiscoveryRunProgress `json:"progress,omitempty"`
	Error           *DiscoveryRunError    `json:"error,omitempty"`
	StartedAt       time.Time             `json:"started_at"`
	FinishedAt      *time.Time            `json:"finished_at,omitempty"`
	LogFileCount    int                   `json:"log_file_count"`
	LineCount       int                   `json:"line_count"`
	PatternCount    int                   `json:"pattern_count"`
	UnmatchedCount  int                   `json:"unmatched_count"`
	Patterns        []PatternInfo         `json:"patterns,omitempty"`
	Unmatched       []TaggedLine          `json:"unmatched,omitempty"`
}

func LatestDiscoveryRun

func LatestDiscoveryRun(records []DiscoveryRunRecord) *DiscoveryRunRecord

func LatestSuccessfulDiscoveryRun

func LatestSuccessfulDiscoveryRun(records []DiscoveryRunRecord) *DiscoveryRunRecord

func ListDiscoveryRunRecords

func ListDiscoveryRunRecords(workspaceDir string) ([]DiscoveryRunRecord, error)

func ReadDiscoveryRunRecord

func ReadDiscoveryRunRecord(workspaceDir, runID string) (DiscoveryRunRecord, error)

type DiscoveryRunState

type DiscoveryRunState string
const (
	DiscoveryRunStateQueued    DiscoveryRunState = "QUEUED"
	DiscoveryRunStateRunning   DiscoveryRunState = "RUNNING"
	DiscoveryRunStateSucceeded DiscoveryRunState = "SUCCEEDED"
	DiscoveryRunStateFailed    DiscoveryRunState = "FAILED"
)

type DiscoveryStep

type DiscoveryStep string
const (
	DiscoveryStepReadingLogs         DiscoveryStep = "READING_LOGS"
	DiscoveryStepMergingEntries      DiscoveryStep = "MERGING_ENTRIES"
	DiscoveryStepDiscoveringPatterns DiscoveryStep = "DISCOVERING_PATTERNS"
	DiscoveryStepLabelingPatterns    DiscoveryStep = "LABELING_PATTERNS"
	DiscoveryStepWritingResults      DiscoveryStep = "WRITING_RESULTS"
)

type ImportConfig

type ImportConfig struct {
	Dir      string
	RunID    string
	Provider string
	Project  string
	Filter   string
	From     time.Time
	To       time.Time
	Limit    int
	Fetcher  ImportFetcher
}

type ImportFetchResult

type ImportFetchResult struct {
	Truncated bool
}

ImportFetchResult reports facts about one completed provider fetch.

type ImportFetcher

type ImportFetcher func(
	ctx context.Context,
	req ImportRequest,
	writeLine ImportLineWriter,
) (ImportFetchResult, error)

ImportFetcher pulls matching entries from a provider. It is the narrow seam between run orchestration and provider network access, so tests can inject a fake without touching the network (precedent: DiscoveryConfig.Labeler).

type ImportLineWriter

type ImportLineWriter func(line string) error

ImportLineWriter writes one envelope NDJSON line without a trailing newline.

type ImportRequest

type ImportRequest struct {
	Project string
	Filter  string
	From    time.Time
	To      time.Time
	Limit   int
}

ImportRequest is what the fetcher needs to pull entries from a provider.

type ImportResult

type ImportResult struct {
	RunID       string
	EntryCount  int
	Truncated   bool
	LogFileName string
}

ImportResult summarizes a completed import run.

func RunImport

func RunImport(ctx context.Context, config ImportConfig) (ImportResult, error)

RunImport starts an ImportRun: it records provenance under import-runs/<run-id>/record.json, pulls entries through the fetcher, and lands them as one NDJSON log file. It never starts discovery (ADR 0005). Zero matching entries is a success with no log file written.

type ImportRunError

type ImportRunError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type ImportRunRecord

type ImportRunRecord struct {
	ID          string          `json:"id"`
	Provider    string          `json:"provider"`
	Project     string          `json:"project"`
	Filter      string          `json:"filter,omitempty"`
	From        time.Time       `json:"from"`
	To          time.Time       `json:"to"`
	Limit       int             `json:"limit"`
	State       ImportRunState  `json:"state"`
	EntryCount  int             `json:"entry_count"`
	Truncated   bool            `json:"truncated"`
	LogFileName string          `json:"log_file_name,omitempty"`
	StartedAt   time.Time       `json:"started_at"`
	FinishedAt  *time.Time      `json:"finished_at,omitempty"`
	Error       *ImportRunError `json:"error,omitempty"`
}

ImportRunRecord is the persisted provenance for one provider import. These records are the only store of import history (ADR 0004). Provider metadata such as labels, trace, and resource belongs here, never in the imported log lines.

func ListImportRunRecords

func ListImportRunRecords(workspaceDir string) ([]ImportRunRecord, error)

func ReadImportRunRecord

func ReadImportRunRecord(workspaceDir, runID string) (ImportRunRecord, error)

type ImportRunState

type ImportRunState string
const (
	ImportRunStateQueued    ImportRunState = "QUEUED"
	ImportRunStateRunning   ImportRunState = "RUNNING"
	ImportRunStateSucceeded ImportRunState = "SUCCEEDED"
	ImportRunStateFailed    ImportRunState = "FAILED"
)

type LineRef

type LineRef struct {
	FileName string
	LineNum  int
}

LineRef identifies a line's location in a source file.

type PatternInfo

type PatternInfo struct {
	SemanticID  string
	DirName     string
	Template    string
	Description string
	Count       int
	FirstSeen   LineRef
	LastSeen    LineRef
	LineRefs    []LineRef
	Samples     []string
}

PatternInfo holds all data about a discovered pattern for workspace output.

type PatternLabeler

PatternLabeler assigns stable semantic labels to discovered Drain patterns.

type TaggedLine

type TaggedLine struct {
	Content  string
	FileName string
	LineNum  int
	// ExtractedLine is the text fed to pattern mining for NDJSON entries.
	// Empty for plain text entries, whose Content is mined directly.
	ExtractedLine string `json:",omitempty"`
}

TaggedLine represents a log line with its source file and line number.

func (TaggedLine) DrainLine

func (t TaggedLine) DrainLine() string

DrainLine returns the text used for pattern mining and template matching: the extracted line for NDJSON entries, otherwise the raw content.

Jump to

Keyboard shortcuts

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