Documentation
¶
Index ¶
Constants ¶
const ( // DBString to format connection string to database for postgres PostgresDBString = "host=%s port=%d dbname=%s user=%s password=%s sslmode=%s" // MySQLDBString to format connection string for MySQL MySQLDBString = "%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local" // DBKey to identify the configuration JSON key DBKey = "db" // Database types DBTypePostgres = "postgres" DBTypeMySQL = "mysql" DBTypeSQLite = "sqlite" )
Variables ¶
This section is empty.
Functions ¶
func LoadDBManagerFile ¶ added in v0.4.9
func LoadDBManagerFile(dbConfigFile string) (*config.YAMLConfigurationDB, error)
LoadDBManagerFile - Function to load DB configuration from YAML file
func PrepareDSN ¶
func PrepareDSN(config config.YAMLConfigurationDB) string
PrepareDSN to generate DB connection string
Types ¶
type DBHealth ¶ added in v0.5.5
type DBHealth struct {
// contains filtered or unexported fields
}
DBHealth monitors database availability by pinging the DB on a fixed interval. It is safe for concurrent use.
A background goroutine calls the check function every Interval. If the check fails FailureThreshold times in a row, IsDegraded() flips to true. The first success after degradation flips it back to false.
The monitor is opt-in: callers must call Start to launch the goroutine and Stop to shut it down. A nil *DBHealth is always non-degraded — EnvCache treats nil as "no monitoring, behave as before" so existing callers that don't wire a monitor are unaffected.
func NewDBHealth ¶ added in v0.5.5
NewDBHealth creates a DBHealth monitor for the given DBManager. Call Start to begin monitoring and Stop to shut down.
func (*DBHealth) IsDegraded ¶ added in v0.5.5
IsDegraded returns true when the DB has been unreachable for at least FailureThreshold consecutive checks.
func (*DBHealth) SetOnChange ¶ added in v0.5.5
SetOnChange wires a callback invoked whenever the degraded state transitions. Receives the new state (true = degraded). Used by callers to flip a Prometheus gauge without pkg/backend importing prometheus. Called from the monitor goroutine; callers must ensure their callback is safe to invoke from that goroutine.
type DBManager ¶
type DBManager struct {
Conn *gorm.DB
Config *config.YAMLConfigurationDB
DSN string
}
DBManager have access to backend
func CreateDBManager ¶
func CreateDBManager(dbConfig *config.YAMLConfigurationDB) (*DBManager, error)
CreateDBManager to initialize the DB struct
func CreateDBManagerFile ¶
CreateDBManagerFile to load values from YAML file and initialize the DB struct
type DegradedReader ¶ added in v0.5.5
type DegradedReader interface {
// IsDegraded returns true when the DB has been unreachable for
// at least FailureThreshold consecutive checks. Returns to false
// on the first successful ping after a degradation window.
IsDegraded() bool
}
DegradedReader is the read-only interface for DB health state. Caches and handlers use it to decide whether to serve stale data or extend TTLs during a DB outage.