backplane

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2020 License: Apache-2.0 Imports: 21 Imported by: 2

Documentation

Overview

Package backplane allows you to create a Choria based management backplane for your application

Your application will live on the Choria network where it can be discovered and managed remotely on a very large scale with built in authentication, auditing and authorization.

You will be able to interact with your application from the Choria CLI, Ruby API or Go API and perform some or all of the below

* Circuit Breaker that can pause and resume your application * Healthchecks to query the internal health of your application * Shutdown the application

Additionally data about your application like it's configuration can be exposed to the Choria discovery subsystem

Index

Constants

This section is empty.

Variables

View Source
var Version = "development"

Version is the version of the management backplane

Functions

func AgentDDL

func AgentDDL() *agent.DDL

AgentDDL creates a DDL for the agent

func AgentMetadata

func AgentMetadata() *agents.Metadata

AgentMetadata returns the agent metadata

Types

type Authorization

type Authorization struct {
	// Insecure disables security and allow all callers to do anything
	Insecure bool `json:"insecure" yaml:"insecure"`

	// Full is a regex list of certnames that can perform changes like pause and resume
	Full []string `json:"full" yaml:"full"`

	// RO is a regex list of certnames that can request information from the service
	RO []string `json:"read_only" yaml:"read_only"`
}

Authorization lists certificate names that may access the backplane

func (*Authorization) FullAllowed

func (a *Authorization) FullAllowed(c string) bool

FullAllowed determines if this user can access all actions

func (*Authorization) ROAllowed

func (a *Authorization) ROAllowed(c string) bool

ROAllowed determines if this user can access read only action

type Config

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

Config configures the backplane

type ConfigProvider

type ConfigProvider interface {
	// MiddlewareHosts are hosts in host:port format to connect to
	MiddlewareHosts() []string

	// Name is a unique name for this backplane, similarly named backplanes are grouped together
	// and isolated from others.  Valid names are ^[a-z0-9]+.
	Name() string

	// LogFile is the file to use for logging the backplane related logs, "" means stdout
	LogFile() string

	// LogLevel is the logging level, one of debug, info, warn, error
	LogLevel() string

	// TLS is a TLS configuration, nil meaning disable security
	TLS() *TLSConf

	// Auth configured allow/deny lists of who may access the service
	Auth() Authorization
}

ConfigProvider provides management backplane configuration

type DataItem

type DataItem struct {
	// Data is the raw data to publish
	Data []byte

	// Destination let you set custom NATS targets, when this is not set
	// the TargetAgent will be used to create a normal agent target
	Destination string

	// TargetAgent lets you pick where to send the data as a request
	TargetAgent string
}

DataItem contains a single data message

type HealthCheckable

type HealthCheckable interface {
	// HealthCheck should return as its result a struct that can be JSON converted
	HealthCheck() (result interface{}, ok bool)
}

HealthCheckable describes a application that can be checked using the backplane

type HealthReply

type HealthReply struct {
	Result  json.RawMessage `json:"result"`
	Healthy bool            `json:"healthy"`
}

HealthReply is the reply from the health action

type InfoReply

type InfoReply struct {
	BackplaneVersion string      `json:"backplane_version"`
	Version          string      `json:"version"`
	Paused           bool        `json:"paused"`
	Facts            interface{} `json:"facts"`
	Healthy          bool        `json:"healthy"`
	LogLevel         string      `json:"loglevel"`
	HealthFeature    bool        `json:"healthcheck_feature"`
	PauseFeature     bool        `json:"pause_feature"`
	ShutdownFeature  bool        `json:"shutdown_feature"`
	FactsFeature     bool        `json:"facts_feature"`
	LogLevelFeature  bool        `json:"loglevel_feature"`
}

InfoReply is the reply from the info action

type InfoSource

type InfoSource interface {
	// FactData should return any data you wish to expose to the fact system, it should
	// be a JSON serializable struct and it's best if its a flat one with k=v pairs
	FactData() interface{}

	// Version is any version string of your application
	Version() string
}

InfoSource supplies fact data

type LogLevel

type LogLevel int8

LogLevel is a valid log level

const (

	// DebugLevel is developer level debugging information
	DebugLevel LogLevel = iota

	// InfoLevel is end user informative information
	InfoLevel

	// WarnLevel is end user warning information
	WarnLevel

	// CriticalLevel is end user critical information
	CriticalLevel
)

type LogLevelReply

type LogLevelReply struct {
	Level string `json:"level"`
}

LogLevelReply is the reply format from the log level actions

type LogLevelSetable

type LogLevelSetable interface {
	SetLogLevel(LogLevel)
	GetLogLevel() LogLevel
}

LogLevelSetable describes an application that can have its log levels adjusted at runtime

type Management

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

Management is a embeddable Choria based backplane for your Go application

func Run

func Run(ctx context.Context, wg *sync.WaitGroup, conf ConfigProvider, opts ...Option) (m *Management, err error)

Run creates a new instance of the backplane

