internal

package
v1.27.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const Customized = ""
View Source
const DefaultMaxDecompressionSize = 500 * 1024 * 1024 //500MB
View Source
const KillGrace = 5 * time.Second

KillGrace is the amount of time we allow a process to shutdown before sending a SIGKILL.

Variables

View Source
var (
	ErrTimeout        = errors.New("command timed out")
	ErrNotImplemented = errors.New("not implemented yet")
)
View Source
var (
	Version = "unknown"
	Branch  = ""
	Commit  = ""
)

Set via LDFLAGS -X

View Source
var HostEndianess = binary.LittleEndian

Functions

func AlignDuration added in v1.14.0

func AlignDuration(tm time.Time, interval time.Duration) time.Duration

AlignDuration returns the duration until next aligned interval. If the current time is aligned a 0 duration is returned.

func AlignTime added in v1.14.0

func AlignTime(tm time.Time, interval time.Duration) time.Time

AlignTime returns the time of the next aligned interval. If the current time is aligned the current time is returned.

func AuthHandler added in v1.14.0

func AuthHandler(username, password, realm string, onError BasicAuthErrorFunc) func(h http.Handler) http.Handler

AuthHandler returns a http handler that requires HTTP basic auth credentials to match the given username and password.

func CombinedOutputTimeout added in v1.14.0

func CombinedOutputTimeout(c *exec.Cmd, timeout time.Duration) ([]byte, error)

CombinedOutputTimeout runs the given command with the given timeout and returns the combined output of stdout and stderr. If the command times out, it attempts to kill the process.

func CompressWithGzip added in v1.14.0

func CompressWithGzip(data io.Reader) io.ReadCloser

CompressWithGzip takes an io.Reader as input and pipes it through a gzip.Writer returning an io.Reader containing the gzipped data. Errors occurring during compression are returned to the instance reading from the returned reader via through the corresponding read call (e.g. io.Copy or io.ReadAll).

func ExitStatus added in v1.14.0

func ExitStatus(err error) (int, bool)

ExitStatus takes the error from exec.Command and returns the exit status and true if error is not exit status, will return 0 and false

func FormatFullVersion added in v1.24.0

func FormatFullVersion() string

func GenericAuthHandler added in v1.16.0

func GenericAuthHandler(credentials string, onError GenericAuthErrorFunc) func(h http.Handler) http.Handler

GenericAuthHandler returns a http handler that requires `Authorization: <credentials>`

func IPRangeHandler added in v1.14.0

func IPRangeHandler(networks []*net.IPNet, onError ErrorFunc) func(h http.Handler) http.Handler

IPRangeHandler returns a http handler that requires the remote address to be in the specified network.

func NewGzipReader added in v1.15.0

func NewGzipReader(r io.Reader) (io.Reader, error)

func NewStreamContentDecoder added in v1.15.0

func NewStreamContentDecoder(encoding string, r io.Reader) (io.Reader, error)

NewStreamContentDecoder returns a reader that will decode the stream according to the encoding type.

func OnClientError added in v1.14.3

func OnClientError(client *http.Client, err error)

func ParseTimestamp added in v1.14.0

func ParseTimestamp(format string, timestamp interface{}, location *time.Location, separator ...string) (time.Time, error)

ParseTimestamp parses a Time according to the standard Telegraf options. These are generally displayed in the toml similar to:

json_time_key= "timestamp"
json_time_format = "2006-01-02T15:04:05Z07:00"
json_timezone = "America/Los_Angeles"

The format can be one of "unix", "unix_ms", "unix_us", "unix_ns", or a Go time layout suitable for time.Parse.

When using the "unix" format, an optional fractional component is allowed. Specific unix time precisions cannot have a fractional component.

Unix times may be an int64, float64, or string. When using a Go format string the timestamp must be a string.

The location is a location string suitable for time.LoadLocation. Unix times do not use the location string, a unix time is always return in the UTC location.

