plugin

package
v0.16.1-beta Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2016 License: Apache-2.0 Imports: 28 Imported by: 527

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 MarshalMetricTypes

func MarshalMetricTypes(contentType string, metrics []MetricType) ([]byte, string, error)

MarshalMetricTypes returns a []byte containing a serialized version of []MetricType 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 - CollectorPlugin, ProcessorPlugin 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 SwapMetricContentType

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

SwapMetricContentType 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 log level
	LogLevel log.Level
	// Ping timeout duration
	PingTimeoutDuration time.Duration

	NoDaemon bool
	// contains filtered or unexported fields
}

Arguments passed to startup of Plugin

func NewArg

func NewArg(logLevel int) Arg

type CollectMetricsArgs

type CollectMetricsArgs struct {
	MetricTypes []MetricType
}

Arguments passed to CollectMetrics() for a Collector implementation

type CollectMetricsReply

type CollectMetricsReply struct {
	PluginMetrics []MetricType
}

Reply assigned by a Collector implementation using CollectMetrics()

type CollectorPlugin

type CollectorPlugin interface {
	Plugin
	CollectMetrics([]MetricType) ([]MetricType, error)
	GetMetricTypes(ConfigType) ([]MetricType, error)
}

Collector plugin

type ConfigType

type ConfigType struct {
	*cdata.ConfigDataNode
}

func NewPluginConfigType

func NewPluginConfigType() ConfigType

func (*ConfigType) GobDecode

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

func (ConfigType) GobEncode

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

func (*ConfigType) UnmarshalJSON

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

type ExecutablePlugin

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

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) Kill

func (e *ExecutablePlugin) Kill() error

func (*ExecutablePlugin) Run

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

Run executes the plugin and waits for a response, or times out.

type GetConfigPolicyArgs

type GetConfigPolicyArgs struct{}

type GetConfigPolicyReply

type GetConfigPolicyReply struct {
	Policy *cpolicy.ConfigPolicy
}

type GetMetricTypesArgs

type GetMetricTypesArgs struct {
	PluginConfig ConfigType
}

GetMetricTypesArgs args passed to GetMetricTypes

type GetMetricTypesReply

type GetMetricTypesReply struct {
	MetricTypes []MetricType
}

GetMetricTypesReply assigned by GetMetricTypes() implementation

type KillArgs

type KillArgs struct {
	Reason string
}

type MetricType

type MetricType struct {
	// Namespace is the identifier for a metric.
	Namespace_ []core.NamespaceElement `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"`

	// Tags are key value pairs that can be added by the framework or any
	// plugin along the collect -> process -> publish pipeline.
	Tags_ map[string]string `json:"tags"`

	// Unit represents the unit of magnitude of the measured quantity.
	// See http://metrics20.org/spec/#units as a guideline for this
	// field.
	Unit_ string

	// A (long) description for the metric.  The description is stored on the
	// metric catalog and not sent through  collect -> process -> publish.
	Description_ string `json:"description"`

	// 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 NewMetricType

func NewMetricType(namespace core.Namespace, timestamp time.Time, tags map[string]string, unit string, data interface{}) *MetricType

NewMetricType returns a Constructor

func UnmarshallMetricTypes

func UnmarshallMetricTypes(contentType string, payload []byte) ([]MetricType, error)

UnmarshallMetricTypes takes a content type and []byte payload and returns a []MetricType

func (*MetricType) AddData

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

func (MetricType) Config

func (p MetricType) Config() *cdata.ConfigDataNode

Config returns the map of config data for this metric

func (MetricType) Data

func (p MetricType) Data() interface{}

returns the data for the metric

func (MetricType) Description

func (p MetricType) Description() string

returns the description of the metric

func (MetricType) LastAdvertisedTime

func (p MetricType) LastAdvertisedTime() time.Time

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

func (MetricType) Namespace

func (p MetricType) Namespace() core.Namespace

Returns the namespace.

func (MetricType) Tags

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

Tags returns the map of tags for this metric

func (MetricType) Timestamp

func (p MetricType) Timestamp() time.Time

returns the timestamp of when the metric was collected

func (MetricType) Unit

func (p MetricType) Unit() string

returns the metrics unit

func (MetricType) Version

func (p MetricType) Version() int

Returns the namespace.

type PingArgs

type PingArgs struct{}

Arguments passed to ping

type Plugin

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

type PluginMeta

type PluginMeta struct {
	Name       string
	Version    int
	Type       PluginType
	RPCType    RPCType
	RPCVersion int
	// 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 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
	GRPC
)

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

	DecryptKey([]byte) ([]byte, 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
Package rpc is a generated protocol buffer package.
Package rpc is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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