storage

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregationResult

type AggregationResult struct {
	Function  string            `json:"function"`
	Filters   map[string]string `json:"filters"`
	Value     float64           `json:"value"`
	Count     int               `json:"count"`
	Timestamp time.Time         `json:"timestamp"`
}

AggregationResult represents the result of an aggregation.

type MemoryStorage

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

MemoryStorage provides in-memory storage for metrics.

func (*MemoryStorage) Aggregate

func (ms *MemoryStorage) Aggregate(ctx context.Context, aggregation MetricsAggregation) (*AggregationResult, error)

Aggregate performs aggregation on stored metrics.

func (*MemoryStorage) Backup

func (ms *MemoryStorage) Backup(ctx context.Context) ([]byte, error)

Backup creates a backup of all stored metrics.

func (*MemoryStorage) Clear

func (ms *MemoryStorage) Clear(ctx context.Context) error

Clear clears all stored entries.

func (*MemoryStorage) Count

func (ms *MemoryStorage) Count(ctx context.Context) (int64, error)

Count returns the number of stored entries.

func (*MemoryStorage) Delete

func (ms *MemoryStorage) Delete(ctx context.Context, name string, tags map[string]string) error

Delete deletes a metric entry.

func (*MemoryStorage) Health

func (ms *MemoryStorage) Health(ctx context.Context) error

Health checks the health of the storage system.

func (*MemoryStorage) List

func (ms *MemoryStorage) List(ctx context.Context, filters map[string]string) ([]*MetricEntry, error)

List lists all metric entries.

func (*MemoryStorage) Query

func (ms *MemoryStorage) Query(ctx context.Context, query MetricsQuery) (*QueryResult, error)

Query performs a query on stored metrics.

func (*MemoryStorage) Restore

func (ms *MemoryStorage) Restore(ctx context.Context, data []byte) error

Restore restores metrics from a backup.

func (*MemoryStorage) Retrieve

func (ms *MemoryStorage) Retrieve(ctx context.Context, name string, tags map[string]string) (*MetricEntry, error)

Retrieve retrieves a metric entry.

func (*MemoryStorage) Start

func (ms *MemoryStorage) Start(ctx context.Context) error

Start starts the storage system.

func (*MemoryStorage) Stats

func (ms *MemoryStorage) Stats(ctx context.Context) (any, error)

Stats returns storage statistics.

func (*MemoryStorage) Stop

func (ms *MemoryStorage) Stop(ctx context.Context) error

Stop stops the storage system.

func (*MemoryStorage) Store

func (ms *MemoryStorage) Store(ctx context.Context, entry *MetricEntry) error

Store stores a metric entry.

type MemoryStorageBackup

type MemoryStorageBackup struct {
	Timestamp time.Time          `json:"timestamp"`
	Entries   []*MetricEntry     `json:"entries"`
	Stats     MemoryStorageStats `json:"stats"`
}

MemoryStorageBackup represents a backup of memory storage.

type MemoryStorageConfig

type MemoryStorageConfig struct {
	MaxEntries      int           `json:"max_entries"      yaml:"max_entries"`
	Retention       time.Duration `json:"retention"        yaml:"retention"`
	CleanupInterval time.Duration `json:"cleanup_interval" yaml:"cleanup_interval"`
	EnableStats     bool          `json:"enable_stats"     yaml:"enable_stats"`
}

MemoryStorageConfig contains configuration for memory storage.

func DefaultMemoryStorageConfig

func DefaultMemoryStorageConfig() *MemoryStorageConfig

DefaultMemoryStorageConfig returns default configuration.

type MemoryStorageStats

type MemoryStorageStats struct {
	EntriesCount     int64         `json:"entries_count"`
	MaxEntries       int           `json:"max_entries"`
	StorageSize      int64         `json:"storage_size"`
	TotalWrites      int64         `json:"total_writes"`
	TotalReads       int64         `json:"total_reads"`
	TotalDeletes     int64         `json:"total_deletes"`
	CleanupRuns      int64         `json:"cleanup_runs"`
	LastCleanup      time.Time     `json:"last_cleanup"`
	AverageEntrySize float64       `json:"average_entry_size"`
	OldestEntry      time.Time     `json:"oldest_entry"`
	NewestEntry      time.Time     `json:"newest_entry"`
	MemoryUsage      int64         `json:"memory_usage"`
	HitRate          float64       `json:"hit_rate"`
	Uptime           time.Duration `json:"uptime"`
	// contains filtered or unexported fields
}

