heartbeat

package
Version: v0.27.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB implements Store using Postgres as a backend.

func NewDB

func NewDB(ctx context.Context, db *sql.DB) (*DB, error)

func (*DB) CreateTx

func (db *DB) CreateTx(ctx context.Context, tx *sql.Tx, m *Monitor) (*Monitor, error)

func (*DB) DeleteTx

func (db *DB) DeleteTx(ctx context.Context, tx *sql.Tx, ids ...string) error

func (*DB) FindAllByService

func (db *DB) FindAllByService(ctx context.Context, serviceID string) ([]Monitor, error)

func (*DB) FindMany added in v0.24.0

func (db *DB) FindMany(ctx context.Context, ids ...string) ([]Monitor, error)

func (*DB) FindOneTx added in v0.24.0

func (db *DB) FindOneTx(ctx context.Context, tx *sql.Tx, id string) (*Monitor, error)

func (*DB) Heartbeat

func (db *DB) Heartbeat(ctx context.Context, id string) error

func (*DB) UpdateTx added in v0.24.0

func (db *DB) UpdateTx(ctx context.Context, tx *sql.Tx, m *Monitor) error

type Monitor

type Monitor struct {
	ID        string        `json:"id,omitempty"`
	Name      string        `json:"name,omitempty"`
	ServiceID string        `json:"service_id,omitempty"`
	Timeout   time.Duration `json:"timeout,omitempty"`
	// contains filtered or unexported fields
}

A Monitor will generate an alert if it does not receive a heartbeat within the configured TimeoutMinutes.

func (Monitor) LastHeartbeat added in v0.24.0

func (m Monitor) LastHeartbeat() time.Time

LastHeartbeat returns the timestamp of the last successful heartbeat.

func (Monitor) LastState

func (m Monitor) LastState() State

LastState returns the last known state.

func (Monitor) Normalize

func (m Monitor) Normalize() (*Monitor, error)

Normalize performs validation and returns a new copy.

type State

type State string

State represents the health of a heartbeat monitor.

const (
	// StateInactive means the heartbeat has not yet reported for the first time.
	StateInactive State = "inactive"

	// StateHealthy indicates a heartbeat was received within the past interval.
	StateHealthy State = "healthy"

	// StateUnhealthy indicates a heartbeat has not been received since beyond the interval.
	StateUnhealthy State = "unhealthy"
)

func (*State) Scan

func (r *State) Scan(value interface{}) error

Scan handles reading State from the DB format

type Store

type Store interface {
	// Heartbeat records a heartbeat for the given heartbeat ID.
	Heartbeat(context.Context, string) error

	// CreateTx creates a new heartbeat check within the transaction.
	CreateTx(context.Context, *sql.Tx, *Monitor) (*Monitor, error)

	// Delete deletes the heartbeat check with the given heartbeat ID.
	DeleteTx(context.Context, *sql.Tx, ...string) error

	// FindAllByService returns all heartbeats belonging to the given service ID.
	FindAllByService(context.Context, string) ([]Monitor, error)

	// UpdateTx updates a heartbeat's fields within the transaction.
	UpdateTx(context.Context, *sql.Tx, *Monitor) error

	// FindOneTx returns a heartbeat montior for updating.
	FindOneTx(context.Context, *sql.Tx, string) (*Monitor, error)

	// FindMany returns the heartbeat monitors with the given IDs.
	FindMany(context.Context, ...string) ([]Monitor, error)
}

Store manages heartbeat checks and recording heartbeats.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL