fluentbitconfig

package module
v2.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: Apache-2.0 Imports: 20 Imported by: 7

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

Overview

Example (ConfigWithProcessors)
conf := Config{
	Pipeline: Pipeline{
		Inputs: Plugins{
			Plugin{
				Properties: property.Properties{
					{Key: "name", Value: "dummy"},
					{Key: "processors", Value: property.Properties{
						{Key: "logs", Value: Plugins{
							Plugin{
								Properties: property.Properties{
									{Key: "name", Value: "calyptia"},
									{Key: "actions", Value: property.Properties{
										{Key: "type", Value: "block_keys"},
										{Key: "opts", Value: property.Properties{
											{Key: "regex", Value: "star"},
											{Key: "regexEngine", Value: "pcre2"},
										}},
									}},
								},
							},
						}},
					}},
				},
			},
		},
	},
}
yaml, err := conf.DumpAsYAML()
if err != nil {
	panic(err)
}

fmt.Println(yaml)
Output:

pipeline:
    inputs:
        - name: dummy
          processors:
            logs:
                - name: calyptia
                  actions:
                    type: block_keys
                    opts:
                        regex: star
                        regexEngine: pcre2

Index

Examples

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"`
	Parsers  Plugins             `json:"parsers,omitempty" yaml:"parsers,omitempty"`
}

func ParseAs

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

func ParseAsClassic added in v2.3.1

func ParseAsClassic(raw string) (Config, error)

func ParseAsJSON added in v2.3.1

func ParseAsJSON(raw string) (Config, error)

func ParseAsYAML added in v2.3.1

func ParseAsYAML(raw string) (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"`
	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"`
	Processors []SchemaSection `json:"processors"`
}

func GetSchema added in v2.8.0

func GetSchema(version string) (Schema, error)

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 SchemaOptionList added in v2.13.0

type SchemaOptionList []SchemaOptions

func (SchemaOptionList) FindOption added in v2.13.0

func (options SchemaOptionList) FindOption(optname string) *SchemaOptions

type SchemaOptions

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

type SchemaProperties

type SchemaProperties struct {
	Options []SchemaOptions `json:"options"`
	// GlobalOptions only appear on inputs.
	GlobalOptions []SchemaOptions `json:"global_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"
	SectionKindProcessor SectionKind = "processor"
)

func (SectionKind) String

func (k SectionKind) String() string

type ServicePort

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

type ServicePortGetter added in v2.5.0

type ServicePortGetter struct {
	EnabledFunc     func(p Plugin) bool
	PortFunc        func(p Plugin) (int32, bool)
	ProtocolFunc    func(p Plugin) (networking.Protocol, bool)
	DefaultPort     int32
	DefaultProtocol networking.Protocol
}

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
cmd

Jump to

Keyboard shortcuts

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