testutil

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromTestMetric added in v1.14.0

func FromTestMetric(met *Metric) telegraf.Metric

func GetLocalHost added in v0.1.4

func GetLocalHost() string

GetLocalHost returns the DOCKER_HOST environment variable, parsing out any scheme or ports so that only the IP address is returned.

func IgnoreTime added in v1.14.0

func IgnoreTime() cmp.Option

IgnoreTime disables comparison of timestamp.

func MetricEqual added in v1.14.0

func MetricEqual(expected, actual telegraf.Metric, opts ...cmp.Option) bool

MetricEqual returns true if the metrics are equal.

func MockMetrics added in v1.14.0

func MockMetrics() []telegraf.Metric

MockMetrics returns a mock []telegraf.Metric object for using in unit tests of telegraf output sinks.

func MustMetric added in v1.14.0

func MustMetric(
	name string,
	tags map[string]string,
	fields map[string]interface{},
	tm time.Time,
	tp ...telegraf.ValueType,
) telegraf.Metric

Metric creates a new metric or panics on error.

func NewPKI added in v1.14.0

func NewPKI(path string) *pki

func OnlyTags added in v1.18.0

func OnlyTags() cmp.Option

OnlyTags returns an option for keeping only "Tags" for a given Metric

func ParseMetricsFrom added in v1.18.0

func ParseMetricsFrom(lines []string, header string, parser LineParser) ([]telegraf.Metric, error)

ParseMetricsFrom parses metrics from the given lines in line-protocol following a header, with a trailing blank line

func ParseRawLinesFrom added in v1.18.0

func ParseRawLinesFrom(lines []string, header string) ([]string, error)

ParseRawLinesFrom returns the raw lines between the given header and a trailing blank line

func RequireMetricEqual added in v1.14.0

func RequireMetricEqual(t *testing.T, expected, actual telegraf.Metric, opts ...cmp.Option)

RequireMetricEqual halts the test with an error if the metrics are not equal.

func RequireMetricsEqual added in v1.14.0

func RequireMetricsEqual(t *testing.T, expected, actual []telegraf.Metric, opts ...cmp.Option)

RequireMetricsEqual halts the test with an error if the array of metrics are not equal.

func SortMetrics added in v1.14.0

func SortMetrics() cmp.Option

SortMetrics enables sorting metrics before comparison.

func TestMetric added in v1.14.0

func TestMetric(value interface{}, name ...string) telegraf.Metric

TestMetric Returns a simple test point:

measurement -> "test1" or name
tags -> "tag1":"value1"
value -> value
time -> time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)

Types

type Accumulator

type Accumulator struct {
	sync.Mutex
	*sync.Cond

	Metrics []*Metric

	Discard bool
	Errors  []error

	TimeFunc func() time.Time
	// contains filtered or unexported fields
}

Accumulator defines a mocked out accumulator

func (*Accumulator) AddCounter added in v1.14.0

func (a *Accumulator) AddCounter(
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
	timestamp ...time.Time,
)

func (*Accumulator) AddError added in v1.14.0

func (a *Accumulator) AddError(err error)

AddError appends the given error to Accumulator.Errors.

func (*Accumulator) AddFields added in v0.2.0

func (a *Accumulator) AddFields(
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
	timestamp ...time.Time,
)

AddFields adds a measurement point with a specified timestamp.

func (*Accumulator) AddGauge added in v1.14.0

func (a *Accumulator) AddGauge(
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
	timestamp ...time.Time,
)

func (*Accumulator) AddHistogram added in v1.14.0

func (a *Accumulator) AddHistogram(
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
	timestamp ...time.Time,
)

func (*Accumulator) AddMetric added in v1.14.0

func (a *Accumulator) AddMetric(m telegraf.Metric)

func (*Accumulator) AddMetrics added in v1.14.0

func (a *Accumulator) AddMetrics(metrics []telegraf.Metric)

func (*Accumulator) AddSummary added in v1.14.0

func (a *Accumulator) AddSummary(
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
	timestamp ...time.Time,
)

