// Package component describes the interfaces which Flow components implement.1//2// A Flow component is a distinct piece of business logic that accepts inputs3// (Arguments) for its configuration and can optionally export a set of outputs4// (Exports).5//6// Arguments and Exports do not need to be static for the lifetime of a7// component. A component will be given a new Config if the runtime8// configuration changes. A component may also update its Exports throughout9// its lifetime, such as a component which outputs the current day of the week.10//11// Components are built by users with River, where they can use River12// expressions to refer to any input or exported field from other components.13// This allows users to connect components together to declaratively form a14// pipeline.15//16// # Defining Arguments and Exports structs17//18// Arguments and Exports implemented by new components must be able to be19// encoded to and from River. "river" struct field tags are used for encoding;20// refer to the package documentation at pkg/river for a description of how to21// write these tags.22//23// The set of River element names of a given component's Arguments and Exports24// types must not overlap. Additionally, the following River field and block25// names are reserved for use by the Flow controller:26//27// - for_each28// - enabled29// - health30// - debug31//32// Default values for Arguments may be provided by implementing33// river.Unmarshaler.34//35// # Arguments and Exports immutability36//37// Arguments passed to a component should be treated as immutable, as memory38// can be shared between components as an optimization. Components should make39// copies for fields they need to modify. An exception to this is for fields40// which are expected to be mutable (e.g., interfaces which expose a41// goroutine-safe API).42//43// Similarly, Exports and the fields within Exports must be considered44// immutable after they are written for the same reason.45//46// # Mapping River strings to custom types47//48// Custom encoding and decoding of fields is available by implementing49// encoding.TextMarshaler and encoding.TextUnmarshaler. Types implementing50// these interfaces will be represented as strings in River.51//52// # Component registration53//54// Components are registered globally by calling Register. These components are55// then made available by including them in the import path. The "all" child56// package imports all known component packages and should be updated when57// creating a new one.58package component5960import (61"context"62"net/http"63)6465// The Arguments contains the input fields for a specific component, which is66// unmarshaled from River.67//68// Refer to the package documentation for details around how to build proper69// Arguments implementations.70type Arguments interface{}7172// Exports contains the current set of outputs for a specific component, which73// is then marshaled to River.74//75// Refer to the package documentation for details around how to build proper76// Exports implementations.77type Exports interface{}7879// Component is the base interface for a Flow component. Components may80// implement extension interfaces (named <Extension>Component) to implement81// extra known behavior.82type Component interface {83// Run starts the component, blocking until ctx is canceled or the component84// suffers a fatal error. Run is guaranteed to be called exactly once per85// Component.86//87// Implementations of Component should perform any necessary cleanup before88// returning from Run.89Run(ctx context.Context) error9091// Update provides a new Config to the component. The type of newConfig will92// always match the struct type which the component registers.93//94// Update will be called concurrently with Run. The component must be able to95// gracefully handle updating its config while still running.96//97// An error may be returned if the provided config is invalid.98Update(args Arguments) error99}100101// DebugComponent is an extension interface for components which can report102// debugging information upon request.103type DebugComponent interface {104Component105106// DebugInfo returns the current debug information of the component. May107// return nil if there is no debug info to currently report. The result of108// DebugInfo must be encodable to River like Arguments and Exports.109//110// Values from DebugInfo are not exposed to other components for use in111// expressions.112//113// DebugInfo must be safe for calling concurrently.114DebugInfo() interface{}115}116117// HTTPComponent is an extension interface for components which contain their own HTTP handlers.118type HTTPComponent interface {119Component120121// Handler should return a valid HTTP handler for the component.122// All requests to the component will have the path trimmed such that the component is at the root.123// For example, f a request is made to `/component/{id}/metrics`, the component124// will receive a request to just `/metrics`.125Handler() http.Handler126}127128// ClusteredComponent is an extension interface for components which implement129// clustering-specific behavior.130type ClusteredComponent interface {131Component132133ClusterUpdatesRegistration() bool134}135136137