connection

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2020 License: GPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DbBulkDeletes = promauto.NewCounter(prometheus.CounterOpts{
	Name: "db_bulk_deletes",
	Help: "Database bulk deletes since startup",
})
View Source
var DbBulkInserts = promauto.NewCounter(prometheus.CounterOpts{
	Name: "db_bulk_inserts",
	Help: "Database bulk inserts since startup",
})
View Source
var DbBulkUpdates = promauto.NewCounter(prometheus.CounterOpts{
	Name: "db_bulk_updates",
	Help: "Database bulk updates since startup",
})
View Source
var DbFetchChecksums = promauto.NewCounter(prometheus.CounterOpts{
	Name: "db_fetch_checksums",
	Help: "Database FetchChecksums calls since startup",
})
View Source
var DbFetchIds = promauto.NewCounter(prometheus.CounterOpts{
	Name: "db_fetch_ids",
	Help: "Database FetchId calls since startup",
})
View Source
var DbIoSeconds = promauto.NewSummaryVec(
	prometheus.SummaryOpts{
		Name: "db_io_seconds",
		Help: "Database I/O (s)",
	},
	[]string{"backend_type", "operation"},
)
View Source
var DbOperationsBegin = promauto.NewCounter(prometheus.CounterOpts{
	Name: "db_operations_begin",
	Help: "Database begin operations since startup",
})
View Source
var DbOperationsCommit = promauto.NewCounter(prometheus.CounterOpts{
	Name: "db_operations_commit",
	Help: "Database commit operations since startup",
})
View Source
var DbOperationsExec = promauto.NewCounter(prometheus.CounterOpts{
	Name: "db_operations_exec",
	Help: "Database exec operations since startup",
})
View Source
var DbOperationsQuery = promauto.NewCounter(prometheus.CounterOpts{
	Name: "db_operations_query",
	Help: "Database query operations since startup",
})
View Source
var DbOperationsRollback = promauto.NewCounter(prometheus.CounterOpts{
	Name: "db_operations_rollback",
	Help: "Database rollback operations since startup",
})
View Source
var DbTransactions = promauto.NewCounter(prometheus.CounterOpts{
	Name: "db_transactions",
	Help: "Database transactions since startup",
})
View Source
var RedisWriter = Icinga2RedisWriter{
	Events: Icinga2RedisWriterEvents{
		Config: Icinga2RedisWriterEventsConfig{
			Dump:   "icinga:config:dump",
			Delete: "icinga:config:delete",
			Update: "icinga:config:update",
		},
		Stats: "icinga:stats",
	},
	KeyPrefixes: Icinga2RedisWriterKeyPrefixes{
		Config: Icinga2RedisWriterKeyPrefixesConfig{
			Checksum:  "icinga:config:checksum:",
			Object:    "icinga:config:object:",
			Customvar: "icinga:config:customvar:",
		},
		Status: Icinga2RedisWriterKeyPrefixesStatus{
			Object: "icinga:state:object:",
		},
	},
}

Functions

func ConvertValueForDb

func ConvertValueForDb(in interface{}) (interface{}, error)

func MakePlaceholderList

func MakePlaceholderList(x int) string

Types

type BulkDeleteStmt

type BulkDeleteStmt struct {
	Format string
}

func NewBulkDeleteStmt

func NewBulkDeleteStmt(table string, primaryKey string) *BulkDeleteStmt

type BulkInsertStmt

type BulkInsertStmt struct {
	Format      string
	Fields      []string
	Placeholder string
	NumField    int
}

func NewBulkInsertStmt

func NewBulkInsertStmt(table string, fields []string) *BulkInsertStmt

type BulkUpdateStmt

type BulkUpdateStmt struct {
	Format      string
	Fields      []string
	Placeholder string
	NumField    int
}

func NewBulkUpdateStmt

func NewBulkUpdateStmt(table string, fields []string) *BulkUpdateStmt

type ChecksumChunk

type ChecksumChunk struct {
	Keys      []string
	Checksums []interface{}
}

type ConfigChunk

type ConfigChunk struct {
	Keys      []string
	Configs   []interface{}
	Checksums []interface{}
}

type DBWrapper

type DBWrapper struct {
	Db                          DbClient
	ConnectedAtomic             *uint32 //uint32 to be able to use atomic operations
	ConnectionUpCondition       *sync.Cond
	ConnectionLostCounterAtomic *uint32 //uint32 to be able to use atomic operations
}