MemoryStorageStats contains statistics about memory storage.

type MetricEntry

type MetricEntry struct {
	Name        string            `json:"name"`
	Type        shared.MetricType `json:"type"`
	Value       any               `json:"value"`
	Tags        map[string]string `json:"tags"`
	Timestamp   time.Time         `json:"timestamp"`
	LastUpdated time.Time         `json:"last_updated"`
	AccessCount int64             `json:"access_count"`
	Metadata    map[string]any    `json:"metadata"`
}

MetricEntry represents a stored metric entry.

type MetricsAggregation

type MetricsAggregation struct {
	Function string            `json:"function"`
	Filters  map[string]string `json:"filters"`
	GroupBy  []string          `json:"group_by"`
}

MetricsAggregation represents an aggregation operation.

type MetricsQuery

type MetricsQuery struct {
	Filters   map[string]string `json:"filters"`
	StartTime time.Time         `json:"start_time"`
	EndTime   time.Time         `json:"end_time"`
	SortBy    string            `json:"sort_by"`
	SortOrder string            `json:"sort_order"`
	Limit     int               `json:"limit"`
	Offset    int               `json:"offset"`
}

MetricsQuery represents a query for metrics.

type MetricsStorage

type MetricsStorage interface {
	Store(ctx context.Context, entry *MetricEntry) error
	Retrieve(ctx context.Context, name string, tags map[string]string) (*MetricEntry, error)
	Delete(ctx context.Context, name string, tags map[string]string) error
	List(ctx context.Context, filters map[string]string) ([]*MetricEntry, error)
	Count(ctx context.Context) (int64, error)
	Clear(ctx context.Context) error
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	Health(ctx context.Context) error
	Stats(ctx context.Context) (any, error)
}

MetricsStorage defines the interface for metrics storage.

func NewMemoryStorage

func NewMemoryStorage() MetricsStorage

NewMemoryStorage creates a new memory storage instance.

func NewMemoryStorageWithConfig

func NewMemoryStorageWithConfig(config *MemoryStorageConfig) MetricsStorage

NewMemoryStorageWithConfig creates a new memory storage instance with configuration.

func NewRedisStorage

func NewRedisStorage() MetricsStorage

NewRedisStorage creates a new Redis storage instance.

func NewRedisStorageWithConfig

func NewRedisStorageWithConfig(config *RedisStorageConfig) MetricsStorage

NewRedisStorageWithConfig creates a new Redis storage instance with configuration.

func NewTimeSeriesStorage

func NewTimeSeriesStorage() MetricsStorage

NewTimeSeriesStorage creates a new time-series storage instance.

type QueryResult

type QueryResult struct {
	Entries    []*MetricEntry `json:"entries"`
	TotalCount int            `json:"total_count"`
	Query      MetricsQuery   `json:"query"`
	Timestamp  time.Time      `json:"timestamp"`
}

QueryResult represents the result of a query.

type RedisStorage

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

RedisStorage provides Redis-backed storage for metrics.

func (*RedisStorage) Aggregate

func (rs *RedisStorage) Aggregate(ctx context.Context, aggregation MetricsAggregation) (*AggregationResult, error)

Aggregate performs aggregation on stored metrics.

func (*RedisStorage) Backup

func (rs *RedisStorage) Backup(ctx context.Context) ([]byte, error)

Backup creates a backup of all stored metrics.

func (*RedisStorage) Clear

func (rs *RedisStorage) Clear(ctx context.Context) error

Clear clears all stored entries.

func (*RedisStorage) Count

func (rs *RedisStorage) Count(ctx context.Context) (int64, error)

Count returns the number of stored entries.

func (*RedisStorage) Delete

func (rs *RedisStorage) Delete(ctx context.Context, name string, tags map[string]string) error

Delete deletes a metric entry from Redis.