func (*Management) DataOutbox

func (m *Management) DataOutbox() chan *DataItem

DataOutbox returns the channel to use for publishing data to the network from the backplane

func (*Management) StartRegistration

func (m *Management) StartRegistration(ctx context.Context, wg *sync.WaitGroup, interval int, output chan *data.RegistrationItem)

StartRegistration implements registration.RegistrationDataProvider

type Option

type Option func(*Config)

Option is a func that can configure the backplane

func FactWriteInterval

func FactWriteInterval(i time.Duration) Option

FactWriteInterval is the frequency that facts will be written to disk, 600 seconds is default

func ManageHealthCheck

func ManageHealthCheck(h HealthCheckable) Option

ManageHealthCheck supplies a class that can be health checked using the management agent, without supplying this the health action will not be available

func ManageInfoSource

func ManageInfoSource(f InfoSource) Option

ManageInfoSource configures a fact source for discovery data without supplying a info source only basic discoverable data will be provided

func ManageLogLevel

func ManageLogLevel(l LogLevelSetable) Option

ManageLogLevel supplies a class that can have its log level adjusted without supplying this the log level features are not enabled

func ManagePausable

func ManagePausable(p Pausable) Option

ManagePausable supplies a class that can be paused using the management agent without supplying a pausable the circuit breaker features are not enabled

func ManageStopable

func ManageStopable(s Stopable) Option

ManageStopable supplies a class that can be stopped using the management agent, without supplying this the stop action will not be available

func MaxStopDelay

func MaxStopDelay(i time.Duration) Option

MaxStopDelay is the maximum time to wait before calling stop

func StartDataPublisher

func StartDataPublisher() Option

StartDataPublisher starts a publisher for data to the Choria adapter system

type Pausable

type Pausable interface {
	// Pause should pause operations within your app immediately
	Pause()

	// Resume should resume operations within your app immediately
	Resume()

	// Flip should invert the pause state in an atomic manner
	Flip()

	// Should report the pause state
	Paused() bool
}

Pausable is a service that can be paused

type PausableReply

type PausableReply struct {
	Paused bool `json:"paused"`
}

PausableReply is the reply format expected from Pausable actions

type PingReply

type PingReply struct {
	Version string `json:"version"`
}

PingReply is the reply format from the ping action

type ShutdownReply

type ShutdownReply struct {
	Delay string `json:"delay"`
}

ShutdownReply is the reply from the shutdown action

type StandardConfiguration

type StandardConfiguration struct {
	Brokers       []string      `json:"brokers" yaml:"brokers"`
	AppName       string        `json:"name" yaml:"name"`
	LogFilePath   string        `json:"logfile" yaml:"logfile"`
	Loglevel      string        `json:"loglevel" yaml:"loglevel"`
	TLSConf       *TLSConf      `json:"tls" yaml:"tls"`
	Authorization Authorization `json:"auth" yaml:"auth"`
}

StandardConfiguration implements ConfigProvider you can use this as a helper in your own code to give users the ability to configure the backplane

func (*StandardConfiguration) Auth

Auth is the authorized certificates for the backplane

func (*StandardConfiguration) LogFile

func (s *StandardConfiguration) LogFile() string

LogFile is the file to log to

func (*StandardConfiguration) LogLevel

func (s *StandardConfiguration) LogLevel() string

LogLevel is the level to log at

func (*StandardConfiguration) MiddlewareHosts

func (s *StandardConfiguration) MiddlewareHosts() []string

MiddlewareHosts is the hosts that runs Choria Brokers in host:port format

func (*StandardConfiguration) Name

func (s *StandardConfiguration) Name() string

Name is a name for the application which will be used as a name for the collective the nodes are in

func (*StandardConfiguration) TLS

func (s *StandardConfiguration) TLS() *TLSConf

TLS is the TLS configuration

type Stopable

type Stopable interface {
	// Shutdown will be called after some delay and should exit the application
	Shutdown()
}

Stopable describes an application that can be stopped using the backplane

type TLSConf

type TLSConf struct {
	// Identity will be the certificate name to use when attempting to find certs and validate connections
	Identity string `json:"identity" yaml:"identity"`

	// SSLDir is where the puppet scheme will look for the standard Puppet format directories
	SSLDir string `json:"ssl_dir" yaml:"ssl_dir"`

	// Scheme is either puppet or manual
	Scheme string `json:"scheme" yaml:"scheme"`

	// CA sets the path to the ca file in the manual scheme
	CA string `json:"ca" yaml:"ca"`

	// Cert sets the path to the certificate file in the manual scheme
	Cert string `json:"cert" yaml:"cert"`

	// Key sets the path to the key file in the manual scheme
	Key string `json:"key" yaml:"key"`

	// Cache sets the path to the directory the manual scheme will use to store certificates received over the wire
	Cache string `json:"cache" yaml:"cache"`
}

TLSConf describes the TLS config for a NATS connection

Jump to

Keyboard shortcuts

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