plugin

package
v0.0.0-...-c764e65 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: Apache-2.0 Imports: 26 Imported by: 223

Documentation

Index

Constants

View Source
const (
	LRURouter router = iota
	StickyRouter
	ConfigBasedRouter
)

Variables

View Source
var (
	// ErrEmptyKey is returned when a Rule with an empty key is created
	ErrEmptyKey = fmt.Errorf("Key cannot be Empty")

	// ErrConfigNotFound is returned when a config doesn't exist in the config map
	ErrConfigNotFound = fmt.Errorf("config item not found")

	// ErrNotA<type> is returned when the found config item doesn't have the expected type
	ErrNotAString = fmt.Errorf("config item is not a string")
	ErrNotAnInt   = fmt.Errorf("config item is not an int64")
	ErrNotABool   = fmt.Errorf("config item is not a boolean")
	ErrNotAFloat  = fmt.Errorf("config item is not a float64")
)
View Source
var (

	// ListenAddr the address that GRPC will listen on.  Plugin authors can also
	// use this address if their plugin binds to a local port as it's sometimes
	// needed to bind to a public interface.
	ListenAddr = "127.0.0.1"

	LogLevel = 2
)
View Source
var (

	// PingTimeoutLimit is the number of successively missed ping health
	// checks which must occur before the plugin is stopped
	PingTimeoutLimit = 3
	// PingTimeoutDuration is the duration during which a ping healthcheck
	// should be received
	PingTimeoutDuration = 3 * time.Second
)
View Source
var App *cli.App
View Source
var (

	// Flags required by the plugin lib flags - plugin authors can provide their
	// own flags.  Checkout https://github.com/intelsdi-x/snap-plugin-lib-go/blob/master/examples/snap-plugin-collector-rand/rand/rand.go
	// for an example of a plugin adding a custom flag.
	Flags []cli.Flag = []cli.Flag{
		flConfig,
		flAddr,
		flPort,
		flPprof,
		flTLS,
		flCertPath,
		flKeyPath,
		flRootCertPaths,
		flStandAlone,
		flHTTPPort,
		flLogLevel,
		flMaxCollectDuration,
		flMaxMetricsBuffer,
	}
)

Functions

func SetDefaultBool

func SetDefaultBool(in bool) boolRuleOpt

SetDefaultBool Allows easy setting of the Default value for an rpc.BoolRule. Usage:

AddNewBoolRule(ns, key, req, config.SetDefaultBool(default))

func SetDefaultFloat

func SetDefaultFloat(in float64) floatRuleOpt

SetDefaultFloat Allows easy setting of the Default value for an rpc.FloatRule. Usage:

AddNewFloatRule(ns, key, req, config.SetDefaultFloat(default))

func SetDefaultInt

func SetDefaultInt(in int64) integerRuleOpt

SetDefaultInt Allows easy setting of the Default value for an rpc.IntegerRule. Usage:

AddNewIntegerRule(ns, key, req, config.SetDefaultInt(default))

func SetDefaultString

func SetDefaultString(in string) stringRuleOpt

SetDefaultString Allows easy setting of the Default value for an rpc.StringRule. Usage:

AddNewStringRule(ns, key, req, config.SetDefaultString(default))

func SetMaxFloat

func SetMaxFloat(max float64) floatRuleOpt

SetMaxFloat Allows easy setting of the Max value for an rpc.FloatRule. Usage:

AddNewFloatRule(ns, key, req, config.SetMaxFloat(max))

func SetMaxInt

func SetMaxInt(max int64) integerRuleOpt

SetMaxInt Allows easy setting of the Max value for an rpc.IntegerRule. Usage:

AddNewIntegerRule(ns, key, req, config.SetMaxInt(max))

func SetMinFloat

func SetMinFloat(min float64) floatRuleOpt

SetMinFloat Allows easy setting of the Min value for an rpc.FloatRule. Usage:

AddNewFloatRule(ns, key, req, config.SetMinFloat(min))

func SetMinInt

func SetMinInt(min int64) integerRuleOpt

SetMinInt Allows easy setting of the Min value for an rpc.IntegerRule. Usage:

AddNewIntegerRule(ns, key, req, config.SetMinInt(min))

func StartCollector

func StartCollector(plugin Collector, name string, version int, opts ...MetaOpt) int

StartCollector is given a Collector implementation and its metadata, generates a response for the initial stdin / stdout handshake, and starts the plugin's gRPC server.

func StartProcessor

func StartProcessor(plugin Processor, name string, version int, opts ...MetaOpt) int

StartProcessor is given a Processor implementation and its metadata, generates a response for the initial stdin / stdout handshake, and starts the plugin's gRPC server.

func StartPublisher

func StartPublisher(plugin Publisher, name string, version int, opts ...MetaOpt) int

StartPublisher is given a Publisher implementation and its metadata, generates a response for the initial stdin / stdout handshake, and starts the plugin's gRPC server.

func StartStreamCollector

func StartStreamCollector(plugin StreamCollector, name string, version int, opts ...MetaOpt) int

StartStreamCollector is given a StreamCollector implementation and its metadata, generates a response for the initial stdin / stdout handshake, and starts the plugin's gRPC server.