func (*RedisStorage) Health

func (rs *RedisStorage) Health(ctx context.Context) error

Health checks the health of the Redis storage system.

func (*RedisStorage) List

func (rs *RedisStorage) List(ctx context.Context, filters map[string]string) ([]*MetricEntry, error)

List lists all metric entries matching filters.

func (*RedisStorage) Query

func (rs *RedisStorage) Query(ctx context.Context, query MetricsQuery) (*QueryResult, error)

Query performs a query on stored metrics.

func (*RedisStorage) Restore

func (rs *RedisStorage) Restore(ctx context.Context, data []byte) error

Restore restores metrics from a backup.

func (*RedisStorage) Retrieve

func (rs *RedisStorage) Retrieve(ctx context.Context, name string, tags map[string]string) (*MetricEntry, error)

Retrieve retrieves a metric entry from Redis.

func (*RedisStorage) SetLogger

func (rs *RedisStorage) SetLogger(logger logger.Logger)

SetLogger sets the logger for the Redis storage.

func (*RedisStorage) Start

func (rs *RedisStorage) Start(ctx context.Context) error

Start starts the Redis storage system.

func (*RedisStorage) Stats

func (rs *RedisStorage) Stats(ctx context.Context) (any, error)

Stats returns storage statistics.

func (*RedisStorage) Stop

func (rs *RedisStorage) Stop(ctx context.Context) error

Stop stops the Redis storage system.

func (*RedisStorage) Store

func (rs *RedisStorage) Store(ctx context.Context, entry *MetricEntry) error

Store stores a metric entry in Redis.

type RedisStorageBackup

type RedisStorageBackup struct {
	Timestamp time.Time         `json:"timestamp"`
	Entries   []*MetricEntry    `json:"entries"`
	Stats     RedisStorageStats `json:"stats"`
}

RedisStorageBackup represents a backup of Redis storage.

type RedisStorageConfig

type RedisStorageConfig struct {
	Address         string        `json:"address"          yaml:"address"`
	Password        string        `json:"password"         yaml:"password"`
	Database        int           `json:"database"         yaml:"database"`
	KeyPrefix       string        `json:"key_prefix"       yaml:"key_prefix"`
	PoolSize        int           `json:"pool_size"        yaml:"pool_size"`
	MinIdleConns    int           `json:"min_idle_conns"   yaml:"min_idle_conns"`
	MaxRetries      int           `json:"max_retries"      yaml:"max_retries"`
	DialTimeout     time.Duration `json:"dial_timeout"     yaml:"dial_timeout"`
	ReadTimeout     time.Duration `json:"read_timeout"     yaml:"read_timeout"`
	WriteTimeout    time.Duration `json:"write_timeout"    yaml:"write_timeout"`
	Retention       time.Duration `json:"retention"        yaml:"retention"`
	CleanupInterval time.Duration `json:"cleanup_interval" yaml:"cleanup_interval"`
	EnableStats     bool          `json:"enable_stats"     yaml:"enable_stats"`
}

RedisStorageConfig contains configuration for Redis storage.

func DefaultRedisStorageConfig

func DefaultRedisStorageConfig() *RedisStorageConfig

DefaultRedisStorageConfig returns default configuration.

type RedisStorageStats

type RedisStorageStats struct {
	Address          string        `json:"address"`
	Connected        bool          `json:"connected"`
	PoolSize         int           `json:"pool_size"`
	TotalConns       int           `json:"total_conns"`
	IdleConns        int           `json:"idle_conns"`
	StaleConns       int           `json:"stale_conns"`
	EntriesCount     int64         `json:"entries_count"`
	TotalWrites      int64         `json:"total_writes"`
	TotalReads       int64         `json:"total_reads"`
	TotalDeletes     int64         `json:"total_deletes"`
	FailedWrites     int64         `json:"failed_writes"`
	FailedReads      int64         `json:"failed_reads"`
	FailedDeletes    int64         `json:"failed_deletes"`
	CleanupRuns      int64         `json:"cleanup_runs"`
	LastCleanup      time.Time     `json:"last_cleanup"`
	AverageEntrySize float64       `json:"average_entry_size"`
	KeyspaceSize     int64         `json:"keyspace_size"`
	HitRate          float64       `json:"hit_rate"`
	Uptime           time.Duration `json:"uptime"`
	// contains filtered or unexported fields
}

