Documentation
¶
Overview ¶
Package pluginsdk is the Watchtower plugin SDK (ADR-0036): a plugin is a separate process served over HashiCorp go-plugin (gRPC, MPL-2.0) that implements Source, Action and/or Filter.
Wire format: each RPC carries a google.protobuf.BytesValue holding the JSON of the request or response type (see proto/plugin.proto), so the SDK needs no generated code.
Index ¶
- Constants
- Variables
- func AllowedPayload(kind string) bool
- func ClientPlugins() plugin.PluginSet
- func Register(s grpc.ServiceRegistrar, impl any)
- func Serve(impl any)
- type Action
- type Field
- type Filter
- type Frame
- type Frames
- type Manifest
- type Outputs
- type Payload
- type Permissions
- type QueryRequest
- type Remote
- type RunRequest
- type SecretHeader
- type Source
Constants ¶
const ( PayloadNotification = "notification" PayloadWorkflow = "workflow" )
Payload kinds a Filter may see. The ingest hot path is deliberately not among them.
const ( KindSource = "source" KindAction = "action" KindFilter = "filter" )
Plugin kinds a manifest may declare.
const ( DefaultCPUMs = 1000 DefaultMemMB = 256 MaxMemMB = 2048 )
Defaults for the resource limits when the manifest leaves them 0.
const ( FrameTimeSeries = "timeseries" FrameTable = "table" FrameLogs = "logs" )
Frame kinds a Source may return.
const PluginKey = "plugin"
PluginKey is the go-plugin set key.
const ServiceName = "watchtower.plugin.v1.Plugin"
ServiceName is the gRPC service every plugin registers.
Variables ¶
var Handshake = plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "WT_PLUGIN",
MagicCookieValue: "watchtower-plugin-v1",
}
Handshake is shared by the SDK and the runner; the cookie only stops accidental execution.
Functions ¶
func AllowedPayload ¶
AllowedPayload reports whether a filter may be applied to this payload kind.
func ClientPlugins ¶
ClientPlugins is the plugin set for a go-plugin client (the runner).
func Register ¶
func Register(s grpc.ServiceRegistrar, impl any)
Register adds the plugin service for impl to a gRPC server.
Types ¶
type Action ¶
type Action interface {
Describe() Manifest
Run(ctx context.Context, req RunRequest) (Outputs, error)
}
Action is a workflow step, addressed as `plugin:<name>.<action>`.
type Filter ¶
type Filter interface {
Describe() Manifest
Process(ctx context.Context, p Payload) (Payload, error)
}
Filter rewrites notification and workflow payloads before they are sent or run.
type Frame ¶
type Frame struct {
Name string `json:"name"`
Kind string `json:"kind"`
Fields []Field `json:"fields"`
}
Frame is a time series, table or log result.
type Manifest ¶
type Manifest struct {
Name string `yaml:"name" json:"name"`
Version string `yaml:"version" json:"version"`
Kinds []string `yaml:"kinds" json:"kinds"`
ConfigSchema map[string]any `yaml:"config_schema" json:"config_schema,omitempty"`
Permissions Permissions `yaml:"permissions" json:"permissions"`
}
Manifest is plugin.yaml.
func ParseManifest ¶
ParseManifest decodes and validates plugin.yaml.
type Payload ¶
Payload is a notification or workflow payload; Kind is PayloadNotification or PayloadWorkflow.
type Permissions ¶
type Permissions struct {
// EgressHosts are the only hosts the plugin may call (through the runner's egress proxy).
EgressHosts []string `yaml:"egress_hosts" json:"egress_hosts"`
// SecretRefs name the secrets the egress proxy may inject; the plugin never sees values.
SecretRefs []string `yaml:"secret_refs" json:"secret_refs"`
// SecretHeaders say where the egress proxy puts a secret: Header = Prefix + secret(Ref) on
// requests to Host. Ref must be in SecretRefs and Host in EgressHosts.
SecretHeaders []SecretHeader `yaml:"secret_headers" json:"secret_headers"`
MaxCPUMs int `yaml:"max_cpu_ms" json:"max_cpu_ms"`
MaxMemMB int `yaml:"max_mem_mb" json:"max_mem_mb"`
}
Permissions are what the runner grants the plugin: nothing else is reachable.
type QueryRequest ¶
type QueryRequest struct {
Query string `json:"query"`
From time.Time `json:"from"`
To time.Time `json:"to"`
Step time.Duration `json:"step"`
Vars map[string]string `json:"vars,omitempty"`
}
QueryRequest is one data-source query. Vars are the dashboard variable values.
type Remote ¶
type Remote struct {
// contains filtered or unexported fields
}
Remote is the client side of the service (used by the runner).
func NewRemote ¶
func NewRemote(cc grpc.ClientConnInterface) *Remote
NewRemote wraps a connection to a plugin.
func (*Remote) Process ¶
Process runs a Filter; payload kinds other than notification and workflow are refused here before they cross the process boundary.
type RunRequest ¶
type RunRequest struct {
Inputs map[string]any `json:"inputs"`
SecretsRefs []string `json:"secrets_refs,omitempty"`
}
RunRequest is one workflow action call. SecretsRefs name secrets (never values): the runner's egress proxy injects them into outbound requests the plugin makes.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
hello_source
command
Command hello_source is the smallest data-source plugin.
|
Command hello_source is the smallest data-source plugin. |
|
sources
|
|
|
graphite
command
Command graphite is the Graphite data source: a panel's query is "<host>|<target>".
|
Command graphite is the Graphite data source: a panel's query is "<host>|<target>". |
|
influxdb
command
Command influxdb is the InfluxDB data source: a panel's query is "<host>|<db>|<InfluxQL>", with $timeFilter in its WHERE, or "<host>|flux:<org>|<Flux>" (InfluxDB 2), with v.timeRangeStart and v.timeRangeStop in its range().
|
Command influxdb is the InfluxDB data source: a panel's query is "<host>|<db>|<InfluxQL>", with $timeFilter in its WHERE, or "<host>|flux:<org>|<Flux>" (InfluxDB 2), with v.timeRangeStart and v.timeRangeStop in its range(). |
|
opentsdb
command
Command opentsdb is the OpenTSDB data source: a panel's query is "<host>|sum:metric{tag=value}".
|
Command opentsdb is the OpenTSDB data source: a panel's query is "<host>|sum:metric{tag=value}". |
|
tsdb
Package tsdb has the query paths of the InfluxDB, Graphite and OpenTSDB source plugins: each builds its request, and turns the answer into time series frames.
|
Package tsdb has the query paths of the InfluxDB, Graphite and OpenTSDB source plugins: each builds its request, and turns the answer into time series frames. |