plugin

package
v0.13.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2016 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// SnapAll the wildcard for accepting all snap content types
	SnapAllContentType = "snap.*"
	// SnapGOB snap metrics serialized into go binary format
	SnapGOBContentType = "snap.gob"
	// SnapJSON snap metrics serialized into json
	SnapJSONContentType = "snap.json"
)

Variables

View Source
var (
	// Timeout settings
	// How much time must elapse before a lack of Ping results in a timeout
	PingTimeoutDurationDefault = time.Millisecond * 1500
	// How many successive PingTimeouts must occur to equal a failure.
	PingTimeoutLimit = 3
)

Functions

func CacheTTL

func CacheTTL(t time.Duration) metaOp

CacheTTL is an option that can be be provided to the func NewPluginMeta.

func ConcurrencyCount

func ConcurrencyCount(cc int) metaOp

ConcurrencyCount is an option that can be be provided to the func NewPluginMeta.

func Exclusive

func Exclusive(e bool) metaOp

Exclusive is an option that can be be provided to the func NewPluginMeta.

func MarshalPluginMetricTypes

func MarshalPluginMetricTypes(contentType string, metrics []PluginMetricType) ([]byte, string, error)

MarshalMetricTypes returns a []byte containing a serialized version of []PluginMetricType using the content type provided.

func NewRPCRequest

func NewRPCRequest(r io.Reader) *rpcRequest

NewRPCRequest returns a new rpcRequest.

func RoutingStrategy

func RoutingStrategy(r RoutingStrategyType) metaOp

RoutingStrategy is an option that can be be provided to the func NewPluginMeta.

func Start

func Start(m *PluginMeta, c Plugin, requestString string) (error, int)

Start starts a plugin where: PluginMeta - base information about plugin Plugin - either CollectorPlugin or PublisherPlugin requestString - plugins arguments (marshaled json of control/plugin Arg struct) returns an error and exitCode (exitCode from SessionState initilization or plugin termination code)

func SwapPluginMetricContentType

func SwapPluginMetricContentType(contentType, requestedContentType string, payload []byte) ([]byte, string, error)

SwapPluginMetricContentType swaps a payload with one content type to another one.

func Unsecure

func Unsecure(e bool) metaOp

Unsecure is an option that can be be provided to the func NewPluginMeta.

Types

type Arg

type Arg struct {
	// Plugin file path to binary
	PluginLogPath string
	// Ping timeout duration
	PingTimeoutDuration time.Duration

	NoDaemon bool
	// contains filtered or unexported fields
}

Arguments passed to startup of Plugin

func NewArg

func NewArg(logpath string) Arg

type CollectMetricsArgs

type CollectMetricsArgs struct {
	PluginMetricTypes []PluginMetricType
}

Arguments passed to CollectMetrics() for a Collector implementation

type CollectMetricsReply

type CollectMetricsReply struct {
	PluginMetrics []PluginMetricType
}

Reply assigned by a Collector implementation using CollectMetrics()

type CollectorPlugin

type CollectorPlugin interface {
	Plugin
	CollectMetrics([]PluginMetricType) ([]PluginMetricType, error)
	GetMetricTypes(PluginConfigType) ([]PluginMetricType, error)
}

Collector plugin

type ExecutablePlugin

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

A plugin that is executable as a forked process on *Linux.

func NewExecutablePlugin

func NewExecutablePlugin(a Arg, path string) (*ExecutablePlugin, error)

Initialize a new ExecutablePlugin from path to executable and daemon mode (true or false)

func (*ExecutablePlugin) ErrorResponseReader

func (e *ExecutablePlugin) ErrorResponseReader() io.Reader

The STDERR pipe for the plugin as a io.reader

func (*ExecutablePlugin) Kill

func (e *ExecutablePlugin) Kill() error

Kills the plugin and returns error if one occurred. This is blocking.

func (*ExecutablePlugin) ResponseReader

func (e *ExecutablePlugin) ResponseReader() io.Reader

The STDOUT pipe for the plugin as io.Reader. Use to read from plugin process STDOUT.

func (*ExecutablePlugin) Start

func (e *ExecutablePlugin) Start() error

Starts the plugin and returns error if one occurred. This is non blocking.

func (*ExecutablePlugin) WaitForExit

func (e *ExecutablePlugin) WaitForExit() error

Waits for plugin to halt. If error is returned then plugin stopped with error. If not plugin stopped safely.

func (*ExecutablePlugin) WaitForResponse

func (e *ExecutablePlugin) WaitForResponse(timeout time.Duration) (*Response, error)

Waits for a plugin response from a started plugin

type GetConfigPolicyArgs

type GetConfigPolicyArgs struct{}

type GetConfigPolicyReply

type GetConfigPolicyReply struct {
	Policy *cpolicy.ConfigPolicy
}

type GetMetricTypesArgs

