Documentation ¶
Index ¶
- Constants
- Variables
- func GetFromObject(obj map[string]any, field string) any
- func ReflectConfig(confraw ConfigRaw, conf any) (err error)
- func RegistCodecHandler(name string, handler CodecHandler)
- func RegistFilterHandler(name string, handler FilterHandler)
- func RegistInputHandler(name string, handler InputHandler)
- func RegistOutputHandler(name string, handler OutputHandler)
- type CodecConfig
- type CodecHandler
- type CommonConfig
- type Config
- func (t *Config) PauseSignal() <-chan struct{}
- func (t *Config) RequestPause(ctx context.Context) error
- func (t *Config) RequestResume(ctx context.Context) error
- func (t *Config) ResumeSignal() <-chan struct{}
- func (t *Config) Start(ctx context.Context) (err error)
- func (t *Config) TestGetOutputEvent(timeout time.Duration) (event logevent.LogEvent, err error)
- func (t *Config) TestInputEvent(event logevent.LogEvent)
- func (t *Config) Wait() (err error)
- type ConfigRaw
- type Control
- type DefaultCodec
- func (c *DefaultCodec) Decode(ctx context.Context, data any, eventExtra map[string]any, tags []string, ...) (ok bool, err error)
- func (c *DefaultCodec) DecodeEvent(data []byte, event *logevent.LogEvent) error
- func (c *DefaultCodec) Encode(ctx context.Context, event logevent.LogEvent, dataChan chan<- []byte) (ok bool, err error)
- type FieldConfig
- type FilterConfig
- type FilterHandler
- type InputConfig
- type InputHandler
- type MsgChan
- type OutputConfig
- type OutputHandler
- type TypeCodecConfig
- type TypeCommonConfig
- type TypeFilterConfig
- type TypeInputConfig
- type TypeOutputConfig
Constants ¶
const DefaultCodecName = "default"
DefaultCodecName default codec name
const DefaultErrorTag = "gogstash_codec_default_error"
DefaultErrorTag tag added to event when process module failed
Variables ¶
var ( ErrorUnknownCodecType1 = errutil.NewFactory("unknown codec config type: %q") ErrorInitCodecFailed1 = errutil.NewFactory("initialize codec module failed: %v") ErrorNotImplement1 = errutil.NewFactory("%q is not implement") ErrorUnsupportedTargetEvent = errors.New("unsupported target event to decode") )
errors
var ( ErrDecodeData = errors.New("decode data error") ErrDecodeNilTarget = errors.New("decode event target is nil") )
codec errors
var ( ErrorReadConfigFile1 = errutil.NewFactory("Failed to read config file: %q") ErrorUnmarshalJSONConfig = errutil.NewFactory("Failed unmarshalling config in JSON format") ErrorUnmarshalYAMLConfig = errutil.NewFactory("Failed unmarshalling config in YAML format") ErrorTimeout1 = errutil.NewFactory("timeout: %v") ErrorInvalidState = errutil.NewFactory("Invalid state for pause/resume") ErrorNoFilterName = errutil.NewFactory("No name - probably invalid syntax in configuration section %s") )
errors
var ( ErrorUnknownFilterType1 = errutil.NewFactory("unknown filter config type: %q") ErrorInitFilterFailed1 = errutil.NewFactory("initialize filter module failed: %v") )
errors
var ( ErrorUnknownInputType1 = errutil.NewFactory("unknown input config type: %q") ErrorInitInputFailed1 = errutil.NewFactory("initialize input module failed: %v") )
errors
var ( ErrorUnknownOutputType1 = errutil.NewFactory("unknown output config type: %q") ErrorInitOutputFailed1 = errutil.NewFactory("initialize output module failed: %v") )
errors
Functions ¶
func GetFromObject ¶
GetFromObject obtaining value from specified field recursively
func ReflectConfig ¶
ReflectConfig set conf from confraw
func RegistCodecHandler ¶
func RegistCodecHandler(name string, handler CodecHandler)
RegistCodecHandler regist a codec handler
func RegistFilterHandler ¶
func RegistFilterHandler(name string, handler FilterHandler)
RegistFilterHandler regist a filter handler
func RegistInputHandler ¶
func RegistInputHandler(name string, handler InputHandler)
RegistInputHandler regist a input handler
func RegistOutputHandler ¶
func RegistOutputHandler(name string, handler OutputHandler)
RegistOutputHandler regist a output handler
Types ¶
type CodecConfig ¶
type CodecConfig struct {
CommonConfig
}
CodecConfig is basic codec config struct
type CodecHandler ¶
type CodecHandler func(ctx context.Context, raw ConfigRaw) (TypeCodecConfig, error)
CodecHandler is a handler to regist codec module
type CommonConfig ¶
type CommonConfig struct { Type string `json:"type"` Disabled bool `json:"disabled" yaml:"disabled"` // if set the input/output/filter will be disabled }
CommonConfig is basic config struct
func (CommonConfig) GetType ¶
func (t CommonConfig) GetType() string
GetType return module type of config
type Config ¶
type Config struct { InputRaw []ConfigRaw `json:"input,omitempty" yaml:"input"` FilterRaw []ConfigRaw `json:"filter,omitempty" yaml:"filter"` OutputRaw []ConfigRaw `json:"output,omitempty" yaml:"output"` Event *logevent.Config `json:"event,omitempty" yaml:"event"` // channel size: chInFilter, chFilterOut, chOutDebug ChannelSize int `json:"chsize,omitempty" yaml:"chsize"` // worker number, defaults to 1 Worker int `json:"worker,omitempty" yaml:"worker"` // enable debug channel, used for testing DebugChannel bool `json:"debugch,omitempty" yaml:"debugch"` Sentry struct { DSN string `json:"dsn,omitempty" yaml:"dsn"` SyncTransport bool `json:"syncTransport,omitempty" yaml:"syncTransport"` SyncTransportTimeout time.Duration `json:"syncTransportTimeout,omitempty" yaml:"syncTransportTimeout"` } `json:"sentry,omitempty" yaml:"sentry"` // contains filtered or unexported fields }
Config contains all config
func LoadFromFile ¶
LoadFromFile load config from filepath
func LoadFromJSON ¶
LoadFromJSON load config from []byte in JSON format
func LoadFromYAML ¶
LoadFromYAML load config from []byte in YAML format
func (*Config) PauseSignal ¶
func (t *Config) PauseSignal() <-chan struct{}
func (*Config) ResumeSignal ¶
func (t *Config) ResumeSignal() <-chan struct{}
func (*Config) TestGetOutputEvent ¶
TestGetOutputEvent get an event from chOutDebug, used for testing
func (*Config) TestInputEvent ¶
TestInputEvent send an event to chInFilter, used for testing
type DefaultCodec ¶
type DefaultCodec struct {
CodecConfig
}
DefaultCodec default struct for codec
func (*DefaultCodec) Decode ¶
func (c *DefaultCodec) Decode(ctx context.Context, data any, eventExtra map[string]any, tags []string, msgChan chan<- logevent.LogEvent) (ok bool, err error)
Decode returns an event based on current timestamp and converting 'data' to 'string', adding provided 'eventExtra'
func (*DefaultCodec) DecodeEvent ¶
func (c *DefaultCodec) DecodeEvent(data []byte, event *logevent.LogEvent) error
DecodeEvent decodes data to event pointer, creating new current timestamp if IsZero
type FieldConfig ¶
FieldConfig is a name/value field config
type FilterConfig ¶
type FilterConfig struct { CommonConfig AddTags []string `yaml:"add_tag" json:"add_tag"` RemoveTags []string `yaml:"remove_tag" json:"remove_tag"` AddFields []FieldConfig `yaml:"add_field" json:"add_field"` RemoveFields []string `yaml:"remove_field" json:"remove_field"` }
FilterConfig is basic filter config struct
func (*FilterConfig) CommonFilter ¶
func (*FilterConfig) IsConfigured ¶
func (f *FilterConfig) IsConfigured() bool
IsConfigured returns whether common configuration has been setup
type FilterHandler ¶
type FilterHandler func(ctx context.Context, raw ConfigRaw, control Control) (TypeFilterConfig, error)
FilterHandler is a handler to regist filter module
type InputConfig ¶
type InputConfig struct { CommonConfig Codec TypeCodecConfig `json:"-"` }
InputConfig is basic input config struct
type InputHandler ¶
type InputHandler func(ctx context.Context, raw ConfigRaw, control Control) (TypeInputConfig, error)
InputHandler is a handler to regist input module
type OutputConfig ¶
type OutputConfig struct { CommonConfig Codec TypeCodecConfig `json:"-"` // name of codec to load }
OutputConfig is basic output config struct
type OutputHandler ¶
type OutputHandler func(ctx context.Context, raw ConfigRaw, control Control) (TypeOutputConfig, error)
OutputHandler is a handler to regist output module
type TypeCodecConfig ¶
type TypeCodecConfig interface { TypeCommonConfig // Decode - The codec’s decode method is where data coming in from an input is transformed into an event. // 'ok' returns a boolean indicating if an event was created and sent to a provided 'msgChan' channel // 'error' is returned in case of any failure handling input 'data', but 'ok' == false DOES NOT indicate an error Decode(ctx context.Context, data any, extra map[string]any, tags []string, msgChan chan<- logevent.LogEvent) (ok bool, err error) // DecodeEvent decodes 'data' to 'event' pointer, creating new current timestamp if IsZero // 'error' is returned in case of any failure handling input 'data' DecodeEvent(data []byte, event *logevent.LogEvent) error // Encode - The encode method takes an event and serializes it (encodes) into another format. // 'ok' returns a boolean indicating if an event was encoded and sent to a provided 'dataChan' channel // 'error' is returned in case of any failure encoding 'event', but 'ok' == false DOES NOT indicate an error Encode(ctx context.Context, event logevent.LogEvent, dataChan chan<- []byte) (ok bool, err error) }
TypeCodecConfig is interface of codec module
func DefaultCodecInitHandler ¶
func DefaultCodecInitHandler(context.Context, ConfigRaw) (TypeCodecConfig, error)
DefaultCodecInitHandler returns an TypeCodecConfig interface with default handler
func GetCodec ¶
func GetCodec( ctx context.Context, raw any, defaultType string, ) (codec TypeCodecConfig, err error)
GetCodec returns a codec based on the 'codec' configuration from provided 'ConfigRaw' input defaults to 'defaultType'
func GetCodecOrDefault ¶
func GetCodecOrDefault(ctx context.Context, raw any) (TypeCodecConfig, error)
type TypeCommonConfig ¶
type TypeCommonConfig interface {
GetType() string
}
TypeCommonConfig is interface of basic config
type TypeFilterConfig ¶
type TypeFilterConfig interface { TypeCommonConfig Event(context.Context, logevent.LogEvent) (logevent.LogEvent, bool) CommonFilter(context.Context, logevent.LogEvent) logevent.LogEvent }
TypeFilterConfig is interface of filter module
func GetFilters ¶
func GetFilters( ctx context.Context, filterRaw []ConfigRaw, control Control, ) (filters []TypeFilterConfig, err error)
GetFilters get filters from config
type TypeInputConfig ¶
type TypeInputConfig interface { TypeCommonConfig Start(ctx context.Context, msgChan chan<- logevent.LogEvent) (err error) }
TypeInputConfig is interface of input module
type TypeOutputConfig ¶
type TypeOutputConfig interface { TypeCommonConfig Output(ctx context.Context, event logevent.LogEvent) (err error) }
TypeOutputConfig is interface of output module
func GetOutputs ¶
func GetOutputs( ctx context.Context, outputRaw []ConfigRaw, control Control, ) (outputs []TypeOutputConfig, err error)
GetOutputs get outputs from config