func (*Accumulator) AddTrackingMetric added in v1.14.0

func (a *Accumulator) AddTrackingMetric(m telegraf.Metric) telegraf.TrackingID

func (*Accumulator) AddTrackingMetricGroup added in v1.14.0

func (a *Accumulator) AddTrackingMetricGroup(group []telegraf.Metric) telegraf.TrackingID

func (*Accumulator) AssertContainsFields added in v0.10.0

func (a *Accumulator) AssertContainsFields(
	t *testing.T,
	measurement string,
	fields map[string]interface{},
)

func (*Accumulator) AssertContainsTaggedFields added in v0.10.0

func (a *Accumulator) AssertContainsTaggedFields(
	t *testing.T,
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
)

func (*Accumulator) AssertDoesNotContainMeasurement added in v1.14.0

func (a *Accumulator) AssertDoesNotContainMeasurement(t *testing.T, measurement string)

func (*Accumulator) AssertDoesNotContainsTaggedFields added in v1.14.0

func (a *Accumulator) AssertDoesNotContainsTaggedFields(
	t *testing.T,
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
)

func (*Accumulator) BoolField added in v1.14.0

func (a *Accumulator) BoolField(measurement string, field string) (bool, bool)

BoolField returns the bool value of the given measurement and field or false.

func (*Accumulator) ClearMetrics added in v1.14.0

func (a *Accumulator) ClearMetrics()

func (*Accumulator) Debug added in v0.2.0

func (a *Accumulator) Debug() bool

func (*Accumulator) Delivered added in v1.14.0

func (a *Accumulator) Delivered() <-chan telegraf.DeliveryInfo

func (*Accumulator) DisablePrecision added in v1.14.0

func (a *Accumulator) DisablePrecision()

func (*Accumulator) FirstError added in v1.14.0

func (a *Accumulator) FirstError() error

func (*Accumulator) FloatField added in v1.14.0

func (a *Accumulator) FloatField(measurement string, field string) (float64, bool)

FloatField returns the float64 value of the given measurement and field or false.

func (*Accumulator) GatherError added in v1.14.0

func (a *Accumulator) GatherError(gf func(telegraf.Accumulator) error) error

Calls the given Gather function and returns the first error found.

func (*Accumulator) Get

func (a *Accumulator) Get(measurement string) (*Metric, bool)

Get gets the specified measurement point from the accumulator

func (*Accumulator) GetTelegrafMetrics added in v1.14.0

func (a *Accumulator) GetTelegrafMetrics() []telegraf.Metric

GetTelegrafMetrics returns all the metrics collected by the accumulator If you are getting race conditions here then you are not waiting for all of your metrics to arrive: see Wait()

func (*Accumulator) HasField added in v1.14.0

func (a *Accumulator) HasField(measurement string, field string) bool

HasField returns true if the given measurement has a field with the given name

func (*Accumulator) HasFloatField added in v0.10.0

func (a *Accumulator) HasFloatField(measurement string, field string) bool

HasFloatField returns true if the given measurement has a float value

func (*Accumulator) HasInt32Field added in v1.14.0

func (a *Accumulator) HasInt32Field(measurement string, field string) bool

HasInt32Field returns true if the measurement has an Int value

func (*Accumulator) HasInt64Field added in v1.14.0

func (a *Accumulator) HasInt64Field(measurement string, field string) bool

HasInt64Field returns true if the measurement has an Int64 value

func (*Accumulator) HasIntField added in v0.10.0

func (a *Accumulator) HasIntField(measurement string, field string) bool

HasIntField returns true if the measurement has an Int value

func (*Accumulator) HasMeasurement added in v0.1.8

func (a *Accumulator) HasMeasurement(measurement string) bool

HasMeasurement returns true if the accumulator has a measurement with the given name

func (*Accumulator) HasPoint added in v1.14.0

func (a *Accumulator) HasPoint(
	measurement string,
	tags map[string]string,
	fieldKey string,
	fieldValue interface{},
) bool