DBWrapper is a database wrapper including helper functions.

func NewDBWrapper

func NewDBWrapper(dbDsn string, maxOpenConns int) (*DBWrapper, error)

func (*DBWrapper) CompareAndSetConnected

func (dbw *DBWrapper) CompareAndSetConnected(connected bool) (swapped bool)

func (*DBWrapper) IsConnected

func (dbw *DBWrapper) IsConnected() bool

func (*DBWrapper) SqlBegin

func (dbw *DBWrapper) SqlBegin(concurrencySafety bool, quiet bool) (DbTransaction, error)

SqlBegin is a wrapper around Db.BeginTx() for auto-logging.

func (*DBWrapper) SqlBulkDelete

func (dbw *DBWrapper) SqlBulkDelete(keys []string, stmt *BulkDeleteStmt) error

func (*DBWrapper) SqlBulkInsert

func (dbw *DBWrapper) SqlBulkInsert(rows []Row, stmt *BulkInsertStmt) error

func (*DBWrapper) SqlBulkUpdate

func (dbw *DBWrapper) SqlBulkUpdate(rows []Row, stmt *BulkUpdateStmt) error

func (*DBWrapper) SqlCommit

func (dbw *DBWrapper) SqlCommit(tx DbTransaction, quiet bool) error

SqlCommit is a wrapper around tx.Commit() for auto-logging.

func (*DBWrapper) SqlExec

func (dbw *DBWrapper) SqlExec(opObserver prometheus.Observer, sql string, args ...interface{}) (sql.Result, error)

SqlExec is a wrapper around sql.Exec() for auto-logging.

func (*DBWrapper) SqlExecQuiet

func (dbw *DBWrapper) SqlExecQuiet(opObserver prometheus.Observer, sql string, args ...interface{}) (sql.Result, error)

SqlExecQuiet is like SqlExec, but doesn't log or benchmark.

func (*DBWrapper) SqlExecTx

func (dbw *DBWrapper) SqlExecTx(tx DbTransaction, opObserver prometheus.Observer, sql string, args ...interface{}) (sql.Result, error)

SqlExecTx is a wrapper around tx.Exec() for auto-logging.

func (*DBWrapper) SqlExecTxQuiet

func (dbw *DBWrapper) SqlExecTxQuiet(tx DbTransaction, opObserver prometheus.Observer, sql string, args ...interface{}) (sql.Result, error)

SqlExecTxQuiet is like SqlExecTx, but doesn't log or benchmark.

func (*DBWrapper) SqlFetchAll

func (dbw *DBWrapper) SqlFetchAll(queryObserver prometheus.Observer, query string, args ...interface{}) ([][]interface{}, error)

func (*DBWrapper) SqlFetchAllQuiet

func (dbw *DBWrapper) SqlFetchAllQuiet(queryObserver prometheus.Observer, query string, args ...interface{}) ([][]interface{}, error)

func (*DBWrapper) SqlFetchAllTx

func (dbw *DBWrapper) SqlFetchAllTx(tx DbTransaction, queryObserver prometheus.Observer, query string, args ...interface{}) ([][]interface{}, error)

func (*DBWrapper) SqlFetchAllTxQuiet

func (dbw *DBWrapper) SqlFetchAllTxQuiet(tx DbTransaction, queryObserver prometheus.Observer, query string, args ...interface{}) ([][]interface{}, error)

func (*DBWrapper) SqlFetchChecksums

func (dbw *DBWrapper) SqlFetchChecksums(table string, ids []string) (map[string]map[string]string, error)

func (*DBWrapper) SqlFetchIds

func (dbw *DBWrapper) SqlFetchIds(envId []byte, table string, field string) ([]string, error)

func (*DBWrapper) SqlQuery

func (dbw *DBWrapper) SqlQuery(query string, args ...interface{}) (*sql.Rows, error)

func (*DBWrapper) SqlRollback

func (dbw *DBWrapper) SqlRollback(tx DbTransaction, quiet bool) error

SqlRollback is a wrapper around tx.Rollback() for auto-logging.

func (DBWrapper) SqlTransaction

func (dbw DBWrapper) SqlTransaction(concurrencySafety bool, retryOnConnectionFailure bool, quiet bool, f func(DbTransaction) error) error

sqlTransaction executes the given function inside a transaction.

func (*DBWrapper) WaitForConnection

func (dbw *DBWrapper) WaitForConnection()

func (*DBWrapper) WithRetry

func (dbw *DBWrapper) WithRetry(f func() (sql.Result, error)) (sql.Result, error)

type DbClient

type DbClient interface {
	DbClientOrTransaction
	Ping() error
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}

type DbClientOrTransaction

type DbClientOrTransaction interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
	Exec(query string, args ...interface{}) (sql.Result, error)
}

DbClientOrTransaction is used in SqlFetchAll and SqlFetchAllQuiet.

type DbTransaction

type DbTransaction interface {
	DbClientOrTransaction
	Commit() error
	Rollback() error
}

type Icinga2RedisWriter

type Icinga2RedisWriter struct {
	Events      Icinga2RedisWriterEvents
	KeyPrefixes Icinga2RedisWriterKeyPrefixes
}

type Icinga2RedisWriterEvents

type Icinga2RedisWriterEvents struct {
	Config Icinga2RedisWriterEventsConfig
	Stats  string
}

type Icinga2RedisWriterEventsConfig

type Icinga2RedisWriterEventsConfig struct {
	Update, Delete, Dump string
}

type Icinga2RedisWriterKeyPrefixes

type Icinga2RedisWriterKeyPrefixes struct {
	Config Icinga2RedisWriterKeyPrefixesConfig
	Status Icinga2RedisWriterKeyPrefixesStatus
}

type Icinga2RedisWriterKeyPrefixesConfig

type Icinga2RedisWriterKeyPrefixesConfig struct {
	Checksum, Object, Customvar string
}

type Icinga2RedisWriterKeyPrefixesStatus

type Icinga2RedisWriterKeyPrefixesStatus struct {
	Object string
}

type MysqlConnectionError

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

func (MysqlConnectionError) Error

func (e MysqlConnectionError) Error() string

type PipelinerWrapper

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

func (*PipelinerWrapper) Exec

func (plw *PipelinerWrapper) Exec() ([]redis.Cmder, error)

func (*PipelinerWrapper) HMGet

func (plw *PipelinerWrapper) HMGet(key string, fields ...string) *redis.SliceCmd

type PubSubWrapper

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

func (*PubSubWrapper) Channel

func (psw *PubSubWrapper) Channel() <-chan *redis.Message

func (*PubSubWrapper) ChannelSize

func (psw *PubSubWrapper) ChannelSize(size int) <-chan *redis.Message

func (*PubSubWrapper) Close

func (psw *PubSubWrapper) Close() error

func (*PubSubWrapper) ReceiveMessage

func (psw *PubSubWrapper) ReceiveMessage() (*redis.Message, error)

func (*PubSubWrapper) Subscribe

func (psw *PubSubWrapper) Subscribe(channels ...string) error

type RDBWrapper

type RDBWrapper struct {
	Rdb                         RedisClient
	ConnectedAtomic             *uint32 //uint32 to be able to use atomic operations
	ConnectionUpCondition       *sync.Cond
	ConnectionLostCounterAtomic *uint32 //uint32 to be able to use atomic operations
}

RDBWrapper is a redis wrapper including helper functions.

func NewRDBWrapper

func NewRDBWrapper(address string, poolSize int) *RDBWrapper

func (*RDBWrapper) CheckConnection

func (rdbw *RDBWrapper) CheckConnection(isTicker bool) bool

func (*RDBWrapper) CompareAndSetConnected

func (rdbw *RDBWrapper) CompareAndSetConnected(connected bool) (swapped bool)

func (*RDBWrapper) Eval

func (rdbw *RDBWrapper) Eval(script string, keys []string, args ...interface{}) *redis.Cmd

Eval is a wrapper for connection handling.

func (*RDBWrapper) EvalSha

func (rdbw *RDBWrapper) EvalSha(sha1 string, keys []string, args ...interface{}) *redis.Cmd

EvalSha is a wrapper for connection handling.

func (*RDBWrapper) HGetAll

func (rdbw *RDBWrapper) HGetAll(key string) *redis.StringStringMapCmd

HGetAll is a wrapper for auto-logging and connection handling.

func (*RDBWrapper) HKeys

func (rdbw *RDBWrapper) HKeys(key string) *redis.StringSliceCmd

HKeys is a wrapper for connection handling.

func (*RDBWrapper) HMGet

func (rdbw *RDBWrapper) HMGet(key string, fields ...string) *redis.SliceCmd

func (*RDBWrapper) IsConnected

func (rdbw *RDBWrapper) IsConnected() bool

func (*RDBWrapper) PipeChecksumChunks

func (rdbw *RDBWrapper) PipeChecksumChunks(done <-chan struct{}, keys []string, redisKey string) <-chan *ChecksumChunk

func (*RDBWrapper) PipeConfigChunks

func (rdbw *RDBWrapper) PipeConfigChunks(done <-chan struct{}, keys []string, redisKey string) <-chan *ConfigChunk

func (*RDBWrapper) Pipeline

func (rdbw *RDBWrapper) Pipeline() PipelinerWrapper

func (*RDBWrapper) Publish

func (rdbw *RDBWrapper) Publish(channel string, message interface{}) *redis.IntCmd

Publish is a wrapper for connection handling.

func (*RDBWrapper) SAdd

func (rdbw *RDBWrapper) SAdd(key string, members ...interface{}) *redis.IntCmd

SAdd is a wrapper for connection handling.

func (*RDBWrapper) SRem

func (rdbw *RDBWrapper) SRem(key string, members ...interface{}) *redis.IntCmd

SRem is a wrapper for connection handling.

func (*RDBWrapper) ScriptExists

func (rdbw *RDBWrapper) ScriptExists(hashes ...string) *redis.BoolSliceCmd

ScriptExists is a wrapper for connection handling.

func (*RDBWrapper) ScriptLoad

func (rdbw *RDBWrapper) ScriptLoad(script string) *redis.StringCmd

ScriptLoad is a wrapper for connection handling.

func (*RDBWrapper) Subscribe

func (rdbw *RDBWrapper) Subscribe() PubSubWrapper

func (*RDBWrapper) TxPipelined

func (rdbw *RDBWrapper) TxPipelined(fn func(pipeliner redis.Pipeliner) error) ([]redis.Cmder, error)

TxPipelined is a wrapper for auto-logging and connection handling.

func (*RDBWrapper) WaitForConnection

func (rdbw *RDBWrapper) WaitForConnection()

func (*RDBWrapper) XAdd

func (rdbw *RDBWrapper) XAdd(a *redis.XAddArgs) *redis.StringCmd

XAdd is a wrapper for connection handling.

func (*RDBWrapper) XDel

func (rdbw *RDBWrapper) XDel(stream string, ids ...string) *redis.IntCmd

XDel is a wrapper for connection handling.

func (*RDBWrapper) XRead

func (rdbw *RDBWrapper) XRead(args *redis.XReadArgs) *redis.XStreamSliceCmd

XRead is a wrapper for connection handling.

type RedisClient

type RedisClient interface {
	Ping() *redis.StatusCmd
	Publish(channel string, message interface{}) *redis.IntCmd
	XRead(a *redis.XReadArgs) *redis.XStreamSliceCmd
	XDel(stream string, ids ...string) *redis.IntCmd
	XAdd(a *redis.XAddArgs) *redis.StringCmd
	HKeys(key string) *redis.StringSliceCmd
	HMGet(key string, fields ...string) *redis.SliceCmd
	HGetAll(key string) *redis.StringStringMapCmd
	TxPipelined(fn func(redis.Pipeliner) error) ([]redis.Cmder, error)
	Pipeline() redis.Pipeliner
	Subscribe(channels ...string) *redis.PubSub
	Eval(script string, keys []string, args ...interface{}) *redis.Cmd
	EvalSha(sha1 string, keys []string, args ...interface{}) *redis.Cmd
	ScriptExists(hashes ...string) *redis.BoolSliceCmd
	ScriptLoad(script string) *redis.StringCmd
	SAdd(key string, members ...interface{}) *redis.IntCmd
	SRem(key string, members ...interface{}) *redis.IntCmd
}

type Row

type Row interface {
	InsertValues() []interface{}
	UpdateValues() []interface{}
	GetId() string
	SetId(id string)
	GetFinalRows() ([]Row, error)
}

type RowFactory

type RowFactory func() Row

type StatusCmd

type StatusCmd interface {
}

Jump to

Keyboard shortcuts

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