parser

package
v0.28.0 Latest Latest
Warning

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

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

Documentation

Overview

Package parser wraps a couple of helper libraries with the intention of hiding type information and simplifying data handling outside the gadgets. It can be used to wire the events of gadgets directly to the column formatter and use generic operations like filtering and sorting on them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorGetter added in v0.15.0

type ErrorGetter interface {
	GetType() types.EventType
	GetMessage() string
}

type ExtraLines

type ExtraLines interface {
	ExtraLines() []string
}

type GaugeVal added in v0.17.0

type GaugeVal struct {
	Attrs      []attribute.KeyValue
	Int64Val   int64
	Float64Val float64
}

type LogCallback

type LogCallback func(severity logger.Level, fmt string, params ...any)

type Parser

type Parser interface {
	// GetTextColumnsFormatter returns the default formatter for this columns instance
	GetTextColumnsFormatter(options ...textcolumns.Option) TextColumnsFormatter

	// GetColumnAttributes returns a map of column names to their respective attributes
	GetColumnAttributes() []columns.Attributes

	// GetDefaultColumns returns a list of columns that are visible by default; optionally, hiddenTags will
	// hide columns that contain any of the given tags
	GetDefaultColumns(hiddenTags ...string) []string

	// GetColumns returns the underlying columns definition (mainly used for serialization)
	GetColumns() any

	// VerifyColumnNames takes a list of column names and returns two lists, one containing the
	// valid column names and another containing the invalid column names. Prefixes like "-" for
	// descending sorting will be ignored.
	VerifyColumnNames(columnNames []string) (valid []string, invalid []string)

	// SetColumnFilters sets additional column filters that will be used whenever one of the other methods of this
	// interface are called. This is for example used to filter columns with information on kubernetes in a non-k8s
	// environment like ig
	SetColumnFilters(...columns.ColumnFilter)

	// SetSorting sets what sorting should be applied when calling SortEntries() // TODO
	SetSorting([]string) error

	// SetFilters sets which filter to apply before emitting events downstream
	SetFilters([]string) error

	// EventHandlerFunc returns a function that accepts an instance of type *T and pushes it downstream after applying
	// enrichers and filters
	EventHandlerFunc(enrichers ...func(any) error) any
	EventHandlerFuncArray(enrichers ...func(any) error) any

	// JSONHandlerFunc returns a function that accepts a JSON encoded event, unmarshal it into *T and pushes it
	// downstream after applying enrichers and filters
	JSONHandlerFunc(enrichers ...func(any) error) func([]byte)
	JSONHandlerFuncArray(key string, enrichers ...func(any) error) func([]byte)

	// SetEventCallback sets the downstream callback
	SetEventCallback(eventCallback any)

	// SetLogCallback sets the function to use to send log messages
	SetLogCallback(logCallback LogCallback)

	// EnableSnapshots initializes the snapshot combiner, which is able to aggregate snapshots from several sources
	// and can return (optionally cached) results on demand; used for top gadgets
	EnableSnapshots(ctx context.Context, t time.Duration, ttl int)

	// EnableCombiner initializes the event combiner, which aggregates events from all sources; used for snapshot gadgets.
	// Events are released by calling Flush().
	EnableCombiner()

	// Flush sends the events downstream that were collected after EnableCombiner() was called.
	Flush()

	// AttrsGetter returns a function that accepts an instance of type *T and returns a list of
	// attributes for cols.
	AttrsGetter(cols []string) (func(any) []attribute.KeyValue, error)

	// AggregateEntries receives an array of *T and aggregates them according to cols.
	AggregateEntries(cols []string, entries any, field string, isInt bool) (map[string]*GaugeVal, error)

	// GetColKind returns the reflect.Kind of the column with the given name
	GetColKind(colName string) (reflect.Kind, error)

	// ColIntGetter returns a function that accepts an instance of type *T and returns the value
	// of the column as an int64.
	ColIntGetter(colName string) (func(any) int64, error)

	// ColFloatGetter returns a function that accepts an instance of type *T and returns the
	// value of the column as an float64.
	ColFloatGetter(colName string) (func(any) float64, error)
}

Parser is the (untyped) interface used for parser

func NewParser

func NewParser[T any](columns *columns.Columns[T]) Parser

type TextColumnsFormatter

type TextColumnsFormatter interface {
	FormatHeader() string
	SetShowColumns([]string) error
	TransformEvent(string) (string, error)
	EventHandlerFunc() any
	EventHandlerFuncArray(...func()) any
	SetEventCallback(eventCallback func(string))
	SetEnableExtraLines(bool)
}

TextColumnsFormatter is the interface used for outputHelper

Jump to

Keyboard shortcuts

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