func (*Accumulator) HasStringField added in v1.14.0

func (a *Accumulator) HasStringField(measurement string, field string) bool

HasStringField returns true if the measurement has an String value

func (*Accumulator) HasTag added in v1.14.0

func (a *Accumulator) HasTag(measurement string, key string) bool

func (*Accumulator) HasTimestamp added in v1.14.0

func (a *Accumulator) HasTimestamp(measurement string, timestamp time.Time) bool

HasTimestamp returns true if the measurement has a matching Time value

func (*Accumulator) HasUIntField added in v0.10.0

func (a *Accumulator) HasUIntField(measurement string, field string) bool

HasUIntField returns true if the measurement has a UInt value

func (*Accumulator) Int32Field added in v1.14.0

func (a *Accumulator) Int32Field(measurement string, field string) (int32, bool)

Int32Field returns the int32 value of the given measurement and field or false.

func (*Accumulator) Int64Field added in v1.14.0

func (a *Accumulator) Int64Field(measurement string, field string) (int64, bool)

Int64Field returns the int64 value of the given measurement and field or false.

func (*Accumulator) IntField added in v1.14.0

func (a *Accumulator) IntField(measurement string, field string) (int, bool)

IntField returns the int value of the given measurement and field or false.

func (*Accumulator) NFields added in v0.10.0

func (a *Accumulator) NFields() int

NFields returns the total number of fields in the accumulator, across all measurements

func (*Accumulator) NMetrics added in v1.14.0

func (a *Accumulator) NMetrics() uint64

func (*Accumulator) SetDebug added in v0.2.0

func (a *Accumulator) SetDebug(debug bool)

func (*Accumulator) SetPrecision added in v1.14.0

func (a *Accumulator) SetPrecision(_ time.Duration)

func (*Accumulator) StringField added in v1.14.0

func (a *Accumulator) StringField(measurement string, field string) (string, bool)

StringField returns the string value of the given measurement and field or false.

func (*Accumulator) TagSetValue added in v1.14.0

func (a *Accumulator) TagSetValue(measurement string, key string) string

func (*Accumulator) TagValue added in v1.14.0

func (a *Accumulator) TagValue(measurement string, key string) string

func (*Accumulator) Uint64Field added in v1.14.0

func (a *Accumulator) Uint64Field(measurement string, field string) (uint64, bool)

Uint64Field returns the int64 value of the given measurement and field or false.

func (*Accumulator) Wait added in v1.14.0

func (a *Accumulator) Wait(n int)

Wait waits for the given number of metrics to be added to the accumulator.

func (*Accumulator) WaitError added in v1.14.0

func (a *Accumulator) WaitError(n int)

WaitError waits for the given number of errors to be added to the accumulator.

func (*Accumulator) WithTracking added in v1.14.0

func (a *Accumulator) WithTracking(_ int) telegraf.TrackingAccumulator

type CaptureLogger added in v1.19.0

type CaptureLogger struct {
	Name      string // Name is the plugin name, will be printed in the `[]`.
	LastError string
}

CaptureLogger defines a logging structure for plugins.

func (*CaptureLogger) Debug added in v1.19.0

func (l *CaptureLogger) Debug(args ...interface{})

Debug logs a debug message, patterned after log.Print.

func (*CaptureLogger) Debugf added in v1.19.0

func (l *CaptureLogger) Debugf(format string, args ...interface{})

Debugf logs a debug message, patterned after log.Printf.

func (*CaptureLogger) Error added in v1.19.0

func (l *CaptureLogger) Error(args ...interface{})

Error logs an error message, patterned after log.Print.

func (*CaptureLogger) Errorf added in v1.19.0

func (l *CaptureLogger) Errorf(format string, args ...interface{})

Errorf logs an error message, patterned after log.Printf.

func (*CaptureLogger) Info added in v1.19.0

func (l *CaptureLogger) Info(args ...interface{})

Info logs an information message, patterned after log.Print.

func (*CaptureLogger) Infof added in v1.19.0