func ProductToken added in v1.14.0

func ProductToken() string

ProductToken returns a tag for Telegraf that can be used in user agents.

func RandomDuration added in v1.14.0

func RandomDuration(max time.Duration) time.Duration

RandomDuration returns a random duration between 0 and max.

func RandomSleep added in v1.14.0

func RandomSleep(max time.Duration, shutdown chan struct{})

RandomSleep will sleep for a random amount of time up to max. If the shutdown channel is closed, it will return before it has finished sleeping.

func RandomString added in v1.14.0

func RandomString(n int) (string, error)

RandomString returns a random string of alphanumeric characters

func ReadLines

func ReadLines(filename string) ([]string, error)

ReadLines reads contents from a file and splits them by new lines.

func RunTimeout added in v1.14.0

func RunTimeout(c *exec.Cmd, timeout time.Duration) error

RunTimeout runs the given command with the given timeout. If the command times out, it attempts to kill the process.

func SleepContext added in v1.14.0

func SleepContext(ctx context.Context, duration time.Duration) error

SleepContext sleeps until the context is closed or the duration is reached.

func SnakeCase added in v1.14.0

func SnakeCase(in string) string

SnakeCase converts the given string to snake case following the Golang format: acronyms are converted to lower-case and preceded by an underscore.

func StdOutputTimeout added in v1.14.5

func StdOutputTimeout(c *exec.Cmd, timeout time.Duration) ([]byte, error)

StdOutputTimeout runs the given command with the given timeout and returns the output of stdout. If the command times out, it attempts to kill the process.

func ToBool added in v1.19.0

func ToBool(value interface{}) (bool, error)

func ToFloat64 added in v1.19.0

func ToFloat64(value interface{}) (float64, error)

func ToInt64 added in v1.19.0

func ToInt64(value interface{}) (int64, error)

func ToString added in v1.19.0

func ToString(value interface{}) (string, error)

func ToUint64 added in v1.19.0

func ToUint64(value interface{}) (uint64, error)

func WaitTimeout added in v1.14.0

func WaitTimeout(c *exec.Cmd, timeout time.Duration) error

WaitTimeout waits for the given command to finish with a timeout. It assumes the command has already been started. If the command times out, it attempts to kill the process.

Types

type AutoDecoder added in v1.25.0

type AutoDecoder struct {
	// contains filtered or unexported fields
}

func NewAutoContentDecoder added in v1.25.0

func NewAutoContentDecoder() *AutoDecoder

func (*AutoDecoder) Decode added in v1.25.0

func (a *AutoDecoder) Decode(data []byte, maxDecompressionSize int64) ([]byte, error)

func (*AutoDecoder) SetEncoding added in v1.25.0

func (a *AutoDecoder) SetEncoding(encoding string)

type BasicAuthErrorFunc added in v1.14.0

type BasicAuthErrorFunc func(rw http.ResponseWriter)

type ContentDecoder added in v1.14.0

type ContentDecoder interface {
	SetEncoding(string)
	Decode([]byte, int64) ([]byte, error)
}

ContentDecoder removes a wrapper encoding from byte buffers.

func NewContentDecoder added in v1.14.0

func NewContentDecoder(encoding string) (ContentDecoder, error)

NewContentDecoder returns a ContentDecoder for the encoding type.

type ContentEncoder added in v1.14.0

type ContentEncoder interface {
	Encode([]byte) ([]byte, error)
}

ContentEncoder applies a wrapper encoding to byte buffers.

func NewContentEncoder added in v1.14.0

func NewContentEncoder(encoding string, options ...EncodingOption) (ContentEncoder, error)

NewContentEncoder returns a ContentEncoder for the encoding type.

type EncodingOption added in v1.27.0

type EncodingOption func(*encoderConfig)

EncodingOption provide methods to change the encoding from the standard configuration.

func WithCompressionLevel added in v1.27.1

