beats: github.com/elastic/beats/libbeat/common/schema Index | Files | Directories

package schema

import "github.com/elastic/beats/libbeat/common/schema"

Package schema contains helper utilities to parse, convert, rename, and reorganize data from the format returned by the various monitored systems to the data model used by Metricbeat.

See the docs in the mapstrstr and mapstriface sub-packages for usage examples.

Index

Package Files

doc.go error.go options.go schema.go

Variables

var DefaultApplyOptions = []ApplyOption{AllRequired}

DefaultApplyOptions are the default options for Apply()

func AllRequired Uses

func AllRequired(event common.MapStr, errors multierror.Errors) (common.MapStr, multierror.Errors)

AllRequired considers any missing field as an error, except if explicitly set as optional

func FailOnRequired Uses

func FailOnRequired(event common.MapStr, errors multierror.Errors) (common.MapStr, multierror.Errors)

FailOnRequired considers missing fields as an error only if they are set as required

type ApplyOption Uses

type ApplyOption func(common.MapStr, multierror.Errors) (common.MapStr, multierror.Errors)

ApplyOption modifies the result of Apply

func NotFoundKeys Uses

func NotFoundKeys(cb func(keys []string)) ApplyOption

NotFoundKeys calls a function with the list of missing keys as parameter

type Conv Uses

type Conv struct {
    Func            Converter // Convertor function
    Key             string    // The key in the data map
    Optional        bool      // Whether to ignore errors if the key is not found
    Required        bool      // Whether to provoke errors if the key is not found
    IgnoreAllErrors bool      // Ignore any value conversion error
}

A Conv object represents a conversion mechanism from the data map to the event map.

func IgnoreAllErrors Uses

func IgnoreAllErrors(c Conv) Conv

IgnoreAllErrors set the enable all errors flag

func Optional Uses

func Optional(c Conv) Conv

Optional sets the optional flag, that suppresses the error in case the key doesn't exist

func Required Uses

func Required(c Conv) Conv

Required sets the required flag, that provokes an error in case the key doesn't exist, even if other missing keys can be ignored

func SetOptions Uses

func SetOptions(c Conv, opts []SchemaOption) Conv

setOptions adds the optional flags to the Conv object

func (Conv) HasKey Uses

func (conv Conv) HasKey(key string) bool

func (Conv) Map Uses

func (conv Conv) Map(key string, event common.MapStr, data map[string]interface{}) multierror.Errors

Map applies the conversion on the data and adds the result to the event on the key.

type Converter Uses

type Converter func(key string, data map[string]interface{}) (interface{}, error)

Converter function type

type KeyError Uses

type KeyError interface {
    Key() string
    SetKey(k string)
}

KeyError is an error with a field key

type KeyNotFoundError Uses

type KeyNotFoundError struct {
    Err      error
    Optional bool
    Required bool
    // contains filtered or unexported fields
}

KeyNotFoundError is an error happening when a field key is not found

func NewKeyNotFoundError Uses

func NewKeyNotFoundError(key string) *KeyNotFoundError

NewKeyNotFoundError builds a KeyNotFoundError

func (*KeyNotFoundError) Error Uses

func (err *KeyNotFoundError) Error() string

Error returns the error message of a KeyNotFoundError

func (*KeyNotFoundError) Key Uses

func (k *KeyNotFoundError) Key() string

Key returns the value of the field key

func (*KeyNotFoundError) SetKey Uses

func (k *KeyNotFoundError) SetKey(v string)

SetKey sets the value of the field key

type Mapper Uses

type Mapper interface {
    // Map applies the Mapper conversion on the data and adds the result
    // to the event on the key.
    Map(key string, event common.MapStr, data map[string]interface{}) multierror.Errors

    HasKey(key string) bool
}

Mapper interface represents a valid type to be used in a schema.

type Object Uses

type Object map[string]Mapper

implements Mapper interface for structure

func (Object) HasKey Uses

func (o Object) HasKey(key string) bool

func (Object) Map Uses

func (o Object) Map(key string, event common.MapStr, data map[string]interface{}) multierror.Errors

Map applies the schema for an object

type Schema Uses

type Schema map[string]Mapper

Schema describes how a map[string]interface{} object can be parsed and converted into an event. The conversions can be described using an (optionally nested) common.MapStr that contains Conv objects.

func (Schema) Apply Uses

func (s Schema) Apply(data map[string]interface{}, opts ...ApplyOption) (common.MapStr, error)

Apply converts the fields extracted from data, using the schema, into a new map and reports back the errors.

func (Schema) ApplyTo Uses

func (s Schema) ApplyTo(event common.MapStr, data map[string]interface{}, opts ...ApplyOption) (common.MapStr, multierror.Errors)

ApplyTo adds the fields extracted from data, converted using the schema, to the event map.

func (Schema) HasKey Uses

func (s Schema) HasKey(key string) bool

HasKey checks if the key is part of the schema

type SchemaOption Uses

type SchemaOption func(c Conv) Conv

SchemaOption is for adding optional parameters to the conversion functions

type WrongFormatError Uses

type WrongFormatError struct {
    Msg string
    // contains filtered or unexported fields
}

WrongFormatError is an error happening when a field format is incorrect

func NewWrongFormatError Uses

func NewWrongFormatError(key string, msg string) *WrongFormatError

NewWrongFormatError builds a new WrongFormatError

func (*WrongFormatError) Error Uses

func (err *WrongFormatError) Error() string

Error returns the error message of a WrongFormatError

func (*WrongFormatError) Key Uses

func (k *WrongFormatError) Key() string

Key returns the value of the field key

func (*WrongFormatError) SetKey Uses

func (k *WrongFormatError) SetKey(v string)

SetKey sets the value of the field key

Directories

PathSynopsis
mapstrifacePackage mapstriface contains utilities for transforming map[string]interface{} objects into metricbeat events.
mapstrstrPackage mapstrstr contains utilities for transforming map[string]string objects into metricbeat events.

Package schema imports 4 packages (graph) and is imported by 1154 packages. Updated 2019-05-20. Refresh now. Tools for package owners.