Documentation
¶
Overview ¶
Package storage implements inetrface to diffent ways of storing metrics data.
Index ¶
- type DBConnPool
- type DBConnPoolMock
- func (m *DBConnPoolMock) Acquire(ctx context.Context) (*pgxpool.Conn, error)
- func (m *DBConnPoolMock) Close()
- func (m *DBConnPoolMock) Ping(ctx context.Context) error
- func (m *DBConnPoolMock) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
- func (m *DBConnPoolMock) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
- func (m *DBConnPoolMock) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
- type DatabaseStorage
- func (d DatabaseStorage) Close(_ context.Context) error
- func (d DatabaseStorage) Get(ctx context.Context, key string) (Record, error)
- func (d DatabaseStorage) GetAll(ctx context.Context) ([]Record, error)
- func (d DatabaseStorage) Ping(ctx context.Context) error
- func (d DatabaseStorage) Push(ctx context.Context, key string, record Record) error
- func (d DatabaseStorage) PushBatch(ctx context.Context, data map[string]Record) error
- type FileBackedStorage
- func (f *FileBackedStorage) Close(ctx context.Context) error
- func (f *FileBackedStorage) Dump(ctx context.Context) (err error)
- func (f *FileBackedStorage) Push(ctx context.Context, key string, record Record) error
- func (f *FileBackedStorage) PushBatch(ctx context.Context, data map[string]Record) error
- func (f *FileBackedStorage) Restore() (err error)
- type MemStorage
- func (m *MemStorage) Close(_ context.Context) error
- func (m *MemStorage) Get(_ context.Context, key string) (Record, error)
- func (m *MemStorage) GetAll(_ context.Context) ([]Record, error)
- func (m *MemStorage) Push(_ context.Context, key string, record Record) error
- func (m *MemStorage) PushBatch(_ context.Context, data map[string]Record) error
- func (m *MemStorage) Snapshot() *MemStorage
- type Mock
- func (m *Mock) Close(ctx context.Context) error
- func (m *Mock) Get(ctx context.Context, key string) (Record, error)
- func (m *Mock) GetAll(ctx context.Context) ([]Record, error)
- func (m *Mock) Push(ctx context.Context, key string, record Record) error
- func (m *Mock) PushBatch(ctx context.Context, data map[string]Record) error
- type Record
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBConnPool ¶
type DBConnPool interface { Acquire(ctx context.Context) (*pgxpool.Conn, error) Ping(ctx context.Context) error Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults Close() }
type DBConnPoolMock ¶
func NewDBConnPoolMock ¶
func NewDBConnPoolMock() *DBConnPoolMock
func (*DBConnPoolMock) Close ¶
func (m *DBConnPoolMock) Close()
func (*DBConnPoolMock) QueryRow ¶
func (m *DBConnPoolMock) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
func (*DBConnPoolMock) SendBatch ¶
func (m *DBConnPoolMock) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
type DatabaseStorage ¶
type DatabaseStorage struct {
// contains filtered or unexported fields
}
DatabaseStorage implements database metrics storage.
func NewDatabaseStorage ¶
func NewDatabaseStorage(pool DBConnPool) DatabaseStorage
NewDatabaseStorage creates new instance of DatabaseStorage.
func (DatabaseStorage) Close ¶
func (d DatabaseStorage) Close(_ context.Context) error
Close closes all open connection to the database.
func (DatabaseStorage) GetAll ¶
func (d DatabaseStorage) GetAll(ctx context.Context) ([]Record, error)
GetAll returns all stored metrics.
func (DatabaseStorage) Ping ¶
func (d DatabaseStorage) Ping(ctx context.Context) error
Ping verifies that connection to the database can be established.
type FileBackedStorage ¶
type FileBackedStorage struct { *MemStorage sync.Mutex // contains filtered or unexported fields }
FileBackedStorage implements in-memory metrics storage with ability to dump/restore metrics data to/from disk.
func NewFileBackedStorage ¶
func NewFileBackedStorage(storePath string, syncMode bool) *FileBackedStorage
NewFileBackedStorage creates new instance of FileBackedStorage.
func (*FileBackedStorage) Close ¶
func (f *FileBackedStorage) Close(ctx context.Context) error
Close dumps all stored data to disk. The storage can be restored from this dump later.
func (*FileBackedStorage) Dump ¶
func (f *FileBackedStorage) Dump(ctx context.Context) (err error)
Dump writes all stored data to disk. The storage can be restored from this dump later.
func (*FileBackedStorage) Restore ¶
func (f *FileBackedStorage) Restore() (err error)
Restore reads previously stored data from disk and populates the storage.
type MemStorage ¶
MemStorage implements in-memory metrics storage.
func NewMemStorage ¶
func NewMemStorage() *MemStorage
NewMemStorage creates new instance of MemStorage.
func (*MemStorage) Close ¶
func (m *MemStorage) Close(_ context.Context) error
Close has no effect on in-memory storage.
func (*MemStorage) GetAll ¶
func (m *MemStorage) GetAll(_ context.Context) ([]Record, error)
GetAll returns all stored metrics.
func (*MemStorage) Snapshot ¶
func (m *MemStorage) Snapshot() *MemStorage
Snapshot creates independent copy of in-memory storage.
type Record ¶
A Record is internal represenattion of metric data stored in any kind of storage.
func (Record) MarshalJSON ¶
func (*Record) UnmarshalJSON ¶
type Storage ¶
type Storage interface { Push(ctx context.Context, key string, record Record) error PushBatch(ctx context.Context, data map[string]Record) error Get(ctx context.Context, key string) (Record, error) GetAll(ctx context.Context) ([]Record, error) Close(ctx context.Context) error }
func NewDataStore ¶
NewDataStore create new DataStore object encapsulating particular storage type. New storage is picked according to the following priority: - if DB connection was initialized, use database storage; - if filePath is set, use file backed storage; - otherwise store data in memory.