server

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: Apache-2.0 Imports: 21 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
	// AgentReportingInterval determines how often to report connected agents.
	AgentReportingInterval = 10 * time.Second
	// AgentDisconnectInterval determines how often to disconnect agents that have not reported.
	AgentDisconnectInterval = 10 * time.Second
	// AgentDisconnectTTL must be greater than 2*AgentReportingInterval to avoid frequent disconnects
	AgentDisconnectTTL = 30 * time.Second
)
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
	// MeasurementBatcher retrieves the measurement batcher for batching agent metrics
	MeasurementBatcher() stats.MeasurementBatcher
	// 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) StartAgentDisconnect added in v1.23.0

func (m *DefaultManager) StartAgentDisconnect()

StartAgentDisconnect starts a goroutine that will disconnect agents that have not reported recently. It will stop once the ManagerCtx is closed

func (*DefaultManager) StartAgentReporting added in v1.23.0

func (m *DefaultManager) StartAgentReporting()

StartAgentReporting starts a goroutine that will report connected agents. It will stop once the ManagerCtx is closed

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) UpdateAgent added in v1.24.0

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

UpdateAgent updates an existing Agent in the Store

func (*DefaultManager) UpdateAgentStatus added in v1.26.0

func (m *DefaultManager) UpdateAgentStatus(ctx context.Context, agentID string, status model.AgentStatus) error

UpdateAgentStatus updates the status of an existing Agent in the 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)
	// UpdateAgent updates an existing Agent in the Store
	UpdateAgent(ctx context.Context, agentID string, updater store.AgentUpdater) (*model.Agent, error)
	// UpdateAgentStatus updates the status of an existing Agent in the Store
	UpdateAgentStatus(ctx context.Context, agentID string, status model.AgentStatus) 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 RelayLogs added in v1.17.0

type RelayLogs plog.Logs

RelayLogs is a wrapper around plog.Logs to allow easier JSON marshalling

func NewRelayLogs added in v1.17.0

func NewRelayLogs(t plog.Logs) RelayLogs

NewRelayLogs creates a new RelayLogs from the plog.Logs

func (RelayLogs) MarshalJSON added in v1.17.0

func (r RelayLogs) MarshalJSON() ([]byte, error)

MarshalJSON marshals to json using plog marshaller

func (RelayLogs) OTLP added in v1.17.0

func (r RelayLogs) OTLP() plog.Logs

OTLP returns the plog.Logs type

func (*RelayLogs) UnmarshalJSON added in v1.17.0

func (r *RelayLogs) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals from json using plog unmarshaller

type RelayMetrics added in v1.17.0

type RelayMetrics pmetric.Metrics

RelayMetrics is a wrapper around pmetric.Metrics to allow easier JSON marshalling

func NewRelayMetrics added in v1.17.0

func NewRelayMetrics(t pmetric.Metrics) RelayMetrics

NewRelayMetrics creates a new RelayMetrics from the pmetric.Metrics

func (RelayMetrics) MarshalJSON added in v1.17.0

func (r RelayMetrics) MarshalJSON() ([]byte, error)

MarshalJSON marshals to json using pmetric marshaller

func (RelayMetrics) OTLP added in v1.17.0

func (r RelayMetrics) OTLP() pmetric.Metrics

OTLP returns the pmetric.Metrics type

func (*RelayMetrics) UnmarshalJSON added in v1.17.0

func (r *RelayMetrics) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals from json using pmetric unmarshaller

type RelayTraces added in v1.17.0

type RelayTraces ptrace.Traces

RelayTraces is a wrapper around ptrace.Traces to allow easier JSON marshalling

func NewRelayTraces added in v1.17.0

func NewRelayTraces(t ptrace.Traces) RelayTraces

NewRelayTraces creates a new RelayTraces from the ptrace.Traces

func (RelayTraces) MarshalJSON added in v1.17.0

func (r RelayTraces) MarshalJSON() ([]byte, error)

MarshalJSON marshals to json using plog marshaller

func (RelayTraces) OTLP added in v1.17.0

func (r RelayTraces) OTLP() ptrace.Traces

OTLP returns the ptrace.Traces type

func (*RelayTraces) UnmarshalJSON added in v1.17.0

func (r *RelayTraces) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals from json using ptrace unmarshaller

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[RelayMetrics]
	Logs() Relayer[RelayLogs]
	Traces() Relayer[RelayTraces]
}

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