fluentbitconfig

package module
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: Apache-2.0 Imports: 16 Imported by: 6

README

go-fluentbit-config

Go Reference

Library to parse Fluent Bit config files. With support for both the classic/legacy mode (INI), and the new YAML config.

go get github.com/calyptia/go-fluentbit-config/v2

Documentation

Index

Constants

View Source
const (
	FormatClassic = "classic"
	FormatYAML    = "yaml"
	FormatJSON    = "json"
)

Variables

View Source
var DefaultSchema = func() Schema {
	var s Schema
	err := json.Unmarshal(rawSchema, &s)
	if err != nil {
		fmt.Fprintf(os.Stderr, "could not parse fluent-bit schema: %v\n", err)
		os.Exit(1)
	}

	s.InjectLTSPlugins()

	return s
}()
View Source
var ErrFormatUnknown = errors.New("format unknown")
View Source
var ErrMissingName = errors.New("missing name property")

Functions

func Name

func Name(props property.Properties) string

Name from properties.

func ValidateSection

func ValidateSection(kind SectionKind, props property.Properties) error

func ValidateSectionWithSchema

func ValidateSectionWithSchema(kind SectionKind, props property.Properties, schema Schema) error

Types

type Config

type Config struct {
	Env      property.Properties `json:"env,omitempty" yaml:"env,omitempty"`
	Includes []string            `json:"includes,omitempty" yaml:"includes,omitempty"`
	Service  property.Properties `json:"service,omitempty" yaml:"service,omitempty"`
	Customs  Plugins             `json:"customs,omitempty" yaml:"customs,omitempty"`
	Pipeline Pipeline            `json:"pipeline,omitempty" yaml:"pipeline,omitempty"`
}

func ParseAs

func ParseAs(raw string, format Format) (Config, error)

func (*Config) AddSection

func (c *Config) AddSection(kind SectionKind, props property.Properties)

func (Config) DumpAs

func (c Config) DumpAs(format Format) (string, error)

func (Config) DumpAsClassic

func (c Config) DumpAsClassic() (string, error)

func (Config) DumpAsJSON

func (c Config) DumpAsJSON() (string, error)

func (Config) DumpAsYAML

func (c Config) DumpAsYAML() (string, error)

func (Config) Equal

func (c Config) Equal(target Config) bool

func (Config) FindByID

func (c Config) FindByID(id string) (Plugin, bool)

FindByID were the id should be namespaced with the section kind and name. For example: input:tail:tail.0

func (Config) IDs

func (c Config) IDs(namespaced bool) []string

IDs namespaced with the section kind and name. For example: input:tail:tail.0

func (*Config) Include

func (c *Config) Include(path string)

func (Config) MarshalClassic

func (c Config) MarshalClassic() ([]byte, error)

func (*Config) ServicePorts

func (c *Config) ServicePorts() ServicePorts

func (*Config) SetEnv

func (c *Config) SetEnv(key string, value any)

func (*Config) UnmarshalClassic

func (c *Config) UnmarshalClassic(text []byte) error

func (Config) Validate

func (c Config) Validate() error

Validate with the default schema.

func (Config) ValidateWithSchema

func (c Config) ValidateWithSchema(schema Schema) error

ValidateWithSchema validates that the config satisfies all properties defined on the schema. That is if the schema says the the input plugin "cpu" has a property named "pid" that is of integer type, it must be a valid integer.

type Format

type Format string

type LinedError

type LinedError struct {
	Msg  string
	Line uint
}

LinedError with information about the line number where the error was found while parsing.

func NewLinedError

func NewLinedError(msg string, line uint) *LinedError

func WrapLinedError

func WrapLinedError(err error, line uint) *LinedError

func (*LinedError) Error

func (e *LinedError) Error() string

type Pipeline

