pluginsdk

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	PayloadNotification = "notification"
	PayloadWorkflow     = "workflow"
)

Payload kinds a Filter may see. The ingest hot path is deliberately not among them.

View Source
const (
	KindSource = "source"
	KindAction = "action"
	KindFilter = "filter"
)

Plugin kinds a manifest may declare.

View Source
const (
	DefaultCPUMs = 1000
	DefaultMemMB = 256
	MaxMemMB     = 2048
)

Defaults for the resource limits when the manifest leaves them 0.

View Source
const (
	FrameTimeSeries = "timeseries"
	FrameTable      = "table"
	FrameLogs       = "logs"
)

Frame kinds a Source may return.

View Source
const PluginKey = "plugin"

PluginKey is the go-plugin set key.

View Source
const ServiceName = "watchtower.plugin.v1.Plugin"

ServiceName is the gRPC service every plugin registers.

Variables

View Source
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

func AllowedPayload(kind string) bool

AllowedPayload reports whether a filter may be applied to this payload kind.

func ClientPlugins

func ClientPlugins() plugin.PluginSet

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.

func Serve

func Serve(impl any)

Serve runs the plugin; impl may implement any of Source, Action and Filter. It blocks.

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 Field

type Field struct {
	Name   string `json:"name"`
	Values []any  `json:"values"`
}

Field is one column; Values has one entry per row (numbers, strings, RFC 3339 times).

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 Frames

type Frames struct {
	Frames []Frame `json:"frames"`
}

Frames is a Source's answer.

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

func ParseManifest(b []byte) (Manifest, error)

ParseManifest decodes and validates plugin.yaml.

func (Manifest) Has

func (m Manifest) Has(kind string) bool

Has reports whether the manifest declares the kind.

func (*Manifest) Validate

func (m *Manifest) Validate() error

Validate checks names, kinds and limits, and fills the limit defaults.

type Outputs

type Outputs map[string]any

Outputs are the action's results, available to later workflow steps.

type Payload

type Payload struct {
	Kind string         `json:"kind"`
	Body map[string]any `json:"body"`
}

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

func (r *Remote) Describe(ctx context.Context) (Manifest, error)

Describe returns the plugin's manifest.

func (*Remote) Process

func (r *Remote) Process(ctx context.Context, p Payload) (Payload, error)

Process runs a Filter; payload kinds other than notification and workflow are refused here before they cross the process boundary.

func (*Remote) Query

func (r *Remote) Query(ctx context.Context, q QueryRequest) (Frames, error)

Query runs a Source query.

func (*Remote) Run

func (r *Remote) Run(ctx context.Context, q RunRequest) (Outputs, error)

Run runs an Action.

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.

type SecretHeader

type SecretHeader struct {
	Host   string `yaml:"host" json:"host"`
	Header string `yaml:"header" json:"header"`
	Ref    string `yaml:"ref" json:"ref"`
	Prefix string `yaml:"prefix" json:"prefix,omitempty"`
}

SecretHeader is one credential injection rule of the egress proxy.

type Source

type Source interface {
	Describe() Manifest
	Query(ctx context.Context, req QueryRequest) (Frames, error)
}

Source answers queries for dashboards.

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.

Jump to

Keyboard shortcuts

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