observability

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package observability records handler events, audits and basic runtime metrics.

Index

Constants

View Source
const (
	DefaultAuditQueueSize = 256
	DefaultAuditTimeout   = 2 * time.Second
)

Variables

View Source
var (
	ErrAuditDropped = errors.New("audit event dropped")
	ErrInvalidAudit = errors.New("invalid audit event")
)

Functions

func AppendAudit

func AppendAudit(audits AuditLogStore, actor, action, target string, metadata map[string]any)

func Middleware

func Middleware(eventLogs EventLogStore, metrics MetricsStore) middleware.Middleware

Types

type AuditDispatcher added in v2.0.1

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

AuditDispatcher keeps audit persistence outside mutation and Control paths. Its queue and store calls are bounded; audit remains non-authoritative.

func NewAuditDispatcher added in v2.0.1

func NewAuditDispatcher(store AuditLogStore, queueSize int, timeout time.Duration) (*AuditDispatcher, error)

func (*AuditDispatcher) Append added in v2.0.1

func (d *AuditDispatcher) Append(entry AuditLogEntry) error

func (*AuditDispatcher) Close added in v2.0.1

func (d *AuditDispatcher) Close(ctx context.Context) error

func (*AuditDispatcher) Stats added in v2.0.1

type AuditDispatcherStats added in v2.0.1

type AuditDispatcherStats struct {
	Dropped  uint64
	Failed   uint64
	Rejected uint64
}

type AuditLogEntry

type AuditLogEntry struct {
	Actor     string         `json:"actor"`
	Action    string         `json:"action"`
	Target    string         `json:"target"`
	Metadata  map[string]any `json:"metadata,omitempty"`
	CreatedAt time.Time      `json:"created_at"`
}

type AuditLogQuery

type AuditLogQuery struct {
	Limit  int
	Offset int
	Actor  string
	Action string
	Target string
}

type AuditLogStore

type AuditLogStore interface {
	AppendAudit(ctx context.Context, entry AuditLogEntry) error
	ListAudit(ctx context.Context, query AuditLogQuery) ([]AuditLogEntry, error)
}

type EventLogEntry

type EventLogEntry struct {
	ID         string    `json:"id"`
	Platform   string    `json:"platform"`
	Type       string    `json:"type"`
	ChatID     string    `json:"chat_id"`
	UserID     string    `json:"user_id"`
	Text       string    `json:"text,omitempty"`
	Command    string    `json:"command,omitempty"`
	Payload    string    `json:"payload,omitempty"`
	Error      string    `json:"error,omitempty"`
	DurationMS int64     `json:"duration_ms"`
	CreatedAt  time.Time `json:"created_at"`
}

type EventLogQuery

type EventLogQuery struct {
	Limit    int
	Offset   int
	Platform string
	Type     string
	UserID   string
	ChatID   string
	HasError *bool
}

type EventLogStore

type EventLogStore interface {
	AppendEvent(ctx context.Context, entry EventLogEntry) error
	ListEvents(ctx context.Context, query EventLogQuery) ([]EventLogEntry, error)
}

type InMemory

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

func NewInMemory

func NewInMemory(capacity int) *InMemory

func (*InMemory) AppendAudit

func (m *InMemory) AppendAudit(ctx context.Context, entry AuditLogEntry) error

func (*InMemory) AppendEvent

func (m *InMemory) AppendEvent(ctx context.Context, entry EventLogEntry) error

func (*InMemory) ListAudit

func (m *InMemory) ListAudit(ctx context.Context, query AuditLogQuery) ([]AuditLogEntry, error)

func (*InMemory) ListEvents

func (m *InMemory) ListEvents(ctx context.Context, query EventLogQuery) ([]EventLogEntry, error)

func (*InMemory) Observe

func (m *InMemory) Observe(duration time.Duration, hasError bool, at time.Time)

func (*InMemory) Snapshot

func (m *InMemory) Snapshot(ctx context.Context) (MetricsSnapshot, error)

type MetricsSnapshot

type MetricsSnapshot struct {
	EventsTotal      int64     `json:"events_total"`
	ErrorsTotal      int64     `json:"errors_total"`
	AverageLatencyMS int64     `json:"average_latency_ms"`
	LastEventAt      time.Time `json:"last_event_at"`
}

type MetricsStore

type MetricsStore interface {
	Observe(duration time.Duration, hasError bool, at time.Time)
	Snapshot(ctx context.Context) (MetricsSnapshot, error)
}

type Postgres

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

func NewPostgres

func NewPostgres(pool *pgxpool.Pool) *Postgres

func (*Postgres) AppendAudit

func (p *Postgres) AppendAudit(ctx context.Context, entry AuditLogEntry) error

func (*Postgres) AppendEvent

func (p *Postgres) AppendEvent(ctx context.Context, entry EventLogEntry) error

func (*Postgres) EnsureSchema

func (p *Postgres) EnsureSchema(ctx context.Context) error

func (*Postgres) ListAudit

func (p *Postgres) ListAudit(ctx context.Context, query AuditLogQuery) ([]AuditLogEntry, error)

func (*Postgres) ListEvents

func (p *Postgres) ListEvents(ctx context.Context, query EventLogQuery) ([]EventLogEntry, error)

func (*Postgres) Observe

func (p *Postgres) Observe(duration time.Duration, hasError bool, at time.Time)

func (*Postgres) Snapshot

func (p *Postgres) Snapshot(ctx context.Context) (MetricsSnapshot, error)

Jump to

Keyboard shortcuts

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