Files
signoz/pkg/sqlstore/config.go
Vikrant Gupta 3e241944e7 chore(sqlstore): added connection max lifetime support (#10913)
* chore(sqlstore): added connection max lifetime param support

* chore(sqlstore): fix test

* chore(sqlstore): default to 0 for conn_max_lifetime

* chore(sqlstore): rename the config

* chore(sqlstore): rename the config
2026-04-13 13:09:00 +00:00

72 lines
2.0 KiB
Go

package sqlstore
import (
"time"
"github.com/SigNoz/signoz/pkg/factory"
)
type Config struct {
// Provider is the provider to use.
Provider string `mapstructure:"provider"`
// Connection is the connection configuration.
Connection ConnectionConfig `mapstructure:",squash"`
// Sqlite is the sqlite configuration.
Sqlite SqliteConfig `mapstructure:"sqlite"`
// Postgres is the postgres configuration.
Postgres PostgresConfig `mapstructure:"postgres"`
}
type PostgresConfig struct {
// DSN is the database source name.
DSN string `mapstructure:"dsn"`
}
type SqliteConfig struct {
// Path is the path to the sqlite database.
Path string `mapstructure:"path"`
// Mode is the journal mode for the sqlite database.
Mode string `mapstructure:"mode"`
// BusyTimeout is the timeout for the sqlite database to wait for a lock.
BusyTimeout time.Duration `mapstructure:"busy_timeout"`
// TransactionMode is the default transaction locking behavior for the sqlite database.
TransactionMode string `mapstructure:"transaction_mode"`
}
type ConnectionConfig struct {
// MaxOpenConns is the maximum number of open connections to the database.
MaxOpenConns int `mapstructure:"max_open_conns"`
// MaxConnLifetime is the maximum amount of time a connection may be reused.
// If max_conn_lifetime == 0, connections are not closed due to a connection's age.
MaxConnLifetime time.Duration `mapstructure:"max_conn_lifetime"`
}
func NewConfigFactory() factory.ConfigFactory {
return factory.NewConfigFactory(factory.MustNewName("sqlstore"), newConfig)
}
func newConfig() factory.Config {
return Config{
Provider: "sqlite",
Connection: ConnectionConfig{
MaxOpenConns: 100,
MaxConnLifetime: 0,
},
Sqlite: SqliteConfig{
Path: "/var/lib/signoz/signoz.db",
Mode: "wal",
BusyTimeout: 10000 * time.Millisecond, // increasing the defaults from https://github.com/mattn/go-sqlite3/blob/master/sqlite3.go#L1098 because of transpilation from C to GO
TransactionMode: "deferred",
},
}
}
func (c Config) Validate() error {
return nil
}