RedisStorageStats contains statistics about Redis storage.

type TimeAggregationData

type TimeAggregationData struct {
	Name     string            `json:"name"`
	Tags     map[string]string `json:"tags"`
	Function string            `json:"function"`
	Windows  []*TimeWindow     `json:"windows"`
}

TimeAggregationData represents aggregated time series data.

type TimeAggregationQuery

type TimeAggregationQuery struct {
	Filters  map[string]string `json:"filters"`
	Start    time.Time         `json:"start"`
	End      time.Time         `json:"end"`
	Step     time.Duration     `json:"step"`
	Function string            `json:"function"`
}

TimeAggregationQuery represents a time aggregation query.

type TimeAggregationResult

type TimeAggregationResult struct {
	Data      []*TimeAggregationData `json:"data"`
	Query     TimeAggregationQuery   `json:"query"`
	Timestamp time.Time              `json:"timestamp"`
}

TimeAggregationResult represents the result of a time aggregation query.

type TimeRangeQuery

type TimeRangeQuery struct {
	Filters map[string]string `json:"filters"`
	Start   time.Time         `json:"start"`
	End     time.Time         `json:"end"`
	Step    time.Duration     `json:"step"`
}

TimeRangeQuery represents a time range query.

type TimeRangeResult

type TimeRangeResult struct {
	Data      []*TimeSeriesData `json:"data"`
	Query     TimeRangeQuery    `json:"query"`
	Timestamp time.Time         `json:"timestamp"`
}

TimeRangeResult represents the result of a time range query.

type TimeSeries

type TimeSeries struct {
	Name        string                `json:"name"`
	Tags        map[string]string     `json:"tags"`
	Type        shared.MetricType     `json:"type"`
	Unit        string                `json:"unit"`
	Points      []*TimeSeriesPoint    `json:"points"`
	Buckets     map[int64]*TimeWindow `json:"buckets"`
	Created     time.Time             `json:"created"`
	Updated     time.Time             `json:"updated"`
	AccessCount int64                 `json:"access_count"`
	Metadata    map[string]any        `json:"metadata"`
	// contains filtered or unexported fields
}

TimeSeries represents a time-series of metric data points.

type TimeSeriesData

type TimeSeriesData struct {
	Name   string             `json:"name"`
	Tags   map[string]string  `json:"tags"`
	Points []*TimeSeriesPoint `json:"points"`
}

TimeSeriesData represents time series data.

type TimeSeriesPoint

type TimeSeriesPoint struct {
	Timestamp time.Time         `json:"timestamp"`
	Value     float64           `json:"value"`
	Tags      map[string]string `json:"tags,omitempty"`
	Metadata  map[string]any    `json:"metadata,omitempty"`
}

TimeSeriesPoint represents a single data point in a time series.

type TimeSeriesStorage

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

TimeSeriesStorage provides time-series storage for metrics with efficient time-based operations.

func NewTimeSeriesStorageWithConfig

func NewTimeSeriesStorageWithConfig(config *TimeSeriesStorageConfig) *TimeSeriesStorage

NewTimeSeriesStorageWithConfig creates a new time-series storage instance with configuration.

func (*TimeSeriesStorage) AggregateRange

AggregateRange aggregates time series data over time windows.

func (*TimeSeriesStorage) Clear

func (ts *TimeSeriesStorage) Clear(ctx context.Context) error

Clear clears all time series.

func (*TimeSeriesStorage) Count

func (ts *TimeSeriesStorage) Count(ctx context.Context) (int64, error)

Count returns the number of time series.

func (*TimeSeriesStorage) Delete

func (ts *TimeSeriesStorage) Delete(ctx context.Context, name string, tags map[string]string) error

Delete deletes a time series.

func (*TimeSeriesStorage) Health

func (ts *TimeSeriesStorage) Health(ctx context.Context) error

Health checks the health of the time-series storage system.

func (*TimeSeriesStorage) List