Types

type Arg

type Arg struct {
	// Plugin log level, see logrus.Loglevel
	LogLevel int
	// Ping timeout duration
	PingTimeoutDuration time.Duration

	// The listen port
	ListenPort string

	// enable pprof
	Pprof bool

	// Path to TLS certificate file for a TLS server
	CertPath string

	// Path to TLS private key file for a TLS server
	KeyPath string

	// Paths to root certificates
	RootCertPaths string

	// Flag requesting server to establish TLS channel
	TLSEnabled bool

	MaxCollectDuration string
	MaxMetricsBuffer   int64
}

Arg represents arguments passed to startup of Plugin

type Collector

type Collector interface {
	Plugin

	GetMetricTypes(Config) ([]Metric, error)
	CollectMetrics([]Metric) ([]Metric, error)
}

Collector is a plugin which is the source of new data in the Snap pipeline.

type Config

type Config map[string]interface{}

Config is a type alias for map[string]interface{} to allow the helper functions Get{String,Bool,Float,Int} to be defined.

func NewConfig

func NewConfig() Config

NewConfig returns initialized Config

func (Config) GetBool

func (c Config) GetBool(key string) (bool, error)

GetBool takes a given key and checks the config for both that the key exists, and that it is of type bool. Returns an error if either of these is false.

func (Config) GetFloat

func (c Config) GetFloat(key string) (float64, error)

GetFloat takes a given key and checks the config for both that the key exists, and that it is of type float64. Returns an error if either of these is false.

func (Config) GetInt

func (c Config) GetInt(key string) (int64, error)

GetInt takes a given key and checks the config for both that the key exists, and that it is of type int64. Returns an error if either of these is false.

func (Config) GetString

func (c Config) GetString(key string) (string, error)

GetString takes a given key and checks the config for both that the key exists, and that it is of type string. Returns an error if either of these is false.

type ConfigPolicy

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

func NewConfigPolicy

func NewConfigPolicy() *ConfigPolicy

func (*ConfigPolicy) AddNewBoolRule

func (c *ConfigPolicy) AddNewBoolRule(ns []string, key string, req bool, opts ...boolRuleOpt) error

AddNewBoolRule adds a new boolRule with the specified args to the boolRules map. The required arguments are ns([]string), key(string), req(bool) and optionally:

plugin.SetDefaultBool(bool)

func (*ConfigPolicy) AddNewFloatRule

func (c *ConfigPolicy) AddNewFloatRule(ns []string, key string, req bool, opts ...floatRuleOpt) error

AddNewFloatRule adds a new floatRule with the specified args to the floatRules map. The required arguments are ns([]string), key(string), req(bool) and optionally:

plugin.SetDefaultFloat(float64),
plugin.SetMinFloat(float64),
plugin.SetMaxFloat(float64),

func (*ConfigPolicy) AddNewIntRule

func (c *ConfigPolicy) AddNewIntRule(ns []string, key string, req bool, opts ...integerRuleOpt) error

AddNewIntegerRule adds a new integerRule with the specified args to the integerRules map. The required arguments are ns([]string), key(string), req(bool) and optionally:

plugin.SetDefaultInt(int64),
plugin.SetMinInt(int64),
plugin.SetMaxInt(int64),

func (*ConfigPolicy) AddNewStringRule

func (c *ConfigPolicy) AddNewStringRule(ns []string, key string, req bool, opts ...stringRuleOpt) error

AddNewStringRule adds a new stringRule with the specified args to the stringRules map. The required arguments are ns([]string), key(string), req(bool) and optionally:

plugin.SetDefaultString(string)

type MetaOpt

type MetaOpt func(m *meta)

MetaOpt is used to apply optional metadata on a plugin

func CacheTTL

func CacheTTL(t time.Duration) MetaOpt

CacheTTL will override the default cache TTL for the this plugin. snapteld caches metrics on the daemon side for a default of 500ms. CacheTTL overwrites the default (500ms) for a Meta's CacheTTL.

func ConcurrencyCount

func ConcurrencyCount(cc int) MetaOpt

ConcurrencyCount is the max number of concurrent calls the plugin should take. For example: If there are 5 tasks using the plugin and its concurrency count is 2, snapteld will keep 3 plugin instances running. ConcurrencyCount overwrites the default (5) for a Meta's ConcurrencyCount.

func Exclusive

func Exclusive(e bool) MetaOpt

Exclusive == true results in a single instance of the plugin running regardless of the number of tasks using the plugin. Exclusive overwrites the default (false) for a Meta's Exclusive key.

func GRPCServerOptions

func GRPCServerOptions(options ...grpc.ServerOption) MetaOpt

func RoutingStrategy

func RoutingStrategy(r router) MetaOpt

RoutingStrategy will override the routing strategy this plugin requires. The default routing strategy is Least Recently Used. RoutingStrategy overwrites the default (LRU) for a Meta's RoutingStrategy.

type Metric

type Metric struct {
	Namespace   Namespace
	Version     int64
	Config      Config
	Data        interface{}
	Tags        map[string]string
	Timestamp   time.Time
	Unit        string
	Description string
	// contains filtered or unexported fields
}

