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
- func DayFileID(checkUID string, start time.Time) string
- func DeleteOrganization(ctx context.Context, storage filestorage.FileStorage, orgUIDText string) (int, error)
- func DeleteOrganizationArchives(ctx context.Context, cfg *config.Config, orgUID string) (int, error)
- func Encode(rows []Row) ([]byte, error)
- func FileID(checkUID, targetPeriod string, start time.Time) (string, bool)
- func HourDirPrefix(checkUID string, day time.Time) string
- func HourFileID(checkUID string, start time.Time) string
- func SortRows(rows []Row)
- func StorageConfig(cfg *config.FileStorageConfig) *filestorage.Config
- type Archiver
- type Reader
- type Row
- type StorageArchiver
Constants ¶
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 )
const Extension = ".vortex"
Extension is the suffix of every archive file.
const MimeType = "application/vnd.apache.vortex"
MimeType is the media type of an archive file.
Variables ¶
This section is empty.
Functions ¶
func DayFileID ¶
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 ¶
Encode writes rows as a Vortex file, sorted by period_start then uid, with the compression meant for long storage.
func FileID ¶
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 ¶
HourDirPrefix is the DeletePrefix prefix of the hour files of one day: <checkUID>/<YYYY-MM-DD>/, in UTC.
func HourFileID ¶
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.
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 ¶
ReaderFromConfig returns the Reader of the configuration: nil when archive.enabled is false.
func (*Reader) Find ¶
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) 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 Merge ¶
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 ¶
RowFromResult converts a raw result to its archive row.
type StorageArchiver ¶
type StorageArchiver struct {
// contains filtered or unexported fields
}
StorageArchiver is the Archiver over a filestorage.FileStorage.
func New ¶
func New(storage filestorage.FileStorage) *StorageArchiver
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.