func (ts *TimeSeriesStorage) List(ctx context.Context, filters map[string]string) ([]*MetricEntry, error)

List lists all time series matching filters.

func (*TimeSeriesStorage) QueryRange

func (ts *TimeSeriesStorage) QueryRange(ctx context.Context, query TimeRangeQuery) (*TimeRangeResult, error)

QueryRange queries time series data within a time range.

func (*TimeSeriesStorage) Retrieve

func (ts *TimeSeriesStorage) Retrieve(ctx context.Context, name string, tags map[string]string) (*MetricEntry, error)

Retrieve retrieves a metric entry (latest point) from time-series.

func (*TimeSeriesStorage) SetLogger

func (ts *TimeSeriesStorage) SetLogger(logger logger.Logger)

SetLogger sets the logger for the time-series storage.

func (*TimeSeriesStorage) Start

func (ts *TimeSeriesStorage) Start(ctx context.Context) error

Start starts the time-series storage system.

func (*TimeSeriesStorage) Stats

func (ts *TimeSeriesStorage) Stats(ctx context.Context) (any, error)

Stats returns storage statistics.

func (*TimeSeriesStorage) Stop

func (ts *TimeSeriesStorage) Stop(ctx context.Context) error

Stop stops the time-series storage system.

func (*TimeSeriesStorage) Store

func (ts *TimeSeriesStorage) Store(ctx context.Context, entry *MetricEntry) error

Store stores a metric entry as a time-series point.

type TimeSeriesStorageConfig

type TimeSeriesStorageConfig struct {
	Retention          time.Duration `json:"retention"             yaml:"retention"`
	Resolution         time.Duration `json:"resolution"            yaml:"resolution"`
	MaxSeries          int           `json:"max_series"            yaml:"max_series"`
	MaxPointsPerSeries int           `json:"max_points_per_series" yaml:"max_points_per_series"`
	CompressionEnabled bool          `json:"compression_enabled"   yaml:"compression_enabled"`
	CompressionDelay   time.Duration `json:"compression_delay"     yaml:"compression_delay"`
	CleanupInterval    time.Duration `json:"cleanup_interval"      yaml:"cleanup_interval"`
	EnableStats        bool          `json:"enable_stats"          yaml:"enable_stats"`
}

TimeSeriesStorageConfig contains configuration for time-series storage.

func DefaultTimeSeriesStorageConfig

func DefaultTimeSeriesStorageConfig() *TimeSeriesStorageConfig

DefaultTimeSeriesStorageConfig returns default configuration.

type TimeSeriesStorageStats

type TimeSeriesStorageStats struct {
	SeriesCount       int64         `json:"series_count"`
	TotalPoints       int64         `json:"total_points"`
	CompressedPoints  int64         `json:"compressed_points"`
	TotalWrites       int64         `json:"total_writes"`
	TotalReads        int64         `json:"total_reads"`
	TotalDeletes      int64         `json:"total_deletes"`
	CompressionRuns   int64         `json:"compression_runs"`
	CleanupRuns       int64         `json:"cleanup_runs"`
	LastCleanup       time.Time     `json:"last_cleanup"`
	LastCompression   time.Time     `json:"last_compression"`
	AverageSeriesSize float64       `json:"average_series_size"`
	OldestPoint       time.Time     `json:"oldest_point"`
	NewestPoint       time.Time     `json:"newest_point"`
	CompressionRatio  float64       `json:"compression_ratio"`
	MemoryUsage       int64         `json:"memory_usage"`
	Uptime            time.Duration `json:"uptime"`
	// contains filtered or unexported fields
}

TimeSeriesStorageStats contains statistics about time-series storage.

type TimeWindow

type TimeWindow struct {
	Start      time.Time `json:"start"`
	End        time.Time `json:"end"`
	Count      int64     `json:"count"`
	Sum        float64   `json:"sum"`
	Min        float64   `json:"min"`
	Max        float64   `json:"max"`
	Mean       float64   `json:"mean"`
	StdDev     float64   `json:"stddev"`
	Compressed bool      `json:"compressed"`
}

TimeWindow represents aggregated data for a time window.

Jump to

Keyboard shortcuts

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