Metric contains all info related to a Snap Metric

type Namespace

type Namespace []NamespaceElement

func CopyNamespace

func CopyNamespace(src Namespace) Namespace

CopyNamespace copies array of namespace elements to new array

func NewNamespace

func NewNamespace(ns ...string) Namespace

Newnamespace takes an array of strings and returns a namespace. A namespace is an array of namespaceElements. The provided array of strings is used to set the corresponding Value fields in the array of namespaceElements.

func (Namespace) AddDynamicElement

func (n Namespace) AddDynamicElement(name, description string) Namespace

AddDynamicElement adds a dynamic element to the given Namespace. A dynamic namespaceElement is defined by having a nonempty Name field.

func (Namespace) AddStaticElement

func (n Namespace) AddStaticElement(value string) Namespace

AddStaticElement adds a static element to the given Namespace. A static namespaceElement is defined by having an empty Name field.

func (Namespace) AddStaticElements

func (n Namespace) AddStaticElements(values ...string) Namespace

AddStaticElements adds a static elements to the given Namespace. A static namespaceElement is defined by having an empty Name field.

func (Namespace) Element

func (n Namespace) Element(idx int) NamespaceElement

func (Namespace) IsDynamic

func (n Namespace) IsDynamic() (bool, []int)

IsDynamic returns true if there is any element of the namespace which is dynamic. If the namespace is dynamic the second return value will contain an array of namespace elements (indexes) where there are dynamic namespace elements. A dynamic component of the namespace are those elements that contain variable data.

func (Namespace) String

func (n Namespace) String() string

String returns the string representation of the namespace with "/" joining the elements of the namespace. A leading "/" is added.

func (Namespace) Strings

func (n Namespace) Strings() []string

Strings returns an array of strings that represent the elements of the namespace.

type NamespaceElement

type NamespaceElement struct {
	Value       string
	Description string
	Name        string
}

namespaceElement provides meta data related to the namespace. This is of particular importance when the namespace contains data.

func NewNamespaceElement

func NewNamespaceElement(e string) NamespaceElement

NewNamespaceElement tasks a string and returns a namespaceElement where the Value field is set to the provided string argument.

func (*NamespaceElement) IsDynamic

func (n *NamespaceElement) IsDynamic() bool

IsDynamic returns true if the namespace element contains data. A namespace element that has a nonempty Name field is considered dynamic.

type OSInputOutput

type OSInputOutput interface {
	// contains filtered or unexported methods
}

osInputOutput supports interactions with OS for the plugin lib

type Plugin

type Plugin interface {
	GetConfigPolicy() (ConfigPolicy, error)
}

Plugin is the base plugin type. All plugins must implement GetConfigPolicy.

type Processor

type Processor interface {
	Plugin

	Process([]Metric, Config) ([]Metric, error)
}

Processor is a plugin which filters, aggregates, or decorates data in the Snap pipeline.

type Publisher

type Publisher interface {
	Plugin

	Publish([]Metric, Config) error
}

Publisher is a sink in the Snap pipeline. It publishes data into another System, completing a Workflow path.

type StreamCollector

type StreamCollector interface {
	Plugin

	// StreamMetrics allows the plugin to send/receive metrics on a channel
	// Arguments are (in order):
	//
	// A channel for metrics into the plugin from Snap -- which
	// are the metric types snap is requesting the plugin to collect.
	//
	// A channel for metrics from the plugin to Snap -- the actual
	// collected metrics from the plugin.
	//
	// A channel for error strings that the library will report to snap
	// as task errors.
	StreamMetrics(context.Context, chan []Metric, chan []Metric, chan string) error
	GetMetricTypes(Config) ([]Metric, error)
}

StreamCollector is a Collector that can send back metrics within configurable limits defined in task manifest. These limits might be determined by user by set a value of:

  • `max-metrics-buffer`, default to 0 what means no buffering and sending reply with streaming metrics immediately
  • `max-collect-duration`, default to 10s what means after 10s no new metrics are received, send a reply whatever data it has in buffer instead of waiting longer

type StreamProxy

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

func (*StreamProxy) GetConfigPolicy

func (p *StreamProxy) GetConfigPolicy(ctx context.Context, arg *rpc.Empty) (*rpc.GetConfigPolicyReply, error)

func (*StreamProxy) GetMetricTypes

func (p *StreamProxy) GetMetricTypes(ctx context.Context, arg *rpc.GetMetricTypesArg) (*rpc.MetricsReply, error)

func (*StreamProxy) HeartbeatWatch

func (p *StreamProxy) HeartbeatWatch()

func (*StreamProxy) Kill

func (p *StreamProxy) Kill(ctx context.Context, arg *rpc.KillArg) (*rpc.ErrReply, error)

func (*StreamProxy) Ping

func (p *StreamProxy) Ping(ctx context.Context, arg *rpc.Empty) (*rpc.ErrReply, error)

func (*StreamProxy) StreamMetrics

func (p *StreamProxy) StreamMetrics(stream rpc.StreamCollector_StreamMetricsServer) error

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