agent

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: GPL-3.0 Imports: 17 Imported by: 2

README

menshen-agent

menshen-agent is the agent running on a host (bridge or gateway) which communicates with menshen in order to provide configuration information and allow for dynamic registration/inventory.

This should replace menshen_agent which we will deprecate and remove as this is deployed.

Design

Through the menshen agent endpoints and the agent here we intend to allow bridge and gateway hosts register themselves with menshen, provide their configuration information, and liveness.

Menshen can be configured with a lastSeenCutoffMillis property that, when set, will direct menshen to only return information about bridges and gateways that have been seen within the last lastSeenCutoffMillis time.

The bridge and gateway agents will send their information to the menshen agents every "heartbeat" time. As long as the heartbeat time is appropriately matched to the "last seen cutoff" time, this should ensure that menshen only hands out bridges+gateways which have demonstrated themselves to be recently alive.

Usage

The agent can be instantiated via the API or for gateways (in which we can't easily call into this library w/ go and instead need a sidecar) with the command line gateway-agent

To know how to instantiate via the API, see either the agent test or gateway-agent command line file for an example of how to instantiate, start, monitor, and stop the agent.

See the gateway-agent README for information on running it.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent[H models.ModelsBridge | models.ModelsGateway] struct {

	// ConfigMutex is a mutex for updating the config
	ConfigMutex *sync.RWMutex
	// contains filtered or unexported fields
}

func NewAgent

func NewAgent[H models.ModelsBridge | models.ModelsGateway](ctx context.Context, config Config[H]) *Agent[H]

NewAgent returns a new Agent for a Bridge or Gateway host

func (*Agent[H]) GetHosts added in v0.0.3

func (a *Agent[H]) GetHosts() []*H

func (*Agent[H]) SendHeartbeat

func (a *Agent[H]) SendHeartbeat() error

func (*Agent[H]) Start

func (a *Agent[H]) Start() error

Start starts the agent loop. It immediately returns an error in case of an error in starting. Otherwise it will listen to a.Context.Done() for terminating.

func (*Agent[H]) UpdateHost

func (a *Agent[H]) UpdateHost(host H, index int)

type Config

type Config[H models.ModelsBridge | models.ModelsGateway] struct {
	// Heartbeat is how often we want to send an update message to menshen with our configuration information
	// This needs to take into consideration how menshen is configured.
	Heartbeat time.Duration

	// Hosts is a slice of information about the hosts that the agent should send to menshen
	Hosts []*H

	// MenshenURL is the URL to send host info to ie "http://localhost:8080" or "https://example.com:443"
	MenshenURL *url.URL

	// Logger is a slog.Logger for the Agent to use for logging
	Logger *slog.Logger

	// PresharedKey is a key to be used for authenticating agent requests to menshen
	PresharedKey string

	// ErrorChan is a channel to return errors from our main loop on
	ErrorChan chan error

	// WG is a WaitGroup that allows waiting for the finish of the agent execution loop
	WG *sync.WaitGroup

	// Plugins is a list of "plugins" which provide transform functions for allowing user supplied host updates
	Plugins []plugins.Plugin[H]
}

Source Files

  • agent.go

Directories

Path Synopsis
cmd
gateway-agent command

Jump to

Keyboard shortcuts

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