Documentation ¶
Overview ¶
Package condition contains logical operators that, based on their configuration, return boolean values from messages under certain circumstances.
Index ¶
- Variables
- func Descriptions() string
- func DocumentPlugin(typeString, description string, configSanitiser PluginConfigSanitiser)
- func PluginCount() int
- func PluginDescriptions() string
- func RegisterPlugin(typeString string, configConstructor PluginConfigConstructor, ...)
- func SanitiseConfig(conf Config) (interface{}, error)
- type All
- type AllConfig
- type And
- type AndConfig
- type Any
- type AnyConfig
- type Bloblang
- type BloblangConfig
- type BoundsCheck
- type BoundsCheckConfig
- type CheckField
- type CheckFieldConfig
- type CheckInterpolation
- type CheckInterpolationConfig
- type Config
- type Count
- type CountConfig
- type JMESPath
- type JMESPathConfig
- type JSON
- type JSONConfig
- type JSONSchema
- type JSONSchemaConfig
- type Metadata
- type MetadataConfig
- type Not
- type NotConfig
- type Number
- type NumberConfig
- type Or
- type OrConfig
- type PluginConfigConstructor
- type PluginConfigSanitiser
- type PluginConstructor
- type ProcessorFailed
- type ProcessorFailedConfig
- type Resource
- type Static
- type Text
- type TextConfig
- type Type
- func New(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewAll(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewAnd(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewAny(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewBloblang(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewBoundsCheck(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewCheckField(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewCheckInterpolation(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewCount(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewJMESPath(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewJSON(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewJSONSchema(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewMetadata(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewNot(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewNumber(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewOr(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewProcessorFailed(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewResource(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewStatic(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewText(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewXor(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- type TypeSpec
- type Xor
- type XorConfig
Constants ¶
This section is empty.
Variables ¶
var ( TypeAll = "all" TypeAnd = "and" TypeAny = "any" TypeBloblang = "bloblang" TypeBoundsCheck = "bounds_check" TypeCheckField = "check_field" TypeCheckInterpolation = "check_interpolation" TypeCount = "count" TypeJMESPath = "jmespath" TypeJSON = "json" TypeJSONSchema = "json_schema" TypeNot = "not" TypeNumber = "number" TypeMetadata = "metadata" TypeOr = "or" TypeProcessorFailed = "processor_failed" TypeResource = "resource" TypeStatic = "static" TypeText = "text" TypeXor = "xor" )
String constants representing each condition type.
var Constructors = map[string]TypeSpec{}
Constructors is a map of all condition types with their specs.
var (
ErrInvalidMetadataOperator = errors.New("invalid metadata operator type")
)
Errors for the metadata condition.
var (
ErrInvalidNumberOperator = errors.New("invalid number operator type")
)
Errors for the number condition.
var (
ErrInvalidTextOperator = errors.New("invalid text operator type")
)
Errors for the text condition.
Functions ¶
func Descriptions ¶
func Descriptions() string
Descriptions returns a formatted string of collated descriptions of each type.
func DocumentPlugin ¶
func DocumentPlugin( typeString, description string, configSanitiser PluginConfigSanitiser, )
DocumentPlugin adds a description and an optional configuration sanitiser function to the definition of a registered plugin. This improves the documentation generated by PluginDescriptions.
func PluginCount ¶
func PluginCount() int
PluginCount returns the number of registered plugins. This does NOT count the standard set of components.
func PluginDescriptions ¶
func PluginDescriptions() string
PluginDescriptions generates and returns a markdown formatted document listing each registered plugin and an example configuration for it.
func RegisterPlugin ¶
func RegisterPlugin( typeString string, configConstructor PluginConfigConstructor, constructor PluginConstructor, )
RegisterPlugin registers a plugin by a unique name so that it can be constructed similar to regular conditions. If configuration is not needed for this plugin then configConstructor can be nil. A constructor for the plugin itself must be provided.
func SanitiseConfig ¶
SanitiseConfig returns a sanitised version of the Config, meaning sections that aren't relevant to behaviour are removed.
Types ¶
type All ¶
type All struct {
// contains filtered or unexported fields
}
All is a condition that returns the logical or of all children.
type AllConfig ¶
type AllConfig struct {
*Config `yaml:",inline" json:",inline"`
}
AllConfig is a configuration struct containing fields for the All condition.
func NewAllConfig ¶
func NewAllConfig() AllConfig
NewAllConfig returns a AllConfig with default values.
func (AllConfig) MarshalJSON ¶
MarshalJSON prints an empty object instead of nil.
func (AllConfig) MarshalYAML ¶
MarshalYAML prints an empty object instead of nil.
func (*AllConfig) UnmarshalJSON ¶
UnmarshalJSON ensures that when parsing child config it is initialised.
func (*AllConfig) UnmarshalYAML ¶
UnmarshalYAML ensures that when parsing child config it is initialised.
type And ¶
type And struct {
// contains filtered or unexported fields
}
And is a condition that returns the logical AND of all children.
type AndConfig ¶
type AndConfig []Config
AndConfig is a configuration struct containing fields for the And condition.
func NewAndConfig ¶
func NewAndConfig() AndConfig
NewAndConfig returns a AndConfig with default values.
type Any ¶
type Any struct {
// contains filtered or unexported fields
}
Any is a condition that returns the logical or of all children.
type AnyConfig ¶
type AnyConfig struct {
*Config `yaml:",inline" json:",inline"`
}
AnyConfig is a configuration struct containing fields for the Any condition.
func NewAnyConfig ¶
func NewAnyConfig() AnyConfig
NewAnyConfig returns a AnyConfig with default values.
func (AnyConfig) MarshalJSON ¶
MarshalJSON prints an empty object instead of nil.
func (AnyConfig) MarshalYAML ¶
MarshalYAML prints an empty object instead of nil.
func (*AnyConfig) UnmarshalJSON ¶
UnmarshalJSON ensures that when parsing child config it is initialised.
func (*AnyConfig) UnmarshalYAML ¶
UnmarshalYAML ensures that when parsing child config it is initialised.
type Bloblang ¶
type Bloblang struct {
// contains filtered or unexported fields
}
Bloblang is a condition that checks message against a Bloblang query.
type BloblangConfig ¶
type BloblangConfig string
BloblangConfig is a configuration struct containing fields for the bloblang condition.
func NewBloblangConfig ¶
func NewBloblangConfig() BloblangConfig
NewBloblangConfig returns a BloblangConfig with default values.
type BoundsCheck ¶
type BoundsCheck struct {
// contains filtered or unexported fields
}
BoundsCheck is a condition that checks a message against a set of bounds.
type BoundsCheckConfig ¶
type BoundsCheckConfig struct { MaxParts int `json:"max_parts" yaml:"max_parts"` MinParts int `json:"min_parts" yaml:"min_parts"` MaxPartSize int `json:"max_part_size" yaml:"max_part_size"` MinPartSize int `json:"min_part_size" yaml:"min_part_size"` }
BoundsCheckConfig contains configuration fields for the BoundsCheck condition.
func NewBoundsCheckConfig ¶
func NewBoundsCheckConfig() BoundsCheckConfig
NewBoundsCheckConfig returns a BoundsCheckConfig with default values.
type CheckField ¶
type CheckField struct {
// contains filtered or unexported fields
}
CheckField is a condition that extracts a field and checks the contents against a child condition.
type CheckFieldConfig ¶
type CheckFieldConfig struct { Parts []int `json:"parts" yaml:"parts"` Path string `json:"path" yaml:"path"` Condition *Config `json:"condition" yaml:"condition"` }
CheckFieldConfig contains configuration fields for the CheckField condition.
func NewCheckFieldConfig ¶
func NewCheckFieldConfig() CheckFieldConfig
NewCheckFieldConfig returns a CheckFieldConfig with default values.
func (CheckFieldConfig) MarshalJSON ¶
func (c CheckFieldConfig) MarshalJSON() ([]byte, error)
MarshalJSON prints an empty object instead of nil.
func (CheckFieldConfig) MarshalYAML ¶
func (c CheckFieldConfig) MarshalYAML() (interface{}, error)
MarshalYAML prints an empty object instead of nil.
type CheckInterpolation ¶
type CheckInterpolation struct {
// contains filtered or unexported fields
}
CheckInterpolation is a condition that resolves an interpolated string field and checks the contents against a child condition.
type CheckInterpolationConfig ¶
type CheckInterpolationConfig struct { Value string `json:"value" yaml:"value"` Condition *Config `json:"condition" yaml:"condition"` }
CheckInterpolationConfig contains configuration fields for the CheckInterpolation condition.
func NewCheckInterpolationConfig ¶
func NewCheckInterpolationConfig() CheckInterpolationConfig
NewCheckInterpolationConfig returns a CheckInterpolationConfig with default values.
func (CheckInterpolationConfig) MarshalJSON ¶
func (c CheckInterpolationConfig) MarshalJSON() ([]byte, error)
MarshalJSON prints an empty object instead of nil.
func (CheckInterpolationConfig) MarshalYAML ¶
func (c CheckInterpolationConfig) MarshalYAML() (interface{}, error)
MarshalYAML prints an empty object instead of nil.
type Config ¶
type Config struct { Type string `json:"type" yaml:"type"` All AllConfig `json:"all" yaml:"all"` And AndConfig `json:"and" yaml:"and"` Any AnyConfig `json:"any" yaml:"any"` Bloblang BloblangConfig `json:"bloblang" yaml:"bloblang"` BoundsCheck BoundsCheckConfig `json:"bounds_check" yaml:"bounds_check"` CheckField CheckFieldConfig `json:"check_field" yaml:"check_field"` CheckInterpolation CheckInterpolationConfig `json:"check_interpolation" yaml:"check_interpolation"` Count CountConfig `json:"count" yaml:"count"` JMESPath JMESPathConfig `json:"jmespath" yaml:"jmespath"` JSON JSONConfig `json:"json" yaml:"json"` JSONSchema JSONSchemaConfig `json:"json_schema" yaml:"json_schema"` Not NotConfig `json:"not" yaml:"not"` Number NumberConfig `json:"number" yaml:"number"` Metadata MetadataConfig `json:"metadata" yaml:"metadata"` Or OrConfig `json:"or" yaml:"or"` Plugin interface{} `json:"plugin,omitempty" yaml:"plugin,omitempty"` ProcessorFailed ProcessorFailedConfig `json:"processor_failed" yaml:"processor_failed"` Resource string `json:"resource" yaml:"resource"` Static bool `json:"static" yaml:"static"` Text TextConfig `json:"text" yaml:"text"` Xor XorConfig `json:"xor" yaml:"xor"` }
Config is the all encompassing configuration struct for all condition types.
func NewConfig ¶
func NewConfig() Config
NewConfig returns a configuration struct fully populated with default values.
type Count ¶
type Count struct {
// contains filtered or unexported fields
}
Count is a condition that counts each message and returns false once a target count has been reached, at which point it resets the counter and starts again.
type CountConfig ¶
type CountConfig struct {
Arg int `json:"arg" yaml:"arg"`
}
CountConfig is a configuration struct containing fields for the Count condition.
func NewCountConfig ¶
func NewCountConfig() CountConfig
NewCountConfig returns a CountConfig with default values.
type JMESPath ¶
type JMESPath struct {
// contains filtered or unexported fields
}
JMESPath is a condition that checks message against a jmespath query.
type JMESPathConfig ¶
type JMESPathConfig struct { Part int `json:"part" yaml:"part"` Query string `json:"query" yaml:"query"` }
JMESPathConfig is a configuration struct containing fields for the jmespath condition.
func NewJMESPathConfig ¶
func NewJMESPathConfig() JMESPathConfig
NewJMESPathConfig returns a JMESPathConfig with default values.
type JSON ¶
type JSON struct {
// contains filtered or unexported fields
}
JSON is a condition that checks JSON against a simple logic.
type JSONConfig ¶
type JSONConfig struct { Operator string `json:"operator" yaml:"operator"` Part int `json:"part" yaml:"part"` Path string `json:"path" yaml:"path"` Arg interface{} `json:"arg" yaml:"arg"` }
JSONConfig is a configuration struct containing fields for the JSON condition.
func NewJSONConfig ¶
func NewJSONConfig() JSONConfig
NewJSONConfig returns a JSONConfig with default values.
type JSONSchema ¶
type JSONSchema struct {
// contains filtered or unexported fields
}
JSONSchema is a condition that validates messages a specified JSONSchema.
type JSONSchemaConfig ¶
type JSONSchemaConfig struct { Part int `json:"part" yaml:"part"` SchemaPath string `json:"schema_path" yaml:"schema_path"` Schema string `json:"schema" yaml:"schema"` }
JSONSchemaConfig is a configuration struct containing fields for the jsonschema condition.
func NewJSONSchemaConfig ¶
func NewJSONSchemaConfig() JSONSchemaConfig
NewJSONSchemaConfig returns a JSONSchemaConfig with default values.
type Metadata ¶
type Metadata struct {
// contains filtered or unexported fields
}
Metadata is a condition that checks message text against logical operators.
type MetadataConfig ¶
type MetadataConfig struct { Operator string `json:"operator" yaml:"operator"` Part int `json:"part" yaml:"part"` Key string `json:"key" yaml:"key"` Arg interface{} `json:"arg" yaml:"arg"` }
MetadataConfig is a configuration struct containing fields for the metadata condition.
func NewMetadataConfig ¶
func NewMetadataConfig() MetadataConfig
NewMetadataConfig returns a MetadataConfig with default values.
type Not ¶
type Not struct {
// contains filtered or unexported fields
}
Not is a condition that returns the opposite of a child condition.
type NotConfig ¶
type NotConfig struct {
*Config `yaml:",inline" json:",inline"`
}
NotConfig is a configuration struct containing fields for the Not condition.
func NewNotConfig ¶
func NewNotConfig() NotConfig
NewNotConfig returns a NotConfig with default values.
func (NotConfig) MarshalJSON ¶
MarshalJSON prints an empty object instead of nil.
func (NotConfig) MarshalYAML ¶
MarshalYAML prints an empty object instead of nil.
func (*NotConfig) UnmarshalJSON ¶
UnmarshalJSON ensures that when parsing child config it is initialised.
func (*NotConfig) UnmarshalYAML ¶
UnmarshalYAML ensures that when parsing child config it is initialised.
type Number ¶
type Number struct {
// contains filtered or unexported fields
}
Number is a condition that checks messages interpretted as numbers against logical operators.
type NumberConfig ¶
type NumberConfig struct { Operator string `json:"operator" yaml:"operator"` Part int `json:"part" yaml:"part"` Arg float64 `json:"arg" yaml:"arg"` }
NumberConfig is a configuration struct containing fields for the number condition.
func NewNumberConfig ¶
func NewNumberConfig() NumberConfig
NewNumberConfig returns a NumberConfig with default values.
type Or ¶
type Or struct {
// contains filtered or unexported fields
}
Or is a condition that returns the logical or of all children.
type OrConfig ¶
type OrConfig []Config
OrConfig is a configuration struct containing fields for the Or condition.
type PluginConfigConstructor ¶
type PluginConfigConstructor func() interface{}
PluginConfigConstructor is a func that returns a pointer to a new and fully populated configuration struct for a plugin type.
type PluginConfigSanitiser ¶
type PluginConfigSanitiser func(conf interface{}) interface{}
PluginConfigSanitiser is a function that takes a configuration object for a plugin and returns a sanitised (minimal) version of it for printing in examples and plugin documentation.
This function is useful for when a plugins configuration struct is very large and complex, but can sometimes be expressed in a more concise way without losing the original intent.
type PluginConstructor ¶
type PluginConstructor func( config interface{}, manager types.Manager, logger log.Modular, metrics metrics.Type, ) (types.Condition, error)
PluginConstructor is a func that constructs a Benthos condition plugin. These are plugins that are specific to certain use cases, experimental, private or otherwise unfit for widespread general use. Any number of plugins can be specified when using Benthos as a framework.
The configuration object will be the result of the PluginConfigConstructor after overlaying the user configuration.
type ProcessorFailed ¶
type ProcessorFailed struct {
// contains filtered or unexported fields
}
ProcessorFailed is a condition that checks whether processing steps have failed for a message.
type ProcessorFailedConfig ¶
type ProcessorFailedConfig struct {
Part int `json:"part" yaml:"part"`
}
ProcessorFailedConfig is a configuration struct containing fields for the processor_failed condition.
func NewProcessorFailedConfig ¶
func NewProcessorFailedConfig() ProcessorFailedConfig
NewProcessorFailedConfig returns a ProcessorFailedConfig with default values.
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource is a condition that returns the result of a condition resource.
type Static ¶
type Static struct {
// contains filtered or unexported fields
}
Static is a condition that always returns a static boolean value.
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text is a condition that checks message text against logical operators.
type TextConfig ¶
type TextConfig struct { Operator string `json:"operator" yaml:"operator"` Part int `json:"part" yaml:"part"` Arg interface{} `json:"arg" yaml:"arg"` }
TextConfig is a configuration struct containing fields for the text condition.
func NewTextConfig ¶
func NewTextConfig() TextConfig
NewTextConfig returns a TextConfig with default values.
type Type ¶
type Type interface { // Check tests a message against a configured condition. Check(msg types.Message) bool }
Type reads a message, calculates a condition and returns a boolean.
func NewBloblang ¶
func NewBloblang( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewBloblang returns a Bloblang condition.
func NewBoundsCheck ¶
func NewBoundsCheck( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewBoundsCheck returns a BoundsCheck condition.
func NewCheckField ¶
func NewCheckField( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewCheckField returns a CheckField condition.
func NewCheckInterpolation ¶
func NewCheckInterpolation( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewCheckInterpolation returns a CheckInterpolation condition.
func NewJMESPath ¶
func NewJMESPath( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewJMESPath returns a JMESPath condition.
func NewJSONSchema ¶
func NewJSONSchema( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewJSONSchema returns a JSONSchema condition.
func NewMetadata ¶
func NewMetadata( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewMetadata returns a Metadata condition.
func NewNumber ¶
func NewNumber( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewNumber returns a number condition.
func NewProcessorFailed ¶
func NewProcessorFailed( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewProcessorFailed returns a ProcessorFailed condition.
func NewResource ¶
func NewResource( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewResource returns a resource condition.
func NewStatic ¶
func NewStatic( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewStatic returns a Static condition.
type TypeSpec ¶
type TypeSpec struct { Status docs.Status Summary string Description string Footnotes string FieldSpecs docs.FieldSpecs // contains filtered or unexported fields }
TypeSpec Constructor and a usage description for each condition type.