func WithCompressionLevel(level int) EncodingOption

type ErrorFunc added in v1.14.0

type ErrorFunc func(rw http.ResponseWriter, code int)

ErrorFunc is a callback for writing an error response.

type GenericAuthErrorFunc added in v1.16.0

type GenericAuthErrorFunc func(rw http.ResponseWriter)

type GzipDecoder added in v1.14.0

type GzipDecoder struct {
	// contains filtered or unexported fields
}

GzipDecoder decompresses buffers with gzip compression.

func NewGzipDecoder added in v1.14.0

func NewGzipDecoder() *GzipDecoder

func (*GzipDecoder) Decode added in v1.14.0

func (d *GzipDecoder) Decode(data []byte, maxDecompressionSize int64) ([]byte, error)

func (*GzipDecoder) SetEncoding added in v1.25.0

func (*GzipDecoder) SetEncoding(string)

type GzipEncoder added in v1.14.0

type GzipEncoder struct {
	// contains filtered or unexported fields
}

GzipEncoder compresses the buffer using gzip at the default level.

func NewGzipEncoder added in v1.14.0

func NewGzipEncoder(options ...EncodingOption) (*GzipEncoder, error)

func (*GzipEncoder) Encode added in v1.14.0

func (e *GzipEncoder) Encode(data []byte) ([]byte, error)

type GzipReader added in v1.15.0

type GzipReader struct {
	// contains filtered or unexported fields
}

GzipReader is similar to gzip.Reader but reads only a single gzip stream per read.

func (*GzipReader) Read added in v1.15.0

func (r *GzipReader) Read(b []byte) (int, error)

type IdentityDecoder added in v1.14.0

type IdentityDecoder struct{}

IdentityDecoder is a null decoder that returns the input.

func NewIdentityDecoder added in v1.14.0

func NewIdentityDecoder() *IdentityDecoder

func (*IdentityDecoder) Decode added in v1.14.0

func (*IdentityDecoder) Decode(data []byte, maxDecompressionSize int64) ([]byte, error)

func (*IdentityDecoder) SetEncoding added in v1.25.0

func (*IdentityDecoder) SetEncoding(string)

type IdentityEncoder added in v1.14.0

type IdentityEncoder struct{}

IdentityEncoder is a null encoder that applies no transformation.

func NewIdentityEncoder added in v1.14.0

func NewIdentityEncoder(options ...EncodingOption) (*IdentityEncoder, error)

func (*IdentityEncoder) Encode added in v1.14.0

func (*IdentityEncoder) Encode(data []byte) ([]byte, error)

type ReadWaitCloser added in v1.14.0

type ReadWaitCloser struct {
	// contains filtered or unexported fields
}

func (*ReadWaitCloser) Close added in v1.14.0

func (r *ReadWaitCloser) Close() error

type ZlibDecoder added in v1.22.0

type ZlibDecoder struct {
	// contains filtered or unexported fields
}

func NewZlibDecoder added in v1.22.0

func NewZlibDecoder() *ZlibDecoder

func (*ZlibDecoder) Decode added in v1.22.0

func (d *ZlibDecoder) Decode(data []byte, maxDecompressionSize int64) ([]byte, error)

func (*ZlibDecoder) SetEncoding added in v1.25.0

func (*ZlibDecoder) SetEncoding(string)

type ZlibEncoder added in v1.22.0

type ZlibEncoder struct {
	// contains filtered or unexported fields
}

func NewZlibEncoder added in v1.22.0

func NewZlibEncoder(options ...EncodingOption) (*ZlibEncoder, error)

func (*ZlibEncoder) Encode added in v1.22.0

func (e *ZlibEncoder) Encode(data []byte) ([]byte, error)

Directories

Path Synopsis
Package choice provides basic functions for working with plugin options that must be one of several values.
Package choice provides basic functions for working with plugin options that must be one of several values.

Jump to

Keyboard shortcuts

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