disk

package
v1.2.9 Latest Latest
Warning

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

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

Documentation

Overview

Package disk implements the secondary adapter for persistent storage in hexagonal architecture. This package provides high-performance disk-based storage with Brotli compression and JSON streaming for the CloudZero Agent's metric collection and processing pipeline.

Package disk provides storage functionality.

Index

Constants

View Source
const (
	// CostContentIdentifier marks metrics as cost-related for CloudZero billing analysis.
	CostContentIdentifier = "metrics"

	// ObservabilityContentIdentifier marks metrics as observability-focused rather than cost-related.
	ObservabilityContentIdentifier = "observability"

	// LogsContentIdentifider marks log data for separate processing and storage.
	LogsContentIdentifider = "logs"
)

Content type identifiers for metric classification and storage routing. These constants determine the storage path and processing logic for different metric categories.

Variables

This section is empty.

Functions

func NewParquetStreamer

func NewParquetStreamer(input io.Reader) io.ReadCloser

NewParquetStreamer reads a Brotli-compressed JSON file containing an array of Metrics, and returns a reader with the data transcoded to Snappy-compressed Parquet.

Types

type DiskStore

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

DiskStore is a data store intended to be backed by a disk. Currently, data is stored in Brotli-compressed JSON, but transcoded to Snappy-compressed Parquet

func NewDiskStore

func NewDiskStore(settings config.Database, opts ...DiskStoreOpt) (*DiskStore, error)

NewDiskStore initializes a DiskStore with a directory path and row limit

func (*DiskStore) All

func (d *DiskStore) All(ctx context.Context, file string) (types.MetricRange, error)

All retrieves all metrics from uncompacted .json.br files, excluding the active and compressed files. It reads the data into memory and returns a MetricRange.

func (*DiskStore) Find added in v1.2.0

func (d *DiskStore) Find(ctx context.Context, filterName string, filterExtension string) ([]string, error)

Find searches for files recursively starting from a given directory with optional filename and extension filters.

func (*DiskStore) Flush

func (d *DiskStore) Flush() error

Flush finalizes the current writer, writes all buffered data to disk, and renames the file

func (*DiskStore) GetFiles

func (d *DiskStore) GetFiles(paths ...string) ([]string, error)

func (*DiskStore) GetUsage

func (d *DiskStore) GetUsage(limit uint64, paths ...string) (*types.StoreUsage, error)

GetUsage gathers disk usage stats using syscall.Statfs. paths will be used as `filepath.Join(paths...)`

func (*DiskStore) ListFiles

func (d *DiskStore) ListFiles(paths ...string) ([]os.DirEntry, error)

func (*DiskStore) MaxInterval

func (d *DiskStore) MaxInterval() time.Duration

func (*DiskStore) Pending

func (d *DiskStore) Pending() int

Pending returns the count of buffered rows not yet written to disk

func (*DiskStore) Put

func (d *DiskStore) Put(ctx context.Context, metrics ...types.Metric) error

Put appends metrics to the JSON file, creating a new file if the row limit is reached

func (*DiskStore) Walk

func (d *DiskStore) Walk(loc string, process filepath.WalkFunc) error

Walk will run `process` to walk the file tree

type DiskStoreOpt

type DiskStoreOpt = func(d *DiskStore) error

func WithContentIdentifier

func WithContentIdentifier(identifier string) DiskStoreOpt

func WithMaxInterval

func WithMaxInterval(interval time.Duration) DiskStoreOpt

type MetricFile

type MetricFile struct {
	*os.File // wrapper around an os.File
	// contains filtered or unexported fields
}

func NewMetricFile

func NewMetricFile(path string) (*MetricFile, error)

func (*MetricFile) Close

func (f *MetricFile) Close() error

func (*MetricFile) Location

func (f *MetricFile) Location() string

func (*MetricFile) Read

func (f *MetricFile) Read(p []byte) (int, error)

func (*MetricFile) Rename

func (f *MetricFile) Rename(new string) error

func (*MetricFile) Size

func (f *MetricFile) Size() (int64, error)

Size returns the size of the file.

func (*MetricFile) UniqueID

func (f *MetricFile) UniqueID() string

Jump to

Keyboard shortcuts

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