postgres

package
v0.0.0-...-3ea344a Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package postgres is the PostgreSQL-backed implementation of storage.Repository

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store is the Postgres-backed Repository implementation.

func New

func New(ctx context.Context, cfg config.StorageConfig, logger *slog.Logger) (*Store, error)

func (*Store) Close

func (s *Store) Close() error

Close releases all pool connections

func (*Store) DB

func (s *Store) DB() *sql.DB

DB returns a *sql.DB backed by the pool for use in tests and utilities only

func (*Store) GetCluster

func (s *Store) GetCluster(ctx context.Context, id string) (model.Cluster, error)

GetCluster returns a cluster by its ID.

func (*Store) LatestAnalysisForCluster

func (s *Store) LatestAnalysisForCluster(ctx context.Context, clusterID string) (*model.Analysis, error)

LatestAnalysisForCluster returns the analysis with the greatest window_end for the given cluster

func (*Store) ListClusters

func (s *Store) ListClusters(ctx context.Context, filter storage.ClusterFilter) ([]model.Cluster, int64, error)

ListClusters returns clusters matching the filter, plus the total row count. Services and Levels filters are applied in Go after scanning because they would require a JSON parser in SQL; both columns are TEXT JSON to keep the schema identical between SQLite and Postgres, the reported total is the pre-filter count for that reason.

func (*Store) ListEventsByCluster

func (s *Store) ListEventsByCluster(ctx context.Context, clusterID string, filter storage.EventFilter) ([]model.LogEvent, error)

ListEventsByCluster returns events for a cluster ordered by ts DESC, default time range: last 1 hour, limit: 200

func (*Store) ListRecentAnalyses

func (s *Store) ListRecentAnalyses(ctx context.Context, limit int) ([]model.Analysis, error)

ListRecentAnalyses returns the most recently created analyses ordered by created_at DESC

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping verifies the connection to Postgres

func (*Store) Pool

func (s *Store) Pool() *pgxpool.Pool

Pool exposes the underlying pgxpool.Pool for cross-package test helpers

func (*Store) PruneStaleClusters

func (s *Store) PruneStaleClusters(ctx context.Context, olderThan time.Time) (int64, error)

PruneStaleClusters deletes clusters whose last_seen is before olderThan, returns the number of rows deleted.

func (*Store) SaveAnalysis

func (s *Store) SaveAnalysis(ctx context.Context, a model.Analysis) error

SaveAnalysis inserts an analysis; the existing row is updated so re-runs for the same window are idempotent.

func (*Store) SaveEvent

func (s *Store) SaveEvent(ctx context.Context, e model.LogEvent, clusterID string) error

SaveEvent inserts a single log event

func (*Store) UpsertCluster

func (s *Store) UpsertCluster(ctx context.Context, c model.Cluster) error

UpsertCluster inserts a new cluster or updates all mutable fields when a row with the same id already exists. Cluster ID (assigned once by the in-memory Drain tree) is the stable key; fingerprint is mutable because Drain generalizes templates as new events match a group.

Jump to

Keyboard shortcuts

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