Help us shape the future of Go! Take the 2026 Go Developer Survey

persistence

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 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 ExportFormat

type ExportFormat string

ExportFormat represents supported export formats.

const (
	ExportFormatJSON ExportFormat = "json"
	ExportFormatCSV  ExportFormat = "csv"
	ExportFormatXML  ExportFormat = "xml"
)

type ExporterConfig

type ExporterConfig struct {
	Format         string            `json:"format"         yaml:"format"`         // prometheus, json
	Endpoint       string            `json:"endpoint"       yaml:"endpoint"`       // Export endpoint
	Interval       time.Duration     `json:"interval"       yaml:"interval"`       // Export interval
	Timeout        time.Duration     `json:"timeout"        yaml:"timeout"`        // Request timeout
	Headers        map[string]string `json:"headers"        yaml:"headers"`        // HTTP headers
	Authentication map[string]string `json:"authentication" yaml:"authentication"` // Auth config
}

ExporterConfig contains configuration for health metrics export.

type FileHealthStore

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

FileHealthStore implements HealthStore using file-based storage.

func (*FileHealthStore) Cleanup

func (fhs *FileHealthStore) Cleanup(ctx context.Context, before time.Time) error

Cleanup removes old data.

func (*FileHealthStore) Close

func (fhs *FileHealthStore) Close() error

Close closes the file store.

func (*FileHealthStore) GetHealthHistory

func (fhs *FileHealthStore) GetHealthHistory(ctx context.Context, checkName string, from, to time.Time, interval time.Duration) ([]*HealthHistoryPoint, error)

GetHealthHistory retrieves health history (simplified for file store).

func (*FileHealthStore) GetHealthStatistics

func (fhs *FileHealthStore) GetHealthStatistics(ctx context.Context, checkName string, from, to time.Time) (*HealthStatistics, error)

GetHealthStatistics calculates health statistics (simplified).

func (*FileHealthStore) GetHealthTrend

func (fhs *FileHealthStore) GetHealthTrend(ctx context.Context, checkName string, duration time.Duration) (*HealthTrend, error)

GetHealthTrend analyzes health trends (simplified).

func (*FileHealthStore) GetReport

func (fhs *FileHealthStore) GetReport(ctx context.Context, timestamp time.Time) (*health.HealthReport, error)

GetReport retrieves a specific health report.

func (*FileHealthStore) GetReports

func (fhs *FileHealthStore) GetReports(ctx context.Context, from, to time.Time) ([]*health.HealthReport, error)

GetReports retrieves health reports for a time range.

func (*FileHealthStore) GetResult

func (fhs *FileHealthStore) GetResult(ctx context.Context, checkName string, timestamp time.Time) (*health.HealthResult, error)

GetResult retrieves a specific health result.

func (*FileHealthStore) GetResults

func (fhs *FileHealthStore) GetResults(ctx context.Context, checkName string, from, to time.Time) ([]*health.HealthResult, error)

GetResults retrieves health results for a time range.

func (*FileHealthStore) GetSize

func (fhs *FileHealthStore) GetSize(ctx context.Context) (int64, error)

GetSize returns the file size.

func (*FileHealthStore) StoreReport

func (fhs *FileHealthStore) StoreReport(ctx context.Context, report *health.HealthReport) error

StoreReport stores a health report to file.

func (*FileHealthStore) StoreResult

func (fhs *FileHealthStore) StoreResult(ctx context.Context, result *health.HealthResult) error

StoreResult stores a health result to file.

type HealthDataExporter

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

HealthDataExporter exports health data in various formats.

func NewHealthDataExporter

func NewHealthDataExporter(store HealthStore) *HealthDataExporter

NewHealthDataExporter creates a new health data exporter.

func (*HealthDataExporter) ExportHealthData

func (hde *HealthDataExporter) ExportHealthData(ctx context.Context, checkName string, from, to time.Time, format ExportFormat) ([]byte, error)

ExportHealthData exports health data in the specified format.

type HealthHistoryPoint

type HealthHistoryPoint struct {
	Timestamp time.Time           `json:"timestamp"`
	Status    health.HealthStatus `json:"status"`
	Duration  time.Duration       `json:"duration"`
	Message   string              `json:"message"`
	Error     string              `json:"error,omitempty"`
	Details   map[string]any      `json:"details,omitempty"`
}

HealthHistoryPoint represents a point in health history.

type HealthMetricsCollector

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

HealthMetricsCollector collects metrics from health data.

