config

package
v0.0.0-...-c13075e Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 21 Imported by: 65

Documentation

Index

Constants

View Source
const DefaultCodecName = "default"

DefaultCodecName default codec name

View Source
const DefaultErrorTag = "gogstash_codec_default_error"

DefaultErrorTag tag added to event when process module failed

Variables

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

View Source
var (
	ErrDecodeData      = errors.New("decode data error")
	ErrDecodeNilTarget = errors.New("decode event target is nil")
)

codec errors

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

View Source
var (
	ErrorUnknownFilterType1 = errutil.NewFactory("unknown filter config type: %q")
	ErrorInitFilterFailed1  = errutil.NewFactory("initialize filter module failed: %v")
)

errors

View Source
var (
	ErrorUnknownInputType1 = errutil.NewFactory("unknown input config type: %q")
	ErrorInitInputFailed1  = errutil.NewFactory("initialize input module failed: %v")
)

errors

View Source
var (
	ErrorUnknownOutputType1 = errutil.NewFactory("unknown output config type: %q")
	ErrorInitOutputFailed1  = errutil.NewFactory("initialize output module failed: %v")
)

errors

Functions

func GetFromObject

func GetFromObject(obj map[string]any, field string) any

GetFromObject obtaining value from specified field recursively

func ReflectConfig

func ReflectConfig(confraw ConfigRaw, conf any) (err error)

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"`
	// contains filtered or unexported fields
}

Config contains all config

func LoadFromFile

func LoadFromFile(path string) (config Config, err error)

LoadFromFile load config from filepath

func LoadFromJSON

func LoadFromJSON(data []byte) (config Config, err error)

LoadFromJSON load config from []byte in JSON format

func LoadFromYAML

func LoadFromYAML(data []byte) (config Config, err error)

LoadFromYAML load config from []byte in YAML format

func (*Config) PauseSignal

func (t *Config) PauseSignal() <-chan struct{}

func (*Config) RequestPause

func (t *Config) RequestPause(ctx context.Context) error

func (*Config) RequestResume

func (t *Config) RequestResume(ctx context.Context) error

func (*Config) ResumeSignal

func (t *Config) ResumeSignal() <-chan struct{}

func (*Config) Start

func (t *Config) Start(ctx context.Context) (err error)

Start config in goroutines

func (*Config) TestGetOutputEvent

func (t *Config) TestGetOutputEvent(timeout time.Duration) (event logevent.LogEvent, err error)

TestGetOutputEvent get an event from chOutDebug, used for testing

func (*Config) TestInputEvent

func (t *Config) TestInputEvent(event logevent.LogEvent)

TestInputEvent send an event to chInFilter, used for testing

func (*Config) Wait

func (t *Config) Wait() (err error)

Wait blocks until all filters returned, then returns the first non-nil error (if any) from them.

type ConfigRaw

type ConfigRaw map[string]any

ConfigRaw is general config struct

type Control

type Control interface {
	RequestPause(ctx context.Context) error
	RequestResume(ctx context.Context) error
	PauseSignal() <-chan struct{}
	ResumeSignal() <-chan struct{}
}

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

func (*DefaultCodec) Encode

func (c *DefaultCodec) Encode(ctx context.Context, event logevent.LogEvent, dataChan chan<- []byte) (ok bool, err error)

Encode sends the message field, ignoring any extra fields

type FieldConfig

type FieldConfig struct {
	Key   string `yaml:"key"`
	Value string `yaml:"value"`
}

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 (f *FilterConfig) CommonFilter(
	ctx context.Context,
	event logevent.LogEvent,
) logevent.LogEvent

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 MsgChan

type MsgChan chan logevent.LogEvent

MsgChan message channel type

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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