Documentation
¶
Index ¶
- Variables
- func CheckSchema(ctx context.Context, db *database.DB) error
- func ImportSchema(ctx context.Context, db *database.DB, databaseSchemaDir string) error
- func ServiceUser() string
- type CleanupStmt
- type Delta
- type DeltaHook
- type DumpSignals
- type EntitiesById
- type HA
- func (h *HA) Close(ctx context.Context) error
- func (h *HA) Done() <-chan struct{}
- func (h *HA) EndpointID() types.Binary
- func (h *HA) Environment() *v1.Environment
- func (h *HA) Err() error
- func (h *HA) Handover() chan string
- func (h *HA) Icinga2Version() string
- func (h *HA) NotificationsHeartbeat() chan<- types.Bool
- func (h *HA) State() (responsibleTsMilli int64, responsible, otherResponsible bool)
- func (h *HA) Takeover() chan string
- type NotificationsState
- type RUOption
- type RUOptions
- type RUUpsertFunc
- type RuntimeUpdates
- type ScopedEntity
- type Sync
- func (s Sync) ApplyDelta(ctx context.Context, delta *Delta, hook DeltaHook) error
- func (s Sync) Sync(ctx context.Context, subject *common.SyncSubject, hook DeltaHook) error
- func (s Sync) SyncAfterDump(ctx context.Context, subject *common.SyncSubject, dump *DumpSignals, ...) error
- func (s Sync) SyncCustomvars(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
var ErrSchemaMismatch = stderrors.New("unexpected database schema version")
ErrSchemaMismatch implies an unexpected schema version, most likely after Icinga DB was updated but the database missed the schema upgrade.
var ErrSchemaNotExists = stderrors.New("no database schema exists")
ErrSchemaNotExists implies that no Icinga DB schema has been imported.
Functions ¶
func CheckSchema ¶ added in v1.2.1
CheckSchema verifies the correct database schema is present.
This function returns the following error types, possibly wrapped:
- If no schema exists, the error returned is ErrSchemaNotExists.
- If the schema version does not match the expected version, the error returned is ErrSchemaMismatch.
- Otherwise, the original error is returned, for example in case of general database problems.
func ImportSchema ¶ added in v1.3.0
ImportSchema performs an initial schema import in the db.
This function assumes that no schema exists. So it should only be called after a prior CheckSchema call.
Note: Running a schema file may have side effects, such as altering SQL system variables. Unless you are certain that the schema update will not interfere with future queries, consider using a dedicated database connection.
func ServiceUser ¶ added in v1.6.0
func ServiceUser() string
ServiceUser returns the name the service user the process is running as.
Types ¶
type CleanupStmt ¶
CleanupStmt defines information needed to compose cleanup statements.
func (*CleanupStmt) CleanupOlderThan ¶ added in v1.2.1
func (stmt *CleanupStmt) CleanupOlderThan( ctx context.Context, db *database.DB, envId types.Binary, count uint64, olderThan time.Time, onSuccess ...database.OnSuccess[struct{}], ) (uint64, error)
CleanupOlderThan deletes all rows with the specified statement that are older than the given time. Deletes a maximum of as many rows per round as defined in count. Actually deleted rows will be passed to onSuccess. Returns the total number of rows deleted.
type Delta ¶
type Delta struct {
RedisSnapshot map[string]struct{} // Reflects all the entities read from Redis (desired).
Create EntitiesById
Update EntitiesById
Delete EntitiesById
Subject *common.SyncSubject
// contains filtered or unexported fields
}
Delta calculates the delta of actual and desired entities, and stores which entities need to be created, updated, and deleted.
type DeltaHook ¶ added in v1.6.0
DeltaHook is a type for a function that takes a Delta and returns an error.
It is used to hook into the sync process and perform additional actions on the delta while it is being applied to the database (currently in parallel with the actual DB sync).
type DumpSignals ¶
type DumpSignals struct {
// contains filtered or unexported fields
}
DumpSignals reads dump signals from a Redis stream via Listen. Dump-done signals are passed on via Done channels, while InProgress must be checked for dump-wip signals.
func NewDumpSignals ¶
func NewDumpSignals(redis *redis.Client, logger *logging.Logger) *DumpSignals
NewDumpSignals returns new DumpSignals.
func (*DumpSignals) Done ¶
func (s *DumpSignals) Done(key string) <-chan struct{}
Done returns a channel that is closed when the given key receives a done dump signal.
func (*DumpSignals) InProgress ¶
func (s *DumpSignals) InProgress() <-chan struct{}
InProgress returns a channel that is closed when a new dump is in progress after done signals were sent to channels returned by Done.
func (*DumpSignals) Listen ¶
func (s *DumpSignals) Listen(ctx context.Context) error
Listen starts listening for dump signals in the icinga:dump Redis stream. When a done signal is received, this is signaled via the channels returned from the Done function.
If a wip signal is received after a done signal was passed on via the Done function, this is signaled via the InProgress function and this function returns with err == nil. In this case, all other signals are invalidated. It is up to the caller to pass on this information, for example by cancelling derived contexts.
This function may only be called once for each DumpSignals object. To listen for a new iteration of dump signals, a new DumpSignals instance must be created.
type EntitiesById ¶
EntitiesById is a map of key-database.Entity pairs.
func (EntitiesById) Entities ¶
func (ebi EntitiesById) Entities(ctx context.Context) <-chan database.Entity
Entities streams the entities on a returned channel.
func (EntitiesById) IDs ¶
func (ebi EntitiesById) IDs() []any
IDs returns the contracts.ID of the entities.
type HA ¶
type HA struct {
// contains filtered or unexported fields
}
HA provides high availability and indicates whether a Takeover or Handover must be made.
func NewHA ¶
func NewHA( ctx context.Context, db *database.DB, heartbeat *icingaredis.Heartbeat, logger *logging.Logger, notificationsSynchronizeWithDatabase bool, icinga2VersionCheck func(version string) error, ) *HA
NewHA returns a new HA and starts the controller loop.
func (*HA) Done ¶
func (h *HA) Done() <-chan struct{}
Done returns a channel that's closed when the HA controller loop ended.
func (*HA) EndpointID ¶ added in v1.6.0
EndpointID returns the current endpoint ID.
func (*HA) Environment ¶
func (h *HA) Environment() *v1.Environment
Environment returns the current environment.
func (*HA) Err ¶
Err returns an error if Done has been closed and there is an error. Otherwise returns nil.
func (*HA) Handover ¶
Handover returns a channel with which handovers and their reasons are signaled.
func (*HA) Icinga2Version ¶ added in v1.6.0
Icinga2Version returns the Icinga 2 version from the last received heartbeat, which might be empty if none was received yet.
func (*HA) NotificationsHeartbeat ¶ added in v1.6.0
NotificationsHeartbeat returns a channel to send the status of Icinga Notifications component into.
The channel is used to signal the health of the Icinga Notifications component, where a true value indicates that the component is healthy and able to process notifications, while a false value indicates that it is not. An invalid types.Bool marks the state as unknown, as it is before the component has been configured.
type NotificationsState ¶ added in v1.6.0
type NotificationsState struct {
// contains filtered or unexported fields
}
NotificationsState holds the current state of the Icinga Notifications component.
func (*NotificationsState) IsValidUnhealthy ¶ added in v1.6.0
func (ns *NotificationsState) IsValidUnhealthy() bool
IsValidUnhealthy returns true if the healthy state is valid and set to false, indicating that the Icinga Notifications component is unhealthy.
type RUOption ¶ added in v1.6.0
type RUOption func(*RUOptions)
RUOption defines an option for the RuntimeUpdates.Sync method.
func WithAllowParallel ¶ added in v1.6.0
func WithAllowParallel() RUOption
WithAllowParallel allows parallel execution of runtime updates for the same entity type.
func WithRUUpsert ¶ added in v1.6.0
func WithRUUpsert(fn RUUpsertFunc) RUOption
WithRUUpsert allows providing a callback that is called for each Redis stream message of type "upsert".
If this option is used, RuntimeUpdates.Sync will start a separate xRead goroutine for the corresponding stream, thus allowing the provided callback to run in parallel with the main database upsert operations for the same entity type. Note that the callback is called for each message of type "upsert", regardless of the entity type, so it is the responsibility of that callback to filter the entities if necessary. Also note that the callback must be safe for concurrent execution, as it may be called in parallel with different types of entities.
type RUOptions ¶ added in v1.6.0
type RUOptions struct {
// contains filtered or unexported fields
}
RUOptions defines options for the RuntimeUpdates.Sync method.
type RUUpsertFunc ¶ added in v1.6.0
RUUpsertFunc defines the type of the callback that can be provided to the RuntimeUpdates.Sync method via the WithRUUpsert option.
type RuntimeUpdates ¶
type RuntimeUpdates struct {
// contains filtered or unexported fields
}
RuntimeUpdates specifies the source and destination of runtime updates.
func NewRuntimeUpdates ¶
func NewRuntimeUpdates(db *database.DB, redis *redis.Client, logger *logging.Logger) *RuntimeUpdates
NewRuntimeUpdates creates a new RuntimeUpdates.
func (*RuntimeUpdates) ClearStreams ¶
ClearStreams returns the stream key to ID mapping of the runtime update streams for later use in Sync and clears the streams themselves.
func (*RuntimeUpdates) Sync ¶
func (r *RuntimeUpdates) Sync( ctx context.Context, factoryFuncs []database.EntityFactoryFunc, streams redis.Streams, options ...RUOption, ) error
Sync synchronizes runtime update streams from r.redis to r.db and deletes the original data on success.
The options parameter can be used to specify additional options for the synchronization, such as allowing parallel execution of updates for the same entity type (bulk DB upsert and delete ops) or providing a callback that is called for each Redis stream message of type "upsert" in parallel with the main database upsert operations for the same entity type.
Note that Sync must only be called after configuration synchronization has been completed.
func (*RuntimeUpdates) SyncPassive ¶ added in v1.6.0
func (r *RuntimeUpdates) SyncPassive(ctx context.Context, ha *HA)
SyncPassive discards runtime update streams while this instance is passive. only the active instance consumes them, so a passive instance's streams would grow indefinitely. safe to discard as a takeover always starts with a full config and state sync from the icinga:* hashes.
type ScopedEntity ¶
ScopedEntity combines an entity and a scope that specifies the WHERE conditions that entities of the enclosed entity type must satisfy in order to be SELECTed.
func NewScopedEntity ¶
func NewScopedEntity(entity database.Entity, scope any) *ScopedEntity
NewScopedEntity returns a new ScopedEntity.
func (ScopedEntity) Scope ¶
func (e ScopedEntity) Scope() any
Scope implements the contracts.Scoper interface.
func (ScopedEntity) TableName ¶
func (e ScopedEntity) TableName() string
TableName implements the contracts.TableNamer interface.
type Sync ¶
type Sync struct {
// contains filtered or unexported fields
}
Sync implements a rendezvous point for Icinga DB and Redis to synchronize their entities.
func (Sync) ApplyDelta ¶
ApplyDelta applies all changes from Delta to the database.
func (Sync) Sync ¶
Sync synchronizes entities between Icinga DB and Redis created with the specified sync subject. This function does not respect dump signals. For this, use SyncAfterDump.
func (Sync) SyncAfterDump ¶
func (s Sync) SyncAfterDump(ctx context.Context, subject *common.SyncSubject, dump *DumpSignals, hook DeltaHook) error
SyncAfterDump waits for a config dump to finish (using the dump parameter) and then starts a sync for the given sync subject using the Sync function.