transformer

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: LGPL-2.1 Imports: 7 Imported by: 0

Documentation

Overview

Package transformer provides the means to mutate a container as part of a skogul.Handler, before it is passed on to a Sender.

Index

Constants

This section is empty.

Variables

Auto maps names to Transformers to allow auto configuration

Functions

This section is empty.

Types

type Case added in v0.3.0

type Case struct {
	When         string                   `doc:"Used as a conditional statement on a field"`
	Is           string                   `doc:"Used for the specific value (string) of the stated metadata field"`
	Transformers []*skogul.TransformerRef `doc:"The transformers to run when the defined conditional is true"`
}

Case requires a field ("when") and a value ("is") to match for the set of transformers to run

type Data

type Data struct {
	Set              map[string]interface{} `doc:"Set data fields to specific values."`
	Require          []string               `doc:"Require the pressence of these data fields."`
	Flatten          [][]string             `doc:"Flatten nested structures down to the root level"`
	FlattenSeparator string                 `` /* 137-byte string literal not displayed */
	Remove           []string               `doc:"Remove these data fields."`
	Ban              []string               `doc:"Fail if any of these data fields are present"`
}

Data enforces a set of rules on data in all metrics, potentially changing the metric data.

func (*Data) Transform

func (data *Data) Transform(c *skogul.Container) error

Transform enforces the Metadata rules

type Metadata

type Metadata struct {
	Set             map[string]interface{} `doc:"Set metadata fields to specific values."`
	Require         []string               `doc:"Require the pressence of these fields."`
	ExtractFromData []string               `doc:"Extract a set of fields from Data and add it to Metadata. Removes the original."`
	Remove          []string               `doc:"Remove these metadata fields."`
	Ban             []string               `doc:"Fail if any of these fields are present"`
}

Metadata enforces a set of rules on metadata in all metrics, potentially changing the metric metadata.

func (*Metadata) Transform

func (meta *Metadata) Transform(c *skogul.Container) error

Transform enforces the Metadata rules

type Replace added in v0.2.0

type Replace struct {
	Source      string `doc:"Metadata key to read from."`
	Destination string `` /* 222-byte string literal not displayed */
	Regex       string `doc:"Regular expression to match."`
	Replacement string `doc:"Replacement text. Can also use $1, $2, etc to reference sub-matches. Defaults to empty string - remove matching items."`
	// contains filtered or unexported fields
}

Replace executes a regular expression replacement of metric metadata.

func (*Replace) Transform added in v0.2.0

func (replace *Replace) Transform(c *skogul.Container) error

Transform executes the regular expression replacement

func (*Replace) Verify added in v0.2.0

func (replace *Replace) Verify() error

Verify checks that the required variables are set and that the regular expression compiles

type Split

type Split struct {
	Field []string `doc:"Split into multiple metrics based on this field (each field denotes the path to a nested object element)."`
	Fail  bool     `` /* 140-byte string literal not displayed */
}

Split is the configuration for the split transformer

func (*Split) Transform

func (split *Split) Transform(c *skogul.Container) error

Transform splits the thing

type Switch added in v0.3.0

type Switch struct {
	Cases []Case `doc:"A list of switch cases "`
}

Switch is a wrapper for a list of cases

func (*Switch) Transform added in v0.3.0

func (sw *Switch) Transform(c *skogul.Container) error

Transform checks the cases and applies the matching transformers

type Templater

type Templater struct{}

Templater iterates over all Metrics in a Skogul Container and fills in any missing template variable from the Template in the Container, so noone else has to.

Skogul Templates are shallow:

{
        "template": {
                "metadata": {
                        "foo": "bar",
                        "geo": {
                                "country": "Norway"
                        }
                }
        },
        "metrics": [
        {
                "timestamp": "...",
                "metadata": {
                        "name": "john",
                        "geo": {
                                "city": "Oslo"
                        }
                },
                "data": ...
        },
        {
                "timestamp": "...",
                "metadata": {
                        "name": "fred",
                        "foo": "BANANA"
                },
                "data": ...
        }
        ]
}

Will result in:

{
        "metrics": [
        {
                "timestamp": "...",
                "metadata": {
                        "name": "john",
                        "foo", "bar",
                        "geo": {
                                "city": "Oslo"
                        }
                },
                "data": ...
        },
        {
                "timestamp": "...",
                "metadata": {
                        "name": "fred",
                        "foo": "BANANA",
                        "geo": {
                                "country": "Norway"
                        }
                },
                "data": ...
        }
        ]
}

The template just checked if "geo" was present in metadata or not - it did not merge missing keys.

It is good practice to use a template for any common fields, particularly timestamps.

func (Templater) Transform

func (t Templater) Transform(c *skogul.Container) error

Transform compiles/expands the template of a container

type Timestamp added in v0.4.0

type Timestamp struct {
	Source []string `doc:"The source field of the timestamp"`
	Format string   `doc:"The format to use (default: RFC3339)"`
	Fail   bool     `doc:"Propagate errors back to the caller. Useful if the timestamp is required for the container."`
	// contains filtered or unexported fields
}

Timestamp is the configuration for extracing a timestamp from inside the data

func (*Timestamp) Transform added in v0.4.0

func (config *Timestamp) Transform(c *skogul.Container) error

Transform sets the timestamp of a set of metrics to the specified field

func (*Timestamp) Verify added in v0.4.0

func (config *Timestamp) Verify() error

Verify will make sure the required fields are set

Jump to

Keyboard shortcuts

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