heartbeat

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 6 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 heartbeat writes the registration of a component that is not an agent, for example the controller or the NATS server, to the registry KV bucket.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heartbeat

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

Heartbeat writes ComponentRegistration to the registry KV on a configurable interval.

func New

func New(
	logger *slog.Logger,
	opts Options,
) *Heartbeat

New creates a heartbeat writer for a component that is not an agent.

func (*Heartbeat) Start

func (h *Heartbeat) Start(
	ctx context.Context,
)

Start begins writing heartbeats. It writes an initial registration immediately, then refreshes on each tick. On context cancellation it deregisters and returns.

type Options

type Options struct {
	// KV writes the registration.
	KV RegistryStore
	// RegistryBucket is the KV bucket that gets the registration.
	RegistryBucket string
	// Hostname is the host that the component runs on.
	Hostname string
	// Version is the version of the component.
	Version string
	// Component is the kind of component, for example controller or nats.
	Component string
	// Process reads the CPU and the memory of the process.
	Process process.Provider
	// Interval is the time between two registrations.
	Interval time.Duration
	// Thresholds tell when the process reports a condition.
	Thresholds process.ConditionThresholds
	// SubComponents are the parts of the component that the registration names.
	SubComponents map[string]job.SubComponentInfo
}

Options describe the component that a Heartbeat registers.

type RegistryStore

type RegistryStore interface {
	KVPut(ctx context.Context, bucket string, key string, value []byte) (uint64, error)
	KVDelete(ctx context.Context, bucket string, key string) error
}

RegistryStore writes and removes a registration in a KV bucket. A *natsclient.Client is one.

Directories

Path Synopsis
Package mocks holds the generated doubles of the interfaces of package heartbeat, for its tests.
Package mocks holds the generated doubles of the interfaces of package heartbeat, for its tests.

Jump to

Keyboard shortcuts

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