func NewHealthMetricsCollector

func NewHealthMetricsCollector(store HealthStore, metrics shared.Metrics, logger logger.Logger, config *MetricsCollectorConfig) *HealthMetricsCollector

NewHealthMetricsCollector creates a new health metrics collector.

func (*HealthMetricsCollector) GetLastCollectTime

func (hmc *HealthMetricsCollector) GetLastCollectTime() time.Time

GetLastCollectTime returns the last collection time.

func (*HealthMetricsCollector) IsStarted

func (hmc *HealthMetricsCollector) IsStarted() bool

IsStarted returns true if the collector is started.

func (*HealthMetricsCollector) Start

func (hmc *HealthMetricsCollector) Start(ctx context.Context) error

Start starts the metrics collection.

func (*HealthMetricsCollector) Stop

Stop stops the metrics collection.

type HealthMetricsExporter

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

HealthMetricsExporter exports health metrics to external systems.

func NewHealthMetricsExporter

func NewHealthMetricsExporter(collector *HealthMetricsCollector, config *ExporterConfig, logger logger.Logger) *HealthMetricsExporter

NewHealthMetricsExporter creates a new health metrics exporter.

func (*HealthMetricsExporter) Export

func (hme *HealthMetricsExporter) Export(ctx context.Context) error

Export exports health metrics.

type HealthMetricsService

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

HealthMetricsService provides health metrics as a service.

func NewHealthMetricsService

func NewHealthMetricsService(store HealthStore, metrics shared.Metrics, logger logger.Logger, config *HealthMetricsServiceConfig) *HealthMetricsService

NewHealthMetricsService creates a new health metrics service.

func (*HealthMetricsService) CollectNow

func (hms *HealthMetricsService) CollectNow(ctx context.Context) error

CollectNow triggers immediate metrics collection.

func (*HealthMetricsService) ExportNow

func (hms *HealthMetricsService) ExportNow(ctx context.Context) error

ExportNow triggers immediate metrics export.

func (*HealthMetricsService) GetCollector

func (hms *HealthMetricsService) GetCollector() *HealthMetricsCollector

GetCollector returns the metrics collector.

func (*HealthMetricsService) GetExporter

func (hms *HealthMetricsService) GetExporter() *HealthMetricsExporter

GetExporter returns the metrics exporter.

func (*HealthMetricsService) Name

func (hms *HealthMetricsService) Name() string

Name returns the service name.

func (*HealthMetricsService) OnHealthCheck

func (hms *HealthMetricsService) OnHealthCheck(ctx context.Context) error

OnHealthCheck performs health check.

func (*HealthMetricsService) Start

func (hms *HealthMetricsService) Start(ctx context.Context) error

Start starts the health metrics service.

func (*HealthMetricsService) Stop

func (hms *HealthMetricsService) Stop(ctx context.Context) error

Stop stops the health metrics service.

type HealthMetricsServiceConfig

type HealthMetricsServiceConfig struct {
	CollectorConfig *MetricsCollectorConfig `json:"collector" yaml:"collector"`
	ExporterConfig  *ExporterConfig         `json:"exporter"  yaml:"exporter"`
	Enabled         bool                    `json:"enabled"   yaml:"enabled"`
}

HealthMetricsServiceConfig contains configuration for the health metrics service.

type HealthPersistenceService

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

HealthPersistenceService manages health data persistence.

func NewHealthPersistenceService

func NewHealthPersistenceService(store HealthStore, config *HealthStoreConfig, logger logger.Logger, metrics shared.Metrics) *HealthPersistenceService

NewHealthPersistenceService creates a new health persistence service.

func (*HealthPersistenceService) GetHealthHistory

func (hps *HealthPersistenceService) GetHealthHistory(ctx context.Context, checkName string, from, to time.Time, interval time.Duration) ([]*HealthHistoryPoint, error)

GetHealthHistory returns health history for a check.

func (*HealthPersistenceService) GetHealthStatistics

func (hps *HealthPersistenceService) GetHealthStatistics(ctx context.Context, checkName string, from, to time.Time) (*HealthStatistics, error)

GetHealthStatistics returns health statistics.

func (*HealthPersistenceService) GetHealthTrend

func (hps *HealthPersistenceService) GetHealthTrend(ctx context.Context, checkName string, duration time.Duration) (*HealthTrend, error)

GetHealthTrend returns health trend analysis.

func (*HealthPersistenceService) GetStore

func (hps *HealthPersistenceService) GetStore() HealthStore

GetStore returns the underlying health store.

func (*HealthPersistenceService) Start

Start starts the persistence service.

func (*HealthPersistenceService) Stop

Stop stops the persistence service.

func (*HealthPersistenceService) StoreReport

func (hps *HealthPersistenceService) StoreReport(ctx context.Context, report *health.HealthReport) error

StoreReport stores a health report.

func (*HealthPersistenceService) StoreResult

func (hps *HealthPersistenceService) StoreResult(ctx context.Context, result *health.HealthResult) error

StoreResult stores a health check result.

type HealthQueryBuilder

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

HealthQueryBuilder provides a fluent interface for building health queries.

func NewHealthQueryBuilder

func NewHealthQueryBuilder(store HealthStore) *HealthQueryBuilder

NewHealthQueryBuilder creates a new health query builder.

func (*HealthQueryBuilder) Between

func (hqb *HealthQueryBuilder) Between(from, to time.Time) *HealthQueryBuilder

Between sets the time range for the query.

func (*HealthQueryBuilder) ForCheck

func (hqb *HealthQueryBuilder) ForCheck(checkName string) *HealthQueryBuilder

ForCheck sets the check name to query.

func (*HealthQueryBuilder) GetHistory

func (hqb *HealthQueryBuilder) GetHistory(ctx context.Context) ([]*HealthHistoryPoint, error)

GetHistory executes the query and returns health history.

func (*HealthQueryBuilder) GetResults

func (hqb *HealthQueryBuilder) GetResults(ctx context.Context) ([]*health.HealthResult, error)

GetResults executes the query and returns health results.

func (*HealthQueryBuilder) GetStatistics

func (hqb *HealthQueryBuilder) GetStatistics(ctx context.Context) (*HealthStatistics, error)

GetStatistics executes the query and returns health statistics.

func (*HealthQueryBuilder) GetTrend

func (hqb *HealthQueryBuilder) GetTrend(ctx context.Context) (*HealthTrend, error)

GetTrend executes the query and returns health trend.

func (*HealthQueryBuilder) Last

func (hqb *HealthQueryBuilder) Last(duration time.Duration) *HealthQueryBuilder

Last sets the query to cover the last duration.

func (*HealthQueryBuilder) WithInterval

func (hqb *HealthQueryBuilder) WithInterval(interval time.Duration) *HealthQueryBuilder

WithInterval sets the aggregation interval.

func (*HealthQueryBuilder) WithLimit

func (hqb *HealthQueryBuilder) WithLimit(limit int) *HealthQueryBuilder

WithLimit sets the result limit.

func (*HealthQueryBuilder) WithOffset

func (hqb *HealthQueryBuilder) WithOffset(offset int) *HealthQueryBuilder

WithOffset sets the result offset.

func (*HealthQueryBuilder) WithStatuses

func (hqb *HealthQueryBuilder) WithStatuses(statuses ...health.HealthStatus) *HealthQueryBuilder

WithStatuses filters by health statuses.

type HealthReportRecord