func (l *CaptureLogger) Infof(format string, args ...interface{})

Infof logs an information message, patterned after log.Printf.

func (*CaptureLogger) Warn added in v1.19.0

func (l *CaptureLogger) Warn(args ...interface{})

Warn logs a warning message, patterned after log.Print.

func (*CaptureLogger) Warnf added in v1.19.0

func (l *CaptureLogger) Warnf(format string, args ...interface{})

Warnf logs a warning message, patterned after log.Printf.

type LineParser added in v1.18.0

type LineParser interface {
	ParseLine(line string) (telegraf.Metric, error)
}

type Logger added in v1.14.0

type Logger struct {
	Name string // Name is the plugin name, will be printed in the `[]`.
}

Logger defines a logging structure for plugins.

func (Logger) Debug added in v1.14.0

func (l Logger) Debug(args ...interface{})

Debug logs a debug message, patterned after log.Print.

func (Logger) Debugf added in v1.14.0

func (l Logger) Debugf(format string, args ...interface{})

Debugf logs a debug message, patterned after log.Printf.

func (Logger) Error added in v1.14.0

func (l Logger) Error(args ...interface{})

Error logs an error message, patterned after log.Print.

func (Logger) Errorf added in v1.14.0

func (l Logger) Errorf(format string, args ...interface{})

Errorf logs an error message, patterned after log.Printf.

func (Logger) Info added in v1.14.0

func (l Logger) Info(args ...interface{})

Info logs an information message, patterned after log.Print.

func (Logger) Infof added in v1.14.0

func (l Logger) Infof(format string, args ...interface{})

Infof logs an information message, patterned after log.Printf.

func (Logger) Warn added in v1.14.0

func (l Logger) Warn(args ...interface{})

Warn logs a warning message, patterned after log.Print.

func (Logger) Warnf added in v1.14.0

func (l Logger) Warnf(format string, args ...interface{})

Warnf logs a warning message, patterned after log.Printf.

type Metric added in v1.14.0

type Metric struct {
	Measurement string
	Tags        map[string]string
	Fields      map[string]interface{}
	Time        time.Time
	Type        telegraf.ValueType
}

Metric defines a single point measurement

func (*Metric) String added in v1.14.0

func (p *Metric) String() string

type NopAccumulator added in v1.14.0

type NopAccumulator struct{}

NopAccumulator is used for benchmarking to isolate the plugin from the internal telegraf accumulator machinery.

func (*NopAccumulator) AddCounter added in v1.14.0

func (n *NopAccumulator) AddCounter(_ string, _ map[string]interface{}, _ map[string]string, _ ...time.Time)

func (*NopAccumulator) AddError added in v1.14.0

func (n *NopAccumulator) AddError(_ error)

func (*NopAccumulator) AddFields added in v1.14.0

func (n *NopAccumulator) AddFields(_ string, _ map[string]interface{}, _ map[string]string, _ ...time.Time)

func (*NopAccumulator) AddGauge added in v1.14.0

func (n *NopAccumulator) AddGauge(_ string, _ map[string]interface{}, _ map[string]string, _ ...time.Time)

func (*NopAccumulator) AddHistogram added in v1.14.0

func (n *NopAccumulator) AddHistogram(_ string, _ map[string]interface{}, _ map[string]string, _ ...time.Time)

func (*NopAccumulator) AddMetric added in v1.14.0

func (n *NopAccumulator) AddMetric(telegraf.Metric)

func (*NopAccumulator) AddSummary added in v1.14.0

func (n *NopAccumulator) AddSummary(_ string, _ map[string]interface{}, _ map[string]string, _ ...time.Time)

func (*NopAccumulator) SetPrecision added in v1.14.0

func (n *NopAccumulator) SetPrecision(_ time.Duration)

func (*NopAccumulator) WithTracking added in v1.14.0

func (n *NopAccumulator) WithTracking(_ int) telegraf.TrackingAccumulator

Jump to

Keyboard shortcuts

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