util

package
v0.0.2-0...-4ce78c8 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: Apache-2.0, Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const HostnameProviderConfiguration = "configuration"

HostnameProviderConfiguration is the key for the hostname provider associated to datadog.yaml

View Source
const InsertionSortThreshold = 40

InsertionSortThreshold is the slice size after which we should consider using the stdlib sort method instead of the InsertionSort implemented below.

Variables

This section is empty.

Functions

func CopyDir

func CopyDir(src, dst string) error

CopyDir copies directory recursively

func CopyFile

func CopyFile(src, dst string) error

CopyFile atomically copies file path `src“ to file path `dst`.

func CopyFileAll

func CopyFileAll(src, dst string) error

CopyFileAll calls CopyFile, but will create necessary directories for `dst`.

func DetectCloudProvider

func DetectCloudProvider()

DetectCloudProvider detects the cloud provider where the agent is running in order: * AWS ECS/Fargate * AWS EC2 * GCE * Azure * Alibaba * Tencent

func EnsureParentDirsExist

func EnsureParentDirsExist(p string) error

EnsureParentDirsExist makes a path immediately available for writing by creating the necessary parent directories.

func Fqdn

func Fqdn(hostname string) string

Fqdn returns the FQDN for the host if any

func GetAgentNetworkMode

func GetAgentNetworkMode() (string, error)

GetAgentNetworkMode retrieves from Docker the network mode of the Agent container

func GetAgentUTSMode

func GetAgentUTSMode() (containers.UTSMode, error)

GetAgentUTSMode retrieves from Docker the UTS mode of the Agent container

func GetCloudProviderNTPHosts

func GetCloudProviderNTPHosts() []string

GetCloudProviderNTPHosts detects the cloud provider where the agent is running in order and returns its NTP host name.

func GetFileModTime

func GetFileModTime(path string) (time.Time, error)

GetFileModTime gets the modification time

func GetFileSize

func GetFileSize(path string) (int64, error)

GetFileSize gets the file size

func GetGoRoutinesDump

func GetGoRoutinesDump() (string, error)

GetGoRoutinesDump returns the stack trace of every Go routine of a running Agent.

func GetHostname

func GetHostname() (string, error)

GetHostname retrieves the host name from GetHostnameData

func GetJSONSerializableMap

func GetJSONSerializableMap(m interface{}) interface{}

GetJSONSerializableMap returns a JSON serializable map from a raw map

func GetNetworkID

func GetNetworkID() (string, error)

GetNetworkID retrieves the network_id which can be used to improve network connection resolution. This can be configured or detected. The following sources will be queried: * configuration * GCE * EC2

func HTTPHeaders

func HTTPHeaders() map[string]string

HTTPHeaders returns a http headers including various basic information (User-Agent, Content-Type...).

func InsertionSort

func InsertionSort(elements []string)

InsertionSort sorts in-place the given elements, not doing any allocation. It is very efficient for on slices but if memory allocation is not an issue, consider using the stdlib `sort.Sort` method on slices having a size > InsertionSortThreshold. See `pkg/util/sort_benchmarks_note.md` for more details.

func LogVersionHistory

func LogVersionHistory()

LogVersionHistory loads version history file, append new entry if agent version is different than the last entry in the JSON file, trim the file if too many entries then save the file.

func SortUniqInPlace

func SortUniqInPlace(elements []string) []string

SortUniqInPlace sorts and remove duplicates from elements in place The returned slice is a subslice of elements

Types

type BiMap

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

BiMap provides a bidirectional map of keys and values.

func NewBiMap

func NewBiMap(k, v interface{}) *BiMap

NewBiMap instantiates BiMap

func (*BiMap) AddKV

func (b *BiMap) AddKV(k, v interface{}) error

AddKV adds value `v` to map the map indexed with key `k`.

func (*BiMap) GetKV

func (b *BiMap) GetKV(key interface{}) (interface{}, error)

GetKV gets value provided the key.

func (*BiMap) GetKVBimap

func (b *BiMap) GetKVBimap(key interface{}) (interface{}, error)

GetKVBimap looks for the provided key both for keys and values in the map.

The first occurrence will be returned.

func (*BiMap) GetKVReverse

func (b *BiMap) GetKVReverse(key interface{}) (interface{}, error)

GetKVReverse gets key provided the value.

func (*BiMap) Keys

func (b *BiMap) Keys() []interface{}

Keys returns a slice with all keys in the map.

func (*BiMap) Values

func (b *BiMap) Values() []interface{}

Values returns a slice with all values in the map.

type HostnameData

type HostnameData struct {
	Hostname string
	Provider string
}

HostnameData contains hostname and the hostname provider

func GetHostnameData

func GetHostnameData() (HostnameData, error)

GetHostnameData retrieves the host name for the Agent and hostname provider, trying to query these environments/api, in order: * GCE * Docker * kubernetes * os * EC2

type NamedPipe

type NamedPipe interface {
	Open() error
	Ready() bool
	Read(b []byte) (int, error)
	Write(b []byte) (int, error)
	Close() error
}

NamedPipe interface to NamedPipes (multi-platform)

func GetPipe

func GetPipe(path string) (NamedPipe, error)

GetPipe returns a UnixPipe to path

type Stat

type Stat struct {
	Val int64
	Ts  time.Time
}

Stat type includes a statted value and its timestamp.

type Stats

type Stats struct {
	Aggregated chan Stat
	// contains filtered or unexported fields
}

Stats type structure enabling statting facilities.

func NewStats

func NewStats(sz uint32) (*Stats, error)

NewStats constructor for Stats

func (*Stats) Process

func (s *Stats) Process()

Process call to start processing statistics

func (*Stats) StatEvent

func (s *Stats) StatEvent(v int64)

StatEvent aggregates an event with value v

func (*Stats) Stop

func (s *Stats) Stop()

Stop call to stop processing statistics. Once stopped, Stats cannot be restarted.

func (*Stats) Update

func (s *Stats) Update(expStat *expvar.Int)

Update update the expvar parameter with the last aggregated value

type StatsTracker

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

StatsTracker Keeps track of simple stats over its lifetime and a configurable time range. StatsTracker is designed to be memory efficient by aggregating data into buckets. For example a time frame of 24 hours with a bucketFrame of 1 hour will ensure that only 24 points are ever kept in memory. New data is considered in the stats immediately while old data is removed by dropping expired aggregated buckets.

func NewStatsTracker

func NewStatsTracker(timeFrame time.Duration, bucketSize time.Duration) *StatsTracker

NewStatsTracker Creates a new StatsTracker instance

func NewStatsTrackerWithTimeProvider

func NewStatsTrackerWithTimeProvider(timeFrame time.Duration, bucketSize time.Duration, timeProvider timeProvider) *StatsTracker

NewStatsTrackerWithTimeProvider Creates a new StatsTracker instance with a time provider closure (mostly for testing)

func (*StatsTracker) Add

func (s *StatsTracker) Add(value int64)

Add Records a new value to the stats tracker

func (*StatsTracker) AllTimeAvg

func (s *StatsTracker) AllTimeAvg() int64

AllTimeAvg Gets the all time average of values seen so far

func (*StatsTracker) AllTimePeak

func (s *StatsTracker) AllTimePeak() int64

AllTimePeak Gets the largest value seen so far

func (*StatsTracker) MovingAvg

func (s *StatsTracker) MovingAvg() int64

MovingAvg Gets the moving average of values within the time frame

func (*StatsTracker) MovingPeak

func (s *StatsTracker) MovingPeak() int64

MovingPeak Gets the largest value seen within the time frame

type TagsBuilder

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

TagsBuilder allows to build a slice of tags to generate the context while reusing the same internal slice.

func NewTagsBuilder

func NewTagsBuilder() *TagsBuilder

NewTagsBuilder returns a new empty TagsBuilder.

func NewTagsBuilderFromSlice

func NewTagsBuilderFromSlice(tags []string) *TagsBuilder

NewTagsBuilderFromSlice return a new TagsBuilder with the input slice for it's internal buffer.

func (*TagsBuilder) Append

func (tb *TagsBuilder) Append(tags ...string)

Append appends tags to the builder

func (*TagsBuilder) Copy

func (tb *TagsBuilder) Copy() []string

Copy makes a copy of the internal slice

func (*TagsBuilder) Get

func (tb *TagsBuilder) Get() []string

Get returns the internal slice

func (*TagsBuilder) Reset

func (tb *TagsBuilder) Reset()

Reset resets the size of the builder to 0 without discaring the internal buffer

func (*TagsBuilder) SortUniq

func (tb *TagsBuilder) SortUniq()

SortUniq sorts and remove duplicate in place

type UnixNamedPipe

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

UnixNamedPipe unix abstraction to named pipes

func NewUnixNamedPipe

func NewUnixNamedPipe(path string) (*UnixNamedPipe, error)

NewUnixNamedPipe UnixNamedPipe constructor

func (*UnixNamedPipe) Close

func (p *UnixNamedPipe) Close() error

Close the underlying named pipe

func (*UnixNamedPipe) Open

func (p *UnixNamedPipe) Open() error

Open opens named pipe - will create it if doesn't exist

func (*UnixNamedPipe) Read

func (p *UnixNamedPipe) Read(b []byte) (int, error)

Read from the pipe

func (*UnixNamedPipe) Ready

func (p *UnixNamedPipe) Ready() bool

Ready is the pipe ready to read/write?

func (*UnixNamedPipe) Write

func (p *UnixNamedPipe) Write(b []byte) (int, error)

Write to the pipe

Directories

Path Synopsis
cri
providers/windows
Package windows We need a file in this package as it's referenced by a file built on windows
Package windows We need a file in this package as it's referenced by a file built on windows
ecs
Package ecs provides metadata collection when the Agent runs on the ECS platform
Package ecs provides metadata collection when the Agent runs on the ECS platform
metadata
Package metadata provides clients for Metadata APIs exposed by the ECS agent.
Package metadata provides clients for Metadata APIs exposed by the ECS agent.
Package executable provides information on the executable that started the process
Package executable provides information on the executable that started the process
validate
Package validate provides hostname validation helpers
Package validate provides hostname validation helpers

Jump to

Keyboard shortcuts

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