eventstore

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultRetention = 3 * 24 * time.Hour // 3 days

Variables

This section is empty.

Functions

func AggregateSuggestedActions added in v0.6.0

func AggregateSuggestedActions(allActions []*apiv1.SuggestedActions) *apiv1.SuggestedActions

AggregateSuggestedActions combines multiple suggested actions with priority rules. If any action suggests HW_INSPECTION, that takes priority over SYSTEM_REBOOT. This allows components to evaluate multiple failure types and get a single recommendation.

func EvaluateSuggestedActions added in v0.6.0

func EvaluateSuggestedActions(
	rebootEvents Events,
	failureEvents Events,
	maxRebootsBeforeInspection int,
) *apiv1.SuggestedActions

EvaluateSuggestedActions evaluates repair actions based on reboot history and failure events. It returns health state and suggested actions.

The logic follows these rules: - If no failure events: panic (should never happen) - If the first reboot happened after the first failure: return nil (reboot may have fixed the issue) - If no reboots: suggest reboot - If only 1 reboot or 1 failure event: suggest reboot - Otherwise, count "reboot → failure" sequences (failures that occurred after reboots) - If reboot→failure sequences >= maxRebootsBeforeInspection: suggest hardware inspection - Otherwise: suggest reboot

The function analyzes sequences where a failure occurs AFTER a reboot, indicating that the reboot did not resolve the issue.

Parameters:

  • rebootEvents: Historical reboot events
  • failureEvents: Slice of failure events to evaluate (must not be empty, will panic if empty)
  • maxRebootsBeforeInspection: Threshold for reboot→failure sequences before suggesting hardware inspection (typically 2)

Returns:

  • health: Health state (always Unhealthy when failures exist)
  • suggestedActions: Suggested repair actions (REBOOT, HW_INSPECTION, or nil)

Types

type Bucket

type Bucket interface {
	Name() string
	Insert(ctx context.Context, ev Event) error
	// Find returns nil if the event is not found.
	Find(ctx context.Context, ev Event) (*Event, error)
	// Get queries the event in the descending order of timestamp (latest event first).
	Get(ctx context.Context, since time.Time) (Events, error)
	// Latest queries the latest event, returns nil if no event found.
	Latest(ctx context.Context) (*Event, error)
	Purge(ctx context.Context, beforeTimestamp int64) (int, error)
	Close()
}

type Event added in v0.5.0

type Event struct {
	// Component represents which component generated the event.
	Component string

	// Time represents when the event happened
	Time time.Time

	// Name represents the name of the event.
	Name string

	// Type represents the type of the event.
	Type string

	// Message represents the detailed message of the event.
	Message string

	// ExtraInfo represents the extra information of the event.
	ExtraInfo map[string]string
}

Event represents an entry in the event store.

func (*Event) ToEvent added in v0.5.0

func (e *Event) ToEvent() apiv1.Event

type Events added in v0.5.0

type Events []Event

func (Events) Events added in v0.5.0

func (evs Events) Events() apiv1.Events

type Op added in v0.5.0

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

type OpOption added in v0.5.0

type OpOption func(*Op)

func WithDisablePurge added in v0.5.0

func WithDisablePurge() OpOption

WithDisablePurge specifies that the purge should be disabled. This is useful for loading the bucket for read-only operations.

type Store

type Store interface {
	Bucket(name string, opts ...OpOption) (Bucket, error)
}

func New

func New(dbRW *sql.DB, dbRO *sql.DB, retention time.Duration) (Store, error)

Jump to

Keyboard shortcuts

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