type GetMetricTypesArgs struct {
	PluginConfig PluginConfigType
}

GetMetricTypesArgs args passed to GetMetricTypes

type GetMetricTypesReply

type GetMetricTypesReply struct {
	PluginMetricTypes []PluginMetricType
}

GetMetricTypesReply assigned by GetMetricTypes() implementation

type KillArgs

type KillArgs struct {
	Reason string
}

type PingArgs

type PingArgs struct{}

Arguments passed to ping

type Plugin

type Plugin interface {
	GetConfigPolicy() (*cpolicy.ConfigPolicy, error)
}

type PluginConfigType

type PluginConfigType struct {
	*cdata.ConfigDataNode
}

func NewPluginConfigType

func NewPluginConfigType() PluginConfigType

func (*PluginConfigType) GobDecode

func (p *PluginConfigType) GobDecode(data []byte) error

func (PluginConfigType) GobEncode

func (p PluginConfigType) GobEncode() ([]byte, error)

func (*PluginConfigType) UnmarshalJSON

func (p *PluginConfigType) UnmarshalJSON(data []byte) error

type PluginMeta

type PluginMeta struct {
	Name    string
	Version int
	Type    PluginType
	RPCType RPCType
	// AcceptedContentTypes are types accepted by this plugin in priority order.
	// snap.* means any snap type.
	AcceptedContentTypes []string
	// ReturnedContentTypes are content types returned in priority order.
	// This is only applicable on processors.
	ReturnedContentTypes []string
	// ConcurrencyCount is the max number concurrent calls the plugin may take.
	// If there are 5 tasks using the plugin and concurrency count is 2 there
	// will be 3 plugins running.
	ConcurrencyCount int
	// Exclusive results in a single instance of the plugin running regardless
	// the number of tasks using the plugin.
	Exclusive bool
	// Unsecure results in unencrypted communication with this plugin.
	Unsecure bool
	// CacheTTL will override the default cache TTL for the provided plugin.
	CacheTTL time.Duration
	// RoutingStrategy will override the routing strategy this plugin requires.
	// The default routing strategy round-robin.
	RoutingStrategy RoutingStrategyType
}

PluginMeta for plugin

func NewPluginMeta

func NewPluginMeta(name string, version int, pluginType PluginType, acceptContentTypes, returnContentTypes []string, opts ...metaOp) *PluginMeta

NewPluginMeta constructs and returns a PluginMeta struct

type PluginMetricType

type PluginMetricType struct {
	// Namespace is the identifier for a metric.
	Namespace_ []string `json:"namespace"`

	// Last advertised time is the last time the snap agent was told about
	// a metric.
	LastAdvertisedTime_ time.Time `json:"last_advertised_time"`

	// The metric version. It is bound to the Plugin version.
	Version_ int `json:"version"`

	// The config data needed to collect a metric.
	Config_ *cdata.ConfigDataNode `json:"config"`

	Data_ interface{} `json:"data"`

	// labels are pulled from dynamic metrics to provide context for the metric
	Labels_ []core.Label `json:"labels"`

	Tags_ map[string]string `json:"tags"`

	// The source of the metric (host, IP, etc).
	Source_ string `json:"source"`

	// The timestamp from when the metric was created.
	Timestamp_ time.Time `json:"timestamp"`
}

Represents a metric type. Only used within plugins and across plugin calls. Converted to core.MetricType before being used within modules.

func NewPluginMetricType

func NewPluginMetricType(namespace []string, timestamp time.Time, source string, tags map[string]string, labels []core.Label, data interface{}) *PluginMetricType

// PluginMetricType Constructor

func UnmarshallPluginMetricTypes

func UnmarshallPluginMetricTypes(contentType string, payload []byte) ([]PluginMetricType, error)

UnmarshallPluginMetricTypes takes a content type and []byte payload and returns a []PluginMetricType

func (*PluginMetricType) AddData

func (p *PluginMetricType) AddData(data interface{})

func (PluginMetricType) Config

Config returns the map of config data for this metric

func (PluginMetricType) Data

func (p PluginMetricType) Data() interface{}

func (PluginMetricType) Labels

func (p PluginMetricType) Labels() []core.Label

Labels returns the array of labels for this metric

func (PluginMetricType) LastAdvertisedTime

func (p PluginMetricType) LastAdvertisedTime() time.Time

Returns the last time this metric type was received from the plugin.

func (PluginMetricType) Namespace

func (p PluginMetricType) Namespace() []string

Returns the namespace.

func (PluginMetricType) Source

func (p PluginMetricType) Source() string

returns the source of the metric

func (PluginMetricType) Tags

func (p PluginMetricType) Tags() map[string]string

Tags returns the map of tags for this metric

func (PluginMetricType) Timestamp

func (p PluginMetricType) Timestamp() time.Time

returns the timestamp of when the metric was collected

func (PluginMetricType) Version

func (p PluginMetricType) Version() int

Returns the namespace.

type PluginResponseState

type PluginResponseState int

Plugin response states

const (
	PluginSuccess PluginResponseState = iota
	PluginFailure
)

type PluginType

type PluginType int

Plugin type

const (
	CollectorPluginType PluginType = iota
	ProcessorPluginType
	PublisherPluginType
)

func (PluginType) String

func (p PluginType) String() string

Returns string for matching enum plugin type

type ProcessorArgs

type ProcessorArgs struct {
	//PluginMetrics []PluginMetric
	ContentType string
	Content     []byte
	Config      map[string]ctypes.ConfigValue
}

type ProcessorPlugin

type ProcessorPlugin interface {
	Plugin
	Process(contentType string, content []byte, config map[string]ctypes.ConfigValue) (string, []byte, error)
}

Processor plugin

type ProcessorReply

type ProcessorReply struct {
	ContentType string
	Content     []byte
}

type PublishArgs

type PublishArgs struct {
	ContentType string
	Content     []byte
	Config      map[string]ctypes.ConfigValue
}

type PublishReply

type PublishReply struct {
}

type PublisherPlugin

type PublisherPlugin interface {
	Plugin
	Publish(contentType string, content []byte, config map[string]ctypes.ConfigValue) error
}

Publisher plugin

type RPCType

type RPCType int
const (
	NativeRPC RPCType = iota
	JSONRPC
)

type Response

type Response struct {
	Meta          PluginMeta
	ListenAddress string
	Token         string
	Type          PluginType
	// State is a signal from plugin to control that it passed
	// its own loading requirements
	State        PluginResponseState
	ErrorMessage string
	PublicKey    *rsa.PublicKey
}

Response from started plugin

type RoutingStrategyType

type RoutingStrategyType int
const (
	// DefaultRouting is a least recently used strategy.
	DefaultRouting RoutingStrategyType = iota
	// StickyRouting is a one-to-one strategy.
	// Using this strategy a tasks requests are sent to the same running instance of a plugin.
	StickyRouting
	// ConfigRouting is routing to plugins based on the config provided to the plugin.
	// Using this strategy enables a running database plugin that has the same connection info between
	// two tasks to be shared.
	ConfigRouting
)

func (RoutingStrategyType) String

func (p RoutingStrategyType) String() string

Returns string for matching enum RoutingStrategy type

type Session

type Session interface {
	Ping([]byte, *[]byte) error
	Kill([]byte, *[]byte) error
	GetConfigPolicy([]byte, *[]byte) error
	Logger() *log.Logger
	ListenAddress() string
	SetListenAddress(string)
	ListenPort() string
	Token() string
	KillChan() chan int
	ResetHeartbeat()

	SetKey(SetKeyArgs, *[]byte) error

	Encode(interface{}) ([]byte, error)
	Decode([]byte, interface{}) error
	// contains filtered or unexported methods
}

Session interface

type SessionState

type SessionState struct {
	*Arg
	*encrypter.Encrypter
	encoding.Encoder

	LastPing time.Time
	// contains filtered or unexported fields
}

Started plugin session state

func NewSessionState

func NewSessionState(pluginArgsMsg string, plugin Plugin, meta *PluginMeta) (*SessionState, error, int)

NewSessionState takes the plugin args and returns a SessionState returns State or error and returnCode: 0 - ok 2 - error when unmarshaling pluginArgs 3 - cannot open error files

func (*SessionState) GetConfigPolicy

func (s *SessionState) GetConfigPolicy(args []byte, reply *[]byte) error

GetConfigPolicy returns the plugin's policy

func (*SessionState) Kill

func (s *SessionState) Kill(args []byte, reply *[]byte) error

Kill will stop a running plugin

func (*SessionState) KillChan

func (s *SessionState) KillChan() chan int

KillChan gets the SessionState killchan

func (*SessionState) ListenAddress

func (s *SessionState) ListenAddress() string

ListenAddress gets the SessionState listen address

func (*SessionState) ListenPort

func (s *SessionState) ListenPort() string

ListenPort gets the SessionState listen port

func (*SessionState) Logger

func (s *SessionState) Logger() *log.Logger

Logger gets the SessionState logger

func (*SessionState) Ping

func (s *SessionState) Ping(arg []byte, reply *[]byte) error

Ping returns nothing in normal operation

func (*SessionState) ResetHeartbeat

func (s *SessionState) ResetHeartbeat()

func (*SessionState) SetKey

func (s *SessionState) SetKey(args SetKeyArgs, reply *[]byte) error

func (*SessionState) SetListenAddress

func (s *SessionState) SetListenAddress(a string)

SetListenAddress sets SessionState listen address

func (*SessionState) Token

func (s *SessionState) Token() string

Token gets the SessionState token

type SetKeyArgs

type SetKeyArgs struct {
	Key []byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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