outputs

package
v0.49.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AddTargetOverwrite always sets Prefix.Target from the target template.
	AddTargetOverwrite = "overwrite"
	// AddTargetIfNotPresent sets Prefix.Target from the target template only
	// when the received message has an empty target.
	AddTargetIfNotPresent = "if-not-present"
)

Variables

View Source
var (
	DefaultTargetTemplate = template.Must(
		template.New("target-template").
			Funcs(TemplateFuncs).
			Parse(defaultTargetTemplateString))

	TemplateFuncs = template.FuncMap{
		"host": utils.GetHost,
	}
)
View Source
var OutputTypes = map[string]struct{}{
	"asciigraph":       {},
	"clickhouse":       {},
	"file":             {},
	"influxdb":         {},
	"kafka":            {},
	"nats":             {},
	"otlp":             {},
	"prometheus":       {},
	"prometheus_write": {},
	"tcp":              {},
	"udp":              {},
	"gnmi":             {},
	"jetstream":        {},
	"snmp":             {},
}
View Source
var Outputs = map[string]Initializer{}

Functions

func AddSubscribeResponseTarget

func AddSubscribeResponseTarget(rsp *gnmi.SubscribeResponse, meta Meta, addTarget string, tpl *template.Template) (*gnmi.SubscribeResponse, error)

AddSubscribeResponseTarget sets the Prefix.Target of a SubscribeResponse update according to addTarget (see AddTargetOverwrite and AddTargetIfNotPresent), using tpl rendered with meta as the target value.

Responses that need no change (addTarget empty or unknown, sync-responses, updates that already carry a target with AddTargetIfNotPresent) are returned as they were received: the function never returns nil for a non-nil input. When the response is modified, the input is left untouched and a modified copy is returned. On template error the original response is returned along with the error.

func AddSubscriptionTarget

func AddSubscriptionTarget(msg proto.Message, meta Meta, addTarget string, tpl *template.Template) (proto.Message, error)

AddSubscriptionTarget is the proto.Message form of AddSubscribeResponseTarget. Messages that are not a *gnmi.SubscribeResponse are returned as they were received: the function never returns a nil message for a non-nil input.

func BindLogger added in v0.46.0

func BindLogger(parent *slog.Logger, outputType, name string) *slog.Logger

BindLogger returns a non-nil *slog.Logger annotated with the output kind and instance name. Centralises the

if options.Logger != nil { o.logger = options.Logger.With(...) }

boilerplate that every output used to repeat. When parent is nil, a discarding logger is returned so callers never need a nil check.

func DecodeConfig

func DecodeConfig(src, dst any) error

DecodeConfig decodes an output configuration map into dst.

On top of the mapstructure decoding, it validates the fields shared by several output types (currently `add-target`), so that a typo in one of them is rejected at load time instead of silently changing the output behavior at runtime.

func ExecTemplate

func ExecTemplate(content []byte, tpl *template.Template) ([]byte, error)

func Marshal

func Marshal(pmsg protoreflect.ProtoMessage, meta map[string]string, mo *formatters.MarshalOptions, splitEvents bool, evps ...formatters.EventProcessor) ([][]byte, error)

func Register

func Register(name string, initFn Initializer)

func UpdateProcessorInSlice added in v0.43.0

func UpdateProcessorInSlice(
	logger *slog.Logger,
	storeObj store.Store[any],
	eventProcessors []string,
	currentEvps []formatters.EventProcessor,
	processorName string,
	pcfg map[string]any,
) ([]formatters.EventProcessor, bool, error)

func ValidateAddTarget

func ValidateAddTarget(v any) error

ValidateAddTarget checks the value of an output `add-target` field. An empty string (or nil) disables the feature and is valid.

Types

type BaseOutput added in v0.42.1

type BaseOutput struct {
}

func (*BaseOutput) Close added in v0.42.1

func (b *BaseOutput) Close() error

func (*BaseOutput) Init added in v0.42.1

func (b *BaseOutput) Init(context.Context, string, map[string]any, ...Option) error

func (*BaseOutput) String added in v0.42.1

func (b *BaseOutput) String() string

func (*BaseOutput) Update added in v0.43.0

func (b *BaseOutput) Update(context.Context, map[string]any) error

func (*BaseOutput) UpdateProcessor added in v0.43.0

func (b *BaseOutput) UpdateProcessor(string, map[string]any) error

func (*BaseOutput) Validate added in v0.43.0

func (b *BaseOutput) Validate(map[string]any) error

func (*BaseOutput) Write added in v0.42.1

func (*BaseOutput) WriteEvent added in v0.42.1

func (b *BaseOutput) WriteEvent(context.Context, *formatters.EventMsg)

type Initializer

type Initializer func() Output

type Meta

type Meta map[string]string

type Option

type Option func(*OutputOptions) error

func WithClusterName

func WithClusterName(name string) Option

func WithConfigStore added in v0.43.0

func WithConfigStore(st store.Store[any]) Option

func WithLogger

func WithLogger(logger *slog.Logger) Option

func WithName

func WithName(name string) Option

func WithRegistry

func WithRegistry(reg *prometheus.Registry) Option

type Output

type Output interface {
	// initialize the output
	Init(context.Context, string, map[string]any, ...Option) error
	// validate the config
	Validate(map[string]any) error
	// update the config
	Update(context.Context, map[string]any) error
	// update a processor
	UpdateProcessor(string, map[string]any) error
	// write a protobuf message to the output
	Write(context.Context, proto.Message, Meta)
	// write an event message to the output
	WriteEvent(context.Context, *formatters.EventMsg)
	// close the output
	Close() error
	// return a string representation of the output
	String() string
}

type OutputOptions added in v0.42.1

type OutputOptions struct {
	Name        string
	ClusterName string
	Logger      *slog.Logger
	Registry    *prometheus.Registry
	Store       store.Store[any]
}

type ProtoMsg

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

func NewProtoMsg

func NewProtoMsg(m proto.Message, meta Meta) *ProtoMsg

func (*ProtoMsg) GetMeta

func (m *ProtoMsg) GetMeta() Meta

func (*ProtoMsg) GetMsg

func (m *ProtoMsg) GetMsg() proto.Message

Jump to

Keyboard shortcuts

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