type HealthReportRecord struct {
	ID          uint      `gorm:"primaryKey"     json:"id"`
	Overall     string    `gorm:"not null"       json:"overall"`
	Services    string    `gorm:"type:text"      json:"services"`
	Timestamp   time.Time `gorm:"index;not null" json:"timestamp"`
	Duration    int64     `json:"duration"` // Duration in nanoseconds
	Version     string    `json:"version"`
	Environment string    `json:"environment"`
	Hostname    string    `json:"hostname"`
	Uptime      int64     `json:"uptime"` // Uptime in nanoseconds
	Metadata    string    `gorm:"type:text"      json:"metadata"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

HealthReportRecord represents a health report in the database.

func (HealthReportRecord) TableName

func (HealthReportRecord) TableName() string

TableName returns the table name for health reports.

type HealthResultRecord

type HealthResultRecord struct {
	ID        uint      `gorm:"primaryKey"     json:"id"`
	Name      string    `gorm:"index;not null" json:"name"`
	Status    string    `gorm:"not null"       json:"status"`
	Message   string    `gorm:"type:text"      json:"message"`
	Details   string    `gorm:"type:text"      json:"details"`
	Timestamp time.Time `gorm:"index;not null" json:"timestamp"`
	Duration  int64     `json:"duration"` // Duration in nanoseconds
	Error     string    `gorm:"type:text"      json:"error"`
	Critical  bool      `json:"critical"`
	Tags      string    `gorm:"type:text"      json:"tags"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

HealthResultRecord represents a health result in the database.

func (HealthResultRecord) TableName

func (HealthResultRecord) TableName() string

TableName returns the table name for health results.

type HealthStatistics

type HealthStatistics struct {
	CheckName       string                        `json:"check_name"`
	From            time.Time                     `json:"from"`
	To              time.Time                     `json:"to"`
	TotalChecks     int64                         `json:"total_checks"`
	SuccessCount    int64                         `json:"success_count"`
	FailureCount    int64                         `json:"failure_count"`
	SuccessRate     float64                       `json:"success_rate"`
	AvgDuration     time.Duration                 `json:"avg_duration"`
	MinDuration     time.Duration                 `json:"min_duration"`
	MaxDuration     time.Duration                 `json:"max_duration"`
	StatusCounts    map[health.HealthStatus]int64 `json:"status_counts"`
	ErrorCategories map[string]int64              `json:"error_categories"`
	Uptime          time.Duration                 `json:"uptime"`
	Downtime        time.Duration                 `json:"downtime"`
	MTBF            time.Duration                 `json:"mtbf"` // Mean Time Between Failures
	MTTR            time.Duration                 `json:"mttr"` // Mean Time To Recovery
}

HealthStatistics represents health statistics over a period.

type HealthStore

type HealthStore interface {
	// Store operations
	StoreResult(ctx context.Context, result *health.HealthResult) error
	StoreReport(ctx context.Context, report *health.HealthReport) error

	// Query operations
	GetResult(ctx context.Context, checkName string, timestamp time.Time) (*health.HealthResult, error)
	GetResults(ctx context.Context, checkName string, from, to time.Time) ([]*health.HealthResult, error)
	GetReport(ctx context.Context, timestamp time.Time) (*health.HealthReport, error)
	GetReports(ctx context.Context, from, to time.Time) ([]*health.HealthReport, error)

	// Aggregate operations
	GetHealthHistory(ctx context.Context, checkName string, from, to time.Time, interval time.Duration) ([]*HealthHistoryPoint, error)
	GetHealthTrend(ctx context.Context, checkName string, duration time.Duration) (*HealthTrend, error)
	GetHealthStatistics(ctx context.Context, checkName string, from, to time.Time) (*HealthStatistics, error)

	// Maintenance operations
	Cleanup(ctx context.Context, before time.Time) error
	GetSize(ctx context.Context) (int64, error)
	Close() error
}

HealthStore defines the interface for health history storage.

func NewFileHealthStore

func NewFileHealthStore(config *HealthStoreConfig, logger logger.Logger, metrics shared.Metrics) (HealthStore, error)

NewFileHealthStore creates a new file health store.

func NewMemoryHealthStore

func NewMemoryHealthStore(config *HealthStoreConfig, logger logger.Logger, metrics shared.Metrics) HealthStore

NewMemoryHealthStore creates a new in-memory health store.

type HealthStoreConfig

type HealthStoreConfig struct {
	Type              string            `json:"type"`
	ConnectionString  string            `json:"connection_string"`
	Database          string            `json:"database"`
	Table             string            `json:"table"`
	MaxRetention      time.Duration     `json:"max_retention"`
	CleanupInterval   time.Duration     `json:"cleanup_interval"`
	BatchSize         int               `json:"batch_size"`
	MaxConnections    int               `json:"max_connections"`
	QueryTimeout      time.Duration     `json:"query_timeout"`
	EnableCompression bool              `json:"enable_compression"`
	EnableEncryption  bool              `json:"enable_encryption"`
	Tags              map[string]string `json:"tags"`
}

HealthStoreConfig contains configuration for health store.

func DefaultHealthStoreConfig

func DefaultHealthStoreConfig() *HealthStoreConfig

DefaultHealthStoreConfig returns default configuration.

type HealthStoreFactory

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

HealthStoreFactory creates health store instances.

func NewHealthStoreFactory

func NewHealthStoreFactory(logger logger.Logger, metrics shared.Metrics, container shared.Container) *HealthStoreFactory

NewHealthStoreFactory creates a new health store factory.

func (*HealthStoreFactory) CreateStore

func (f *HealthStoreFactory) CreateStore(config *HealthStoreConfig) (HealthStore, error)

CreateStore creates a health store based on configuration.

type HealthTrend

type HealthTrend struct {
	CheckName           string                        `json:"check_name"`
	Period              time.Duration                 `json:"period"`
	TotalChecks         int64                         `json:"total_checks"`
	SuccessRate         float64                       `json:"success_rate"`
	AvgDuration         time.Duration                 `json:"avg_duration"`
	StatusDistribution  map[health.HealthStatus]int64 `json:"status_distribution"`
	ErrorRate           float64                       `json:"error_rate"`
	Trend               string                        `json:"trend"` // "improving", "stable", "degrading"
	LastCheck           time.Time                     `json:"last_check"`
	ConsecutiveFailures int                           `json:"consecutive_failures"`
}

HealthTrend represents health trend analysis.

type MemoryHealthStore

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

MemoryHealthStore implements HealthStore using in-memory storage.

func (*MemoryHealthStore) Cleanup

func (mhs *MemoryHealthStore) Cleanup(ctx context.Context, before time.Time) error

Cleanup removes old data.

func (*MemoryHealthStore) Close

func (mhs *MemoryHealthStore) Close() error

Close closes the memory store.

func (*MemoryHealthStore) GetHealthHistory

func (mhs *MemoryHealthStore) GetHealthHistory(ctx context.Context, checkName string, from, to time.Time, interval time.Duration) ([]*HealthHistoryPoint, error)

GetHealthHistory retrieves health history (simplified for memory store).

func (*MemoryHealthStore) GetHealthStatistics

func (mhs *MemoryHealthStore) GetHealthStatistics(ctx context.Context, checkName string, from, to time.Time) (*HealthStatistics, error)

GetHealthStatistics calculates health statistics (simplified).

func (*MemoryHealthStore) GetHealthTrend

func (mhs *MemoryHealthStore) GetHealthTrend(ctx context.Context, checkName string, duration time.Duration) (*HealthTrend, error)

GetHealthTrend analyzes health trends (simplified).

func (*MemoryHealthStore) GetReport

func (mhs *MemoryHealthStore) GetReport(ctx context.Context, timestamp time.Time) (*health.HealthReport, error)

GetReport retrieves a specific health report.

func (*MemoryHealthStore) GetReports

func (mhs *MemoryHealthStore) GetReports(ctx context.Context, from, to time.Time) ([]*health.HealthReport, error)

GetReports retrieves health reports for a time range.

func (*MemoryHealthStore) GetResult

func (mhs *MemoryHealthStore) GetResult(ctx context.Context, checkName string, timestamp time.Time) (*health.HealthResult, error)

GetResult retrieves a specific health result.

func (*MemoryHealthStore) GetResults

func (mhs *MemoryHealthStore) GetResults(ctx context.Context, checkName string, from, to time.Time) ([]*health.HealthResult, error)

GetResults retrieves health results for a time range.

func (*MemoryHealthStore) GetSize

func (mhs *MemoryHealthStore) GetSize(ctx context.Context) (int64, error)

GetSize returns the memory usage.

func (*MemoryHealthStore) StoreReport

func (mhs *MemoryHealthStore) StoreReport(ctx context.Context, report *health.HealthReport) error

StoreReport stores a health report in memory.

func (*MemoryHealthStore) StoreResult

func (mhs *MemoryHealthStore) StoreResult(ctx context.Context, result *health.HealthResult) error

StoreResult stores a health result in memory.

type MetricsCollectorConfig

type MetricsCollectorConfig struct {
	Enabled            bool          `json:"enabled"             yaml:"enabled"`
	CollectionInterval time.Duration `json:"collection_interval" yaml:"collection_interval"`
	HistoryDuration    time.Duration `json:"history_duration"    yaml:"history_duration"`
	EnableTrends       bool          `json:"enable_trends"       yaml:"enable_trends"`
	EnableStatistics   bool          `json:"enable_statistics"   yaml:"enable_statistics"`
	MetricPrefix       string        `json:"metric_prefix"       yaml:"metric_prefix"`
	Tags               []string      `json:"tags"                yaml:"tags"`
	ServicesFilter     []string      `json:"services_filter"     yaml:"services_filter"`
	ExcludeServices    []string      `json:"exclude_services"    yaml:"exclude_services"`
}

MetricsCollectorConfig contains configuration for health metrics collection.

func DefaultMetricsCollectorConfig

func DefaultMetricsCollectorConfig() *MetricsCollectorConfig

DefaultMetricsCollectorConfig returns default configuration.

Jump to

Keyboard shortcuts

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