archive

package
v0.0.0-...-4540375 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: AGPL-3.0 Imports: 18 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

Overview

Package archive writes the results a compaction is about to delete as Vortex files in the file storage (spec 2026-11-25-01). The raw rows of an hour go to <orgUID>/archives/<checkUID>/<YYYY-MM-DD>/<HH>.vortex. When the day is compacted, all the raw rows of the day (the union of its hour files) go to <orgUID>/archives/<checkUID>/<YYYY-MM-DD>.vortex (UTC) and the hour files are deleted. An archive only ever holds raw results, never a rollup: an hour compacted before archiving was on is simply absent. The files are also read back by the Reader (spec 2026-11-28-02): the result detail and the raw result list of a window older than the raw retention are served from them, server side. External tools (DuckDB, Spark) read them too.

Index

Constants

View Source
const (
	// MaxWindow is the longest window a raw list reads from the archive.
	MaxWindow = 31 * 24 * time.Hour
	// MaxResults is the most results a raw list reads from the archive.
	MaxResults = 10000
)
View Source
const Extension = ".vortex"

Extension is the suffix of every archive file.

View Source
const MimeType = "application/vnd.apache.vortex"

MimeType is the media type of an archive file.

Variables

This section is empty.

Functions

func DayFileID

func DayFileID(checkUID string, start time.Time) string

DayFileID is the fileID of the long-term archive of one day, every raw row of the day: <checkUID>/<YYYY-MM-DD>.vortex, in UTC.

func DeleteOrganization

func DeleteOrganization(ctx context.Context, storage filestorage.FileStorage, orgUIDText string) (int, error)

DeleteOrganization removes every archive of an organization from storage. The archives have no `files` row, so the reap of the org's files does not see them: they go by prefix.

func DeleteOrganizationArchives

func DeleteOrganizationArchives(ctx context.Context, cfg *config.Config, orgUID string) (int, error)

DeleteOrganizationArchives removes every archive of an organization from the configured file storage. It runs whatever archive.enabled says: archives written while it was on must still go when the org is deleted (GDPR).

func Encode

func Encode(rows []Row) ([]byte, error)

Encode writes rows as a Vortex file, sorted by period_start then uid, with the compression meant for long storage.

func FileID

func FileID(checkUID, targetPeriod string, start time.Time) (string, bool)

FileID returns the fileID of the archive written when a bucket is compacted into targetPeriod, and false for a tier that is not archived (month: the day rows it compacts are tiny and the month rows stay in the database).

func HourDirPrefix

func HourDirPrefix(checkUID string, day time.Time) string

HourDirPrefix is the DeletePrefix prefix of the hour files of one day: <checkUID>/<YYYY-MM-DD>/, in UTC.

func HourFileID

func HourFileID(checkUID string, start time.Time) string

HourFileID is the fileID of the archive of the raw rows of one hour: <checkUID>/<YYYY-MM-DD>/<HH>.vortex, in UTC.

func SortRows

func SortRows(rows []Row)

SortRows orders rows by period_start, then uid for a stable file.

func StorageConfig

func StorageConfig(cfg *config.FileStorageConfig) *filestorage.Config

StorageConfig maps the file storage configuration to the backend factory's.

Types

type Archiver

type Archiver interface {
	// Archive stores rows, the measurable source rows of the bucket of check
	// checkUID starting at start that is compacted into targetPeriod. For an
	// hour they are the raw results archived; for a day they are hour rollups,
	// which are never archived: the day step merges the day's hour files. A
	// tier that is not archived (month) or an empty rows is a no-op.
	Archive(ctx context.Context, orgUID, checkUID, targetPeriod string, start time.Time,
		rows []*models.Result) error
}

Archiver archives the rows a compaction deletes. Archive must return an error whenever the rows are not durably stored: the caller then keeps them.

func FromConfig

func FromConfig(cfg *config.Config) (Archiver, error)

FromConfig returns the Archiver of the configuration: nil when archive.enabled is false, else one over the configured file storage.

type Reader

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

Reader reads archived results back from the file storage (spec 2026-11-28-02). It is nil, never a disabled instance, when archive.enabled is false: every caller treats nil as "no archive".

func NewReader

func NewReader(storage filestorage.FileStorage) *Reader

NewReader returns a Reader over storage.

func ReaderFromConfig

func ReaderFromConfig(cfg *config.Config) (*Reader, error)

ReaderFromConfig returns the Reader of the configuration: nil when archive.enabled is false.

func (*Reader) Find

func (r *Reader) Find(ctx context.Context, orgUID, checkUID, uid string) (*Row, []Row, error)

Find returns the row of the check with the given uid, or nil, plus every row of the files read to find it (the day file and the hour file the uid's timestamp points to), sorted like Rows, so the caller can pick neighbors. A uid that is not a UUIDv7 is not found.

func (*Reader) Row

func (r *Reader) Row(ctx context.Context, orgUID, checkUID, uid string) (*Row, error)

Row returns the row of the check with the given uid, nil when not archived.

func (*Reader) Rows

func (r *Reader) Rows(ctx context.Context, orgUID, checkUID string, from, until time.Time) ([]Row, error)

Rows returns the archived rows of check checkUID in [from, until), merged by uid and sorted by period_start then uid. For each UTC day the window touches it reads the day file and the hour files of the hours inside the window. A missing file is no rows, not an error.

type Row

type Row struct {
	UID         string            `vortex:"uid"`
	CheckUID    string            `vortex:"check_uid"`
	Region      sql.Null[string]  `vortex:"region"`
	PeriodType  string            `vortex:"period_type"`
	PeriodStart time.Time         `vortex:"period_start"`
	WorkerUID   sql.Null[string]  `vortex:"worker_uid"`
	Status      sql.Null[int64]   `vortex:"status"`
	Duration    sql.Null[float32] `vortex:"duration"`
	Metrics     sql.Null[string]  `vortex:"metrics"`
	Output      sql.Null[string]  `vortex:"output"`
	Maintenance bool              `vortex:"maintenance"`
	CreatedAt   time.Time         `vortex:"created_at"`
}

Row is the schema of an archive file: one row per raw result, the columns of models.Result that a raw result fills (the rollup counters and duration stats, the scan-only check info and the transient diagnostics are left out). An archive only ever holds raw results: period_type is always "raw", kept so a merge can drop the summary rows of a day file written by v0.55/v0.56. Nullable columns are sql.Null, the JSON columns are UTF-8 strings. The tags are the column names external tools see. Decoding reads only these columns, so a file written with the older, wider schema still decodes.

func Decode

func Decode(ctx context.Context, data []byte) ([]Row, error)

Decode reads every row of a Vortex archive file.

func Merge

func Merge(existing, incoming []Row) []Row

Merge returns the raw rows of existing and incoming, deduplicated by uid: a row of incoming replaces the row of existing with the same uid. Any other row (the hour summaries of a day file written by v0.55/v0.56) is dropped, so an archive never holds a summary. The result is sorted like Encode sorts.

func RowFromResult

func RowFromResult(res *models.Result) (Row, error)

RowFromResult converts a raw result to its archive row.

func (*Row) Result

func (row *Row) Result(orgUID string) (*models.Result, error)

Result converts an archive row back to a raw models.Result of the organization: the inverse of RowFromResult. The rollup counters, the scan-only check info and the transient diagnostics are not archived.

type StorageArchiver

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

StorageArchiver is the Archiver over a filestorage.FileStorage.

func New

New returns an Archiver writing to storage.

func (*StorageArchiver) Archive

func (a *StorageArchiver) Archive(
	ctx context.Context, orgUIDText, checkUID, targetPeriod string, start time.Time, rows []*models.Result,
) error

Archive stores the rows a compaction is about to delete. For an hour compaction it merges the raw rows into the hour file. For a day compaction it merges the day's hour files into the day file, then deletes them; the hour rollups being compacted are not archived. Any storage error is returned: the caller then keeps the rows in the database and retries later.

Jump to

Keyboard shortcuts

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