type Pipeline struct {
	Inputs  Plugins `json:"inputs,omitempty" yaml:"inputs,omitempty"`
	Parsers Plugins `json:"parsers,omitempty" yaml:"parsers,omitempty"`
	Filters Plugins `json:"filters,omitempty" yaml:"filters,omitempty"`
	Outputs Plugins `json:"outputs,omitempty" yaml:"outputs,omitempty"`
}

type Plugin

type Plugin struct {
	ID         string              `json:"-" yaml:"-"`
	Name       string              `json:"-" yaml:"-"`
	Properties property.Properties `json:",inline" yaml:",inline"`
}

func (Plugin) Equal

func (p Plugin) Equal(target Plugin) bool

func (Plugin) MarshalJSON

func (p Plugin) MarshalJSON() ([]byte, error)

func (Plugin) MarshalYAML

func (p Plugin) MarshalYAML() (any, error)

func (*Plugin) UnmarshalJSON

func (p *Plugin) UnmarshalJSON(data []byte) error

func (*Plugin) UnmarshalYAML

func (p *Plugin) UnmarshalYAML(node *yaml.Node) error

type Plugins

type Plugins []Plugin

func (Plugins) Equal

func (plugins Plugins) Equal(target Plugins) bool

func (Plugins) FindByID

func (plugins Plugins) FindByID(id string) (Plugin, bool)

FindByID were the id should not be namespaced. For example: tail.0

func (Plugins) IDs

func (plugins Plugins) IDs() []string

IDs not namespaced. For example: tail.0

func (*Plugins) UnmarshalJSON

func (plugins *Plugins) UnmarshalJSON(data []byte) error

func (*Plugins) UnmarshalYAML

func (plugins *Plugins) UnmarshalYAML(node *yaml.Node) error

type Schema

type Schema struct {
	FluentBit SchemaFluentBit `json:"fluent-bit"`
	Customs   []SchemaSection `json:"customs"`
	Inputs    []SchemaSection `json:"inputs"`
	Filters   []SchemaSection `json:"filters"`
	Outputs   []SchemaSection `json:"outputs"`
}

func (*Schema) InjectLTSPlugins

func (s *Schema) InjectLTSPlugins()

type SchemaFluentBit

type SchemaFluentBit struct {
	Version       string `json:"version"`
	SchemaVersion string `json:"schema_version"`
	OS            string `json:"os"`
}

type SchemaOptions

type SchemaOptions struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Default     any    `json:"default,omitempty"`
	Type        string `json:"type"`
}

type SchemaProperties

type SchemaProperties struct {
	Options []SchemaOptions `json:"options"`

	// Networking is only present in outputs.
	Networking []SchemaOptions `json:"networking"`
	// NetworkTLS is only present in outputs.
	NetworkTLS []SchemaOptions `json:"network_tls"`
}

type SchemaSection

type SchemaSection struct {
	Type        string           `json:"type"`
	Name        string           `json:"name"`
	Description string           `json:"description"`
	Properties  SchemaProperties `json:"properties"`
}

type SectionKind

type SectionKind string
const (
	SectionKindService SectionKind = "service"
	SectionKindCustom  SectionKind = "custom"
	SectionKindInput   SectionKind = "input"
	SectionKindParser  SectionKind = "parser"
	SectionKindFilter  SectionKind = "filter"
	SectionKindOutput  SectionKind = "output"
)

func (SectionKind) String

func (k SectionKind) String() string

type ServicePort

type ServicePort struct {
	Port     int
	Protocol networking.Protocol
	Kind     SectionKind
	// Plugin is not available for `service“ section kind.
	Plugin *Plugin
}

type ServicePorts

type ServicePorts []ServicePort

type UnknownPluginError added in v2.1.0

type UnknownPluginError struct {
	Kind SectionKind
	Name string
}

func NewUnknownPluginError added in v2.1.0

func NewUnknownPluginError(kind SectionKind, name string) *UnknownPluginError

func (*UnknownPluginError) Error added in v2.1.0

func (e *UnknownPluginError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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