integrations

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package integrations holds the Integrations of C-05: one per Alertmanager cluster, with its Connection mode, Static labels, duplicate window, Heartbeat settings and Integration tokens. A token is `mstr_int_` followed by 32 random bytes; only its SHA-256 is stored and the value is shown once, with the Alertmanager snippet that carries it (ADR-0011). Deletion is soft: the Integration leaves every list and its tokens stop working at once, while its Stored Snapshots stay until retention. Every change is recorded in the Audit log and announced with the live hint integration; the package also exports muster_integration_info. The built-in "Muster" Integration of the Internal alerts exists from the first start and cannot be changed, deleted or given a token.

Index

Constants

View Source
const (
	HeartbeatNotConfigured = "not_configured"
	HeartbeatWaiting       = "waiting"
	HeartbeatLive          = "live"
	HeartbeatLost          = "lost"
)

The Heartbeat states of an Integration (C-07.FR-3): off, waiting for the first signal, live, and lost.

View Source
const (
	DefaultDuplicateWindow  = 45 * time.Second
	DefaultHeartbeatTimeout = 5 * time.Minute
)

The defaults of the forms and of an omitted Heartbeat timeout: integration.duplicate_window and integration.heartbeat_timeout.

View Source
const (
	ActionCreated       = "integration.created"
	ActionUpdated       = "integration.updated"
	ActionDeleted       = "integration.deleted"
	ActionTokenCreated  = "integration_token.created"
	ActionTokenRevoked  = "integration_token.revoked"
	ResourceIntegration = "integration"
	ResourceToken       = "integration_token"
	Hint                = "integration"
)

The Audit log actions and resource types, and the live hint, of Integrations (C-03.FR-14).

View Source
const (
	IngestPath    = "/api/v1/ingest"
	HeartbeatPath = "/api/v1/heartbeat"
)

The paths of the ingestion and Heartbeat endpoints under MUSTER_INGEST_URL.

View Source
const (
	WarningSnapshotTruncated      = "snapshot_truncated"
	WarningLongRepeatInterval     = "long_repeat_interval"
	WarningHeartbeatNotConfigured = "heartbeat_not_configured"
	WarningHeartbeatWaiting       = "heartbeat_waiting"
	WarningHeartbeatLost          = "heartbeat_lost"
)

The kinds of the warnings of an Integration (C-06.FR-18, C-07.FR-5).

View Source
const (
	CodeInvalidFormat = "invalid_format"
	CodeTooLong       = "too_long"
	CodeOutOfRange    = "out_of_range"
	CodeUnsupported   = "unsupported"
)

The codes of FieldError.

View Source
const BuiltinName = "Muster"

BuiltinName is the name of the built-in Integration of the Internal alerts (integrations.builtin).

View Source
const ConnectionWebhookOnly = "webhook_only"

The Connection modes; L1 has only webhook-only (integration.connection_mode).

View Source
const LongRepeatWarning = time.Hour

LongRepeatWarning is processing.long_repeat_warning: a learned repeat interval above it warns about its Alertmanager route (C-06.FR-18).

View Source
const RepeatInterval = 10 * time.Minute

RepeatInterval is snippet.repeat_interval: the repeat_interval of the snippet's route, inside the recommended range of 5 to 15 minutes.

View Source
const Unknown = "unknown"

Unknown is the integration label of an ingestion request whose token matches no Integration that is not deleted (C-05.FR-4).

Variables

View Source
var (
	// ErrNotFound is an Integration that does not exist in the Organization or is deleted, or a token that is not one
	// of its tokens or is revoked.
	ErrNotFound = errors.New("no such integration or integration token")
	// ErrNameTaken is a name another Integration that is not deleted has.
	ErrNameTaken = errors.New("another integration has this name")
	// ErrVersionMismatch is an If-Match that names another version of the Integration.
	ErrVersionMismatch = errors.New("the integration changed since it was read")
	// ErrBuiltinImmutable is a change, a deletion or a token of the built-in Integration.
	ErrBuiltinImmutable = errors.New("the built-in integration cannot be changed, deleted or given a token")
)
View Source
var ErrInvalidToken = errors.New("the integration token is not valid")

ErrInvalidToken is an ingestion request whose token is missing, malformed, unknown or revoked, or belongs to a deleted Integration; it never says which.

Functions

func EnsureBuiltin

func EnsureBuiltin(ctx context.Context, q Queries, orgID int64, now time.Time) error

EnsureBuiltin creates the built-in "Muster" Integration of the Internal alerts once per Organization (C-06.FR-14), as a start-up ensure step: webhook-only, without Static labels and with the Heartbeat off. It changes nothing when the Integration exists; an Integration that is not deleted and already has its name stops the start with ErrNameTaken.

func Snippet

func Snippet(integrationName, ingestURL, token string) string

Snippet is the Alertmanager configuration of an Integration token (C-05.FR-5): an Alertmanager receiver muster-<name> whose webhook sends every alert of an Alertmanager group (max_alerts 0) and its resolves to the ingestion URL with the token as a bearer token, and a child route for it with continue, to be placed first, with snippet.repeat_interval and a comment on its range. Because a first child route without matchers matches every alert, Alertmanager no longer falls back to the top-level receiver: the snippet ends with a commented catch-all child route for that receiver, to be kept last.

Types

type Caller

type Caller struct {
	TokenID       int64
	IntegrationID int64
	// Integration is the public_id of the token's Integration, the integration label of the request's metrics.
	Integration string
}

Caller is who sends an ingestion request: the token and its Integration.

type Config

type Config struct {
	OrgID int64
	Store Store
	Audit *audit.Writer
	// Business is the business clock, which dates the rows and the use of tokens.
	Business clock.Clock
	// IngestURL is MUSTER_INGEST_URL, the base of the ingestion and Heartbeat URLs.
	IngestURL *url.URL
	// RunbookBase is MUSTER_RUNBOOK_BASE_URL, the base of the runbook_url of the Internal alerts a rename raises
	// again.
	RunbookBase string
}

Config is what a Service needs.

type CreatedToken

type CreatedToken struct {
	Token       Token
	Value       string
	Snippet     string
	Integration string
	Heartbeat   bool
}

CreatedToken is a token that was just issued, with its value and the Alertmanager snippet that carries it, which are shown this once. Integration is the name of its Integration, and Heartbeat whether that Integration's Heartbeat is on, so that the Heartbeat snippet can carry the token too.

type Demo

type Demo struct {
	Name         string
	StaticLabels map[string]string
	Heartbeat    bool
	Token        string
	TokenName    string
}

Demo is the Integration of the development mode: its name, Static labels and Heartbeat, and the published token that the fake Alertmanager sends with.

type FieldError

type FieldError struct {
	Pointer string
	Code    string
	Detail  string
}

FieldError is a field of a request that is not valid, at a JSON pointer of the request body, with a stable code of the validation-failed problem.

func (*FieldError) Error

func (e *FieldError) Error() string

type Heartbeat

type Heartbeat struct {
	Enabled        bool
	TimeoutSeconds int64
	State          string
	LastSignalAt   *time.Time
	LostSince      *time.Time
}

Heartbeat is the stored Heartbeat of an Integration: its settings and its state.

type HeartbeatInput

type HeartbeatInput struct {
	Enabled        bool
	TimeoutSeconds *int64
}

HeartbeatInput is the Heartbeat settings of an Input.

type Input

type Input struct {
	Name                   string
	Description            *string
	ConnectionMode         string
	StaticLabels           map[string]string
	DuplicateWindowSeconds int64
	Heartbeat              HeartbeatInput
}

Input is what createIntegration and updateIntegration write. A nil Description, or a nil Heartbeat timeout, keeps the stored value on an update and takes the default on a creation.

type Integration

type Integration struct {
	ID                     int64
	PublicID               string
	Name                   string
	Description            string
	Builtin                bool
	ConnectionMode         string
	StaticLabels           map[string]string
	DuplicateWindowSeconds int64
	Heartbeat              Heartbeat
	SnapshotCount          int64
	// LastSnapshotAt is the receipt time of its newest Stored Snapshot; nil before the first one.
	LastSnapshotAt *time.Time
	// Warnings apply while a groupKey is truncated or a route repeats less often than LongRepeatWarning.
	Warnings  []Warning
	CreatedAt time.Time
	Version   int64
}

Integration is an Integration as the API reads it.

type ListFilter

type ListFilter struct {
	After *int64
	Limit int
}

ListFilter selects a page of Integrations, in the order they were created, after the id After when it is set.

type Page

type Page struct {
	Integrations []Integration
	Next         *int64
}

Page is a page of Integrations; Next, the id to continue after, is nil on the last page.

type Queries

type Queries interface {
	ListIntegrations(ctx context.Context, arg dbgen.ListIntegrationsParams) ([]dbgen.ListIntegrationsRow, error)
	GetIntegration(ctx context.Context, arg dbgen.GetIntegrationParams) (dbgen.GetIntegrationRow, error)
	LastSnapshotTimes(ctx context.Context, arg dbgen.LastSnapshotTimesParams) ([]dbgen.LastSnapshotTimesRow, error)
	LockIntegration(ctx context.Context, arg dbgen.LockIntegrationParams) (int64, error)
	FindIntegrationByName(ctx context.Context, arg dbgen.FindIntegrationByNameParams) (string, error)
	InsertIntegration(ctx context.Context, arg dbgen.InsertIntegrationParams) (int64, error)
	UpdateIntegration(ctx context.Context, arg dbgen.UpdateIntegrationParams) error
	DeleteIntegration(ctx context.Context, arg dbgen.DeleteIntegrationParams) error
	ListIntegrationInfo(ctx context.Context, orgID int64) ([]dbgen.ListIntegrationInfoRow, error)
	InsertIntegrationToken(ctx context.Context, arg dbgen.InsertIntegrationTokenParams) (int64, error)
	EnsureIntegrationToken(ctx context.Context, arg dbgen.EnsureIntegrationTokenParams) (string, error)
	LockDemo(ctx context.Context, key int64) error
	ListIntegrationTokens(ctx context.Context, arg dbgen.ListIntegrationTokensParams) (
		[]dbgen.ListIntegrationTokensRow, error)
	RevokeIntegrationToken(ctx context.Context, arg dbgen.RevokeIntegrationTokenParams) (
		dbgen.RevokeIntegrationTokenRow, error)
	FindIngestToken(ctx context.Context, arg dbgen.FindIngestTokenParams) (dbgen.FindIngestTokenRow, error)
	TouchIntegrationToken(ctx context.Context, arg dbgen.TouchIntegrationTokenParams) error
	EnsureBuiltin(ctx context.Context, arg dbgen.EnsureBuiltinParams) (string, error)
	CountTruncatedGroupsOf(ctx context.Context, arg dbgen.CountTruncatedGroupsOfParams) (
		[]dbgen.CountTruncatedGroupsOfRow, error)
	ListLongRepeatRoutes(ctx context.Context, arg dbgen.ListLongRepeatRoutesParams) (
		[]dbgen.ListLongRepeatRoutesRow, error)
	audit.Store
	internalalerts.Store
	Notify(ctx context.Context, h db.Hint) error
}

Queries are the queries of the package, with the insert of the Audit log and the live hint.

type Requester

type Requester struct {
	Actor     audit.Actor
	Transport audit.Transport
	Address   netip.Addr
}

Requester is who asks for a change and how: the actor and the Transport of the Audit log entry, and the client address.

type Service

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

Service holds the Integrations and Integration tokens of the Organization.

func New

func New(cfg Config) *Service

New returns the Service of the Organization in cfg.

func (*Service) Authenticate

func (s *Service) Authenticate(ctx context.Context, value string) (Caller, error)

Authenticate finds who sends an ingestion request with the token value (C-05.FR-3): a token of an Integration that is not deleted, not revoked. Anything else is ErrInvalidToken, returned with the Caller whose Integration names the metric label: the token's Integration when the token is known — a revoked one included, so that an old token still in use is seen — and Unknown when it matches no Integration or only a deleted one (C-05.FR-4, P-10). The use of a token is recorded at most once a minute, off the request path, so that ingestion stays insert-only.

func (*Service) Create

func (s *Service) Create(ctx context.Context, r Requester, in Input) (Integration, error)

Create creates an Integration; a Heartbeat that is on waits for its first signal (C-07.FR-3). A name another Integration has is ErrNameTaken.

func (*Service) CreateToken

func (s *Service) CreateToken(ctx context.Context, r Requester, publicID, name string) (CreatedToken, error)

CreateToken issues a token of the Integration publicID with an optional name; the value and the Alertmanager snippet are returned once and only the hash is stored.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, r Requester, publicID string, version *int64) error

Delete deletes the Integration publicID; a non-nil version must be its current one. Its tokens stop working at once and it leaves every list; the row and its Stored Snapshots stay. The marker of the deletion goes into its queue in the same transaction: processing reaches it after the Stored Snapshots the Integration accepted before and then resolves its Alerts and Internal alerts (C-06.FR-16). The built-in Integration is ErrBuiltinImmutable.

func (*Service) EnsureDemo

func (s *Service) EnsureDemo(ctx context.Context, d Demo) error

EnsureDemo creates the demo Integration when no Integration that is not deleted has its name, and stores its token when it is missing, revoked or held by another Integration. Muster is the actor of what it writes.

func (*Service) Get

func (s *Service) Get(ctx context.Context, publicID string) (Integration, error)

Get reads the Integration publicID; a deleted or unknown one is ErrNotFound.

func (*Service) HeartbeatURL

func (s *Service) HeartbeatURL() string

HeartbeatURL is the Heartbeat endpoint without a token: MUSTER_INGEST_URL and /api/v1/heartbeat.

func (*Service) InfoChanged

func (s *Service) InfoChanged()

InfoChanged asks RunInfo to refresh muster_integration_info: a hint said an Integration changed, maybe on another replica. It never blocks.

func (*Service) IngestURL

func (s *Service) IngestURL() string

IngestURL is the ingestion endpoint: MUSTER_INGEST_URL and /api/v1/ingest.

func (*Service) List

func (s *Service) List(ctx context.Context, f ListFilter) (Page, error)

List lists the Integrations that are not deleted.

func (*Service) ListTokens

func (s *Service) ListTokens(ctx context.Context, publicID string) ([]Token, error)

ListTokens lists the tokens of the Integration publicID that are not revoked, the newest first.

func (*Service) RefreshInfo

func (s *Service) RefreshInfo(ctx context.Context) error

RefreshInfo makes muster_integration_info list exactly the Integrations that are not deleted, as the database has them, whichever replica changed them, and gives each Integration but the built-in one, which takes no token, its series of muster_ingest_requests_total; a deleted Integration loses them.

func (*Service) RevokeToken

func (s *Service) RevokeToken(ctx context.Context, r Requester, publicID, tokenID string) error

RevokeToken revokes the token tokenID of the Integration publicID: it answers 401 from the next request. A token of another Integration, an unknown or an already revoked one is ErrNotFound.

func (*Service) RunInfo

func (s *Service) RunInfo(ctx context.Context, ticks <-chan time.Time)

RunInfo keeps muster_integration_info current until ctx ends: it refreshes it at once, after InfoChanged and at every tick, which also repairs a refresh that failed.

func (*Service) RunTouches

func (s *Service) RunTouches(ctx context.Context)

RunTouches writes the queued uses of tokens to last_used_at until ctx ends. A failed write is dropped: the next use after a minute writes it again.

func (*Service) Update

func (s *Service) Update(ctx context.Context, r Requester, publicID string, version *int64, in Input) (Integration,
	error)

Update replaces the configured fields of the Integration publicID; a non-nil version must be its current one (If-Match). The built-in Integration is ErrBuiltinImmutable. A new name raises every open Internal alert about the Integration again with it, in the same transaction, so that its name label follows (C-06.AC-11). Turning the Heartbeat on makes it wait for its first signal; turning it off makes it not configured and resolves MusterHeartbeatLost while it is lost (C-07.FR-3).

type Store

type Store interface {
	Queries
	InTx(ctx context.Context, f func(Queries) error) error
}

Store runs the queries alone or in one transaction.

func NewStore

func NewStore(pool *pgxpool.Pool) Store

NewStore is the Store over the main pool.

type Token

type Token struct {
	ID         int64
	PublicID   string
	Name       string
	CreatedAt  time.Time
	LastUsedAt *time.Time
}

Token is an Integration token as the API lists it; its value is never kept.

type Warning

type Warning struct {
	Kind                  string
	TruncatedGroupCount   int64
	RoutePath             string
	RepeatIntervalSeconds int64
	Since                 *time.Time
}

Warning is a warning of an Integration: snapshot_truncated with the count of truncated groupKeys, long_repeat_interval with the Alertmanager route and its learned repeat interval, or one of the Heartbeat warnings, heartbeat_lost with the time of the last signal in Since.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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