server

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package server contains the Manager interface

Index

Constants

View Source
const (
	// AgentCleanupTTL is the default agent cleanup time to live.
	AgentCleanupTTL = 15 * time.Minute
	// AgentCleanupInterval is the default agent cleanup interval.
	AgentCleanupInterval = time.Minute
)
View Source
const (
	// AgentMessageTypeSnapshot is the type of message that is sent to an agent to request a snapshot
	AgentMessageTypeSnapshot = "snapshot"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentMessage

type AgentMessage struct {
	AgentIDField string         `json:"agent_id"`
	TypeField    string         `json:"type"`
	BodyField    map[string]any `json:"body"`
}

AgentMessage is a message that is sent to an agent

func (AgentMessage) AgentID

func (m AgentMessage) AgentID() string

AgentID returns the agent ID of the message

func (AgentMessage) Body

func (m AgentMessage) Body() map[string]interface{}

Body returns the body of the message

func (AgentMessage) Type

func (m AgentMessage) Type() string

Type returns the type of the message

type BindPlane

type BindPlane interface {
	// Store TODO(doc)
	Store() store.Store
	// Manager TODO(doc)
	Manager() Manager
	// Relayer enables Live messages to flow from Agents to GraphQL subscriptions
	Relayers() Relayers
	// Versions TODO(doc)
	Versions() agent.Versions
	// Logger TODO(doc)
	Logger() *zap.Logger
	// BindPlaneURL returns the URL of the BindPlane server
	BindPlaneURL() string
	// BindPlaneInsecureSkipVerify returns true if the BindPlane server should be contacted without verifying the server's certificate chain and host name
	BindPlaneInsecureSkipVerify() bool
	// WebsocketURL returns the URL of the BindPlane server's websocket endpoint
	WebsocketURL() string
	// SecretKey returns the secret key used to authenticate agents with the BindPlane server
	SecretKey() string

	// Authenticator returns the authenticator for validating user credentials
	Authenticator() authenticator.Authenticator
}

BindPlane is the interface for the BindPlane Server

type DefaultManager

type DefaultManager struct {
	Messages      broadcast.Broadcast[Message]
	CancelManager context.CancelCauseFunc
	ManagerCtx    context.Context

	Storage   store.Store
	Versions  agent.Versions
	Logger    *zap.Logger
	Protocols []protocol.Protocol
	SecretKey string
	// contains filtered or unexported fields
}

DefaultManager is the default implementation of the Manager

func (*DefaultManager) Agent

func (m *DefaultManager) Agent(ctx context.Context, agentID string) (*model.Agent, error)

Agent returns the agent with the specified agentID.

func (*DefaultManager) AgentMessages

func (m *DefaultManager) AgentMessages(_ context.Context) eventbus.Source[Message]

AgentMessages returns a source of messages for agents, broadcast from all nodes

func (*DefaultManager) AgentUpdates

func (m *DefaultManager) AgentUpdates(ctx context.Context, agent *model.Agent) (*protocol.AgentUpdates, error)

AgentUpdates returns the updates that should be applied to an agent based on the current bindplane configuration

func (*DefaultManager) AgentVersion

func (m *DefaultManager) AgentVersion(ctx context.Context, version string) (*model.AgentVersion, error)

AgentVersion returns information about a version of an agent

func (*DefaultManager) BindPlaneInsecureSkipVerify

func (m *DefaultManager) BindPlaneInsecureSkipVerify() bool

BindPlaneInsecureSkipVerify returns true if the BindPlane server should be contacted without verifying the server's certificate chain and host name

func (*DefaultManager) BindPlaneURL

func (m *DefaultManager) BindPlaneURL() string

BindPlaneURL returns the URL of the BindPlane server

func (*DefaultManager) EnableProtocol

func (m *DefaultManager) EnableProtocol(protocol protocol.Protocol)

EnableProtocol adds the protocol to the manager

func (*DefaultManager) RequestReport

func (m *DefaultManager) RequestReport(ctx context.Context, agentID string, configuration protocol.Report) error

RequestReport sends report configuration to the specified agent

func (*DefaultManager) ResourceStore

func (m *DefaultManager) ResourceStore() model.ResourceStore

ResourceStore provides access to the store to render configurations

func (*DefaultManager) SendAgentMessage

func (m *DefaultManager) SendAgentMessage(ctx context.Context, message Message) error

SendAgentMessage sends a message to an agent

func (*DefaultManager) Shutdown

func (m *DefaultManager) Shutdown(ctx context.Context) error

Shutdown should disconnect all agents and is called before shutdown of the server

func (*DefaultManager) Start

func (m *DefaultManager) Start(ctx context.Context)

Start starts the manager and concurrently running jobs

func (*DefaultManager) StartCleanupAgents

func (m *DefaultManager) StartCleanupAgents()

StartCleanupAgents starts a goroutine that will handle agent cleanup. It will stop once the ManagerCtx is closed

func (*DefaultManager) Store

func (m *DefaultManager) Store() store.Store

Store provides access to the BindPlane Store

func (*DefaultManager) UpsertAgent

func (m *DefaultManager) UpsertAgent(ctx context.Context, agentID string, updater store.AgentUpdater) (*model.Agent, error)

UpsertAgent adds a new Agent to the Store or updates an existing one

func (*DefaultManager) VerifySecretKey

func (m *DefaultManager) VerifySecretKey(ctx context.Context, secretKey string) (context.Context, bool)

VerifySecretKey checks to see if the specified secretKey matches configured secretKey. If the BindPlane server does not have a configured secretKey, this returns true. This implementation doesn't use or modify the context, but it is included to match the interface.

type Manager

type Manager interface {
	// EnableProtocol adds the protocol to the manager
	EnableProtocol(protocol.Protocol)
	// Agent returns the agent with the specified agentID.
	Agent(ctx context.Context, agentID string) (*model.Agent, error)
	// UpsertAgent adds a new Agent to the Store or updates an existing one
	UpsertAgent(ctx context.Context, agentID string, updater store.AgentUpdater) (*model.Agent, error)
	// AgentUpdates returns the updates that should be applied to an agent based on the current bindplane configuration
	AgentUpdates(ctx context.Context, agent *model.Agent) (*protocol.AgentUpdates, error)
	// VerifySecretKey checks to see if the specified secretKey matches configured secretKey
	VerifySecretKey(ctx context.Context, secretKey string) (context.Context, bool)
	// ResourceStore provides access to the store to render configurations
	ResourceStore() model.ResourceStore
	// BindPlaneURL returns the URL of the BindPlane server
	BindPlaneURL() string
	// BindPlaneInsecureSkipVerify returns true if the BindPlane server should be contacted without verifying the server's certificate chain and host name
	BindPlaneInsecureSkipVerify() bool
	// RequestReport sends report configuration to the specified agent
	RequestReport(ctx context.Context, agentID string, configuration protocol.Report) error
	// AgentVersion returns information about a version of an agent
	AgentVersion(ctx context.Context, version string) (*model.AgentVersion, error)
	// Store provides access to the BindPlane Store
	Store() store.Store
	// SendAgentMessage sends a message to an agent
	SendAgentMessage(ctx context.Context, message Message) error
	// AgentMessages returns a source of messages for agents, broadcast from all nodes
	AgentMessages(ctx context.Context) eventbus.Source[Message]
	// Start starts the manager
	Start(ctx context.Context)
	// Shutdown should disconnect all agents and is called before shutdown of the server
	Shutdown(context.Context) error
}

Manager manages agent connects and communications with them

func NewManager

func NewManager(cfg *config.Config, store store.Store, versions agent.Versions, logger *zap.Logger) Manager

NewManager returns a new implementation of the Manager interface

type Message

type Message interface {
	AgentID() string
	Type() string
	Body() map[string]interface{}
}

Message is a message that is sent to an agent

type Relayer

type Relayer[T any] interface {
	AwaitResult() (id string, result <-chan T, cancelFunc func())
	SendResult(id string, result T)
}

Relayer forwards results to consumers awaiting the results. It is intentionally generic and is used to support cases where the request for results is decoupled from the response with the results.

type Relayers

type Relayers interface {
	Metrics() Relayer[pmetric.Metrics]
	Logs() Relayer[plog.Logs]
	Traces() Relayer[ptrace.Traces]
}

Relayers is a wrapper around multiple Relayer instances used for different types of results

type RouteBuilder

type RouteBuilder interface {
	// AddRoutes adds routes to the passed in router
	AddRoutes(gin.IRouter, BindPlane) error
}

RouteBuilder builds routes for a given router

type Scheduler

type Scheduler interface {
	// Start starts the scheduler which will begin executing background tasks.
	Start(context.Context)

	// Stop stops the scheduler
	Stop(context.Context) error
}

Scheduler schedules periodic background tasks

func NewScheduler

func NewScheduler(s store.Store, logger *zap.Logger, interval time.Duration) Scheduler

NewScheduler creates a new scheduler

type SnapshotBody

type SnapshotBody struct {
	Configuration protocol.Report `json:"configuration" mapstructure:"configuration"`
}

SnapshotBody is the body of a snapshot message

type Updater

type Updater interface {
	// Start starts the updater
	Start(context.Context)

	// Stop stops the updater and can be called when there are no agents connected to free up resources.
	Stop(context.Context)
}

Updater listens to store.Updates events and synchronizes agents and configurations.

Directories

Path Synopsis
Package protocol defines communication to agents
Package protocol defines communication to agents

Jump to

Keyboard shortcuts

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