common

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2018 License: Apache-2.0 Imports: 25 Imported by: 150

Documentation

Index

Constants

View Source
const (
	// BPFCapability the probe is able to handle bpf filters
	BPFCapability ProbeCapability = 1
	// RawPacketsCapability the probe can capture raw packets
	RawPacketsCapability = 2
	// ExtraTCPMetricCapability the probe can report TCP metrics
	ExtraTCPMetricCapability = 4
)
View Source
const (
	AllPackets    = syscall.ETH_P_ALL
	OnlyIPPackets = syscall.ETH_P_IP
)
View Source
const (
	// StoppedState service stopped
	StoppedState = iota + 1
	// RunningState service running
	RunningState
	// StoppingState service stopping
	StoppingState
)

Variables

View Source
var (
	// CaptureTypes contains all registred capture type and associated probes
	CaptureTypes = map[string]CaptureType{}

	// ProbeCapabilities defines capability per probes
	ProbeCapabilities = map[string]ProbeCapability{}
)
View Source
var (
	// ErrInvalidPortRange invalid port range
	ErrInvalidPortRange = errors.New("Invalid port range")
	// ErrNoPortLeft no port left in the range
	ErrNoPortLeft = errors.New("No free port left")
)
View Source
var (
	// ErrCantCompareInterface error can't compare interface
	ErrCantCompareInterface = errors.New("Can't compare interface")
	// ErrFieldNotFound error field not found
	ErrFieldNotFound = errors.New("Field not found")
	// ErrFieldWrongType error field has wrong type
	ErrFieldWrongType = errors.New("Field has wrong type")
	// ErrNotFound error no result was found
	ErrNotFound = errors.New("No result found")
	// ErrTimeout network timeout
	ErrTimeout = errors.New("Timeout")
	// ErrNotImplemented unimplemented feature
	ErrNotImplemented = errors.New("Not implemented")
)

Functions

func CheckProbeCapabilities added in v0.15.0

func CheckProbeCapabilities(probeType string, capability ProbeCapability) bool

CheckProbeCapabilities checks that a probe supports given capabilities

func CrossTypeCompare added in v0.5.0

func CrossTypeCompare(a interface{}, b interface{}) (int, error)

CrossTypeCompare compare 2 differents number types like Float64 vs Float32

func CrossTypeEqual

func CrossTypeEqual(a interface{}, b interface{}) bool

CrossTypeEqual compare 2 differents number types

func DelField added in v0.12.0

func DelField(obj map[string]interface{}, k string) bool

DelField detete a value in a tree based on dot key

func GetField added in v0.12.0

func GetField(obj map[string]interface{}, k string) (interface{}, error)

GetField retrieves a value from a tree from the dot key like "a.b.c.d"

func GetFields added in v0.16.0

func GetFields(obj map[string]interface{}) ([]string, error)

GetFields returns all the keys using dot notation

func IPV4CIDRToRegex added in v0.13.0

func IPV4CIDRToRegex(cidr string) (string, error)

IPV4CIDRToRegex returns a regex matching IPs belonging to a given cidr

func IPv6Supported added in v0.8.0

func IPv6Supported() bool

IPv6Supported returns true if the platform support IPv6

func IsCaptureAllowed added in v0.5.0

func IsCaptureAllowed(nodeType string) bool

IsCaptureAllowed returns true if the node capture type exist

func IsIPv6 added in v0.15.0

func IsIPv6(str string) bool

IsIPv6 returns whether is a IPV6 addresses or not

func JSONDecode added in v0.12.0

func JSONDecode(r io.Reader, i interface{}) error

JSONDecode wrapper to UseNumber during JSON decoding

func MaxInt64

func MaxInt64(a, b int64) int64

MaxInt64 returns the biggest value

func MinInt64

func MinInt64(a, b int64) int64

MinInt64 returns the lowest value

func NormalizeAddrForURL added in v0.15.0

func NormalizeAddrForURL(addr string) string

NormalizeAddrForURL format the given address to be used in URL. For IPV6 addresses the brackets will be added.

func NormalizeIPForURL added in v0.19.0

func NormalizeIPForURL(ip net.IP) string

NormalizeIPForURL returns a string normalized that can be used in URL. Brackets will be used for IPV6 addresses.

func NormalizeValue added in v0.14.0

func NormalizeValue(obj interface{}) interface{}

NormalizeValue returns a version of the passed value that can be safely marshalled to JSON

func ProbeTypeForNode added in v0.16.0

func ProbeTypeForNode(nodeTYpe string, captureType string) (string, error)

ProbeTypeForNode returns the appropriate probe type for the given node type and capture type.

func RandString added in v0.20.0

func RandString(n int) string

RandString generates random string

func RangeToRegex added in v0.13.0

func RangeToRegex(min, max int) string

RangeToRegex returns a regular expression matching number in the given range Golang version of https://github.com/dimka665/range-regex

func Retry

func Retry(fnc func() error, try int, delay time.Duration) error

Retry tries to execute the given function until a success applying a delay between each try

func RetryExponential added in v0.18.0

func RetryExponential(fnc func() error, try int, baseDelay time.Duration) error

RetryExponential tries to execute the given function until a success applying a delay between each try. The delay is doubled after each try. Its initial value is baseDelay.

func SetField added in v0.12.0

func SetField(obj map[string]interface{}, k string, v interface{}) bool

SetField set a value in a tree based on dot key ("a.b.c.d" = "ok")

func SetupTLSClientConfig added in v0.12.0

func SetupTLSClientConfig(certPEM string, keyPEM string) (*tls.Config, error)

SetupTLSClientConfig creates a client X509 certificate from public and private key

func SetupTLSLoadCertificate added in v0.12.0

func SetupTLSLoadCertificate(certPEM string) (*x509.CertPool, error)

SetupTLSLoadCertificate creates a X509 certificate from file

func SetupTLSServerConfig added in v0.12.0

func SetupTLSServerConfig(certPEM string, keyPEM string) (*tls.Config, error)

SetupTLSServerConfig creates a server X509 certificate from public and private key

func StructFieldKeys added in v0.19.0

func StructFieldKeys(i interface{}) []string

StructFieldKeys returns field names of a structure

func ToFloat64 added in v0.8.0

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

ToFloat64 Convert all number like type to float64

func ToInt64 added in v0.8.0

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

ToInt64 Convert all number like type to int64

func UnixMillis added in v0.10.0

func UnixMillis(t time.Time) int64

UnixMillis returns the current time in miliseconds

Types

type CaptureType added in v0.7.0

type CaptureType struct {
	Allowed []string
	Default string
}

CaptureType describes a list of allowed and default captures probes

type Debouncer added in v0.16.0

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

Debouncer defines a debouncer object

func NewDebouncer added in v0.16.0

func NewDebouncer(interval time.Duration, callback func()) *Debouncer

NewDebouncer returns a Debouncer calling the given callback after a certain amount of time.

func (*Debouncer) Call added in v0.16.0

func (d *Debouncer) Call()

Call calls the callback of the Debouncer object

func (*Debouncer) Start added in v0.16.0

func (d *Debouncer) Start()

Start the debouncer

func (*Debouncer) Stop added in v0.16.0

func (d *Debouncer) Stop()

Stop stops the debouncer

type Iterator added in v0.6.0

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

Iterator describes a int64 iterator

func NewIterator added in v0.6.0

func NewIterator(values ...int64) (it *Iterator)

NewIterator creates a new iterator based on (at, from, to) parameters

func (*Iterator) Done added in v0.6.0

func (it *Iterator) Done() bool

Done returns true when the Iterator is at the end or uninitialized properly

func (*Iterator) Next added in v0.6.0

func (it *Iterator) Next() bool

Next returns true if we can continue to iterate

type Metric added in v0.10.0

type Metric interface {
	GetFieldInt64(field string) (int64, error)
	Add(m Metric) Metric
	Sub(m Metric) Metric
	Split(cut int64) (Metric, Metric)
	GetStart() int64
	SetStart(start int64)
	GetLast() int64
	SetLast(last int64)
	IsZero() bool
	GetFields() []string
}

Metric defines a common metric interface

type NetNSContext added in v0.8.0

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

NetNSContext describes a NameSpace Context switch API

func NewNetNsContext added in v0.8.0

func NewNetNsContext(path string) (*NetNSContext, error)

NewNetNsContext creates a new NameSpace context base on path

func (*NetNSContext) Close added in v0.8.0

func (n *NetNSContext) Close()

Close the NameSpace

func (*NetNSContext) Quit added in v0.8.0

func (n *NetNSContext) Quit() error

Quit the NameSpace and go back to the original one

type PortAllocator added in v0.10.0

type PortAllocator struct {
	RWMutex
	MinPort int
	MaxPort int
	PortMap map[int]bool
}

PortAllocator describes a threads safe port list that can be allocated

func NewPortAllocator added in v0.10.0

func NewPortAllocator(min, max int) (*PortAllocator, error)

NewPortAllocator creates a new port allocator range

func (*PortAllocator) Allocate added in v0.10.0

func (p *PortAllocator) Allocate() (int, error)

Allocate returns a new port between min and max ports.

func (*PortAllocator) Release added in v0.10.0

func (p *PortAllocator) Release(i int) error

Release a port

func (*PortAllocator) ReleaseAll added in v0.10.0

func (p *PortAllocator) ReleaseAll()

ReleaseAll ports

type ProbeCapability added in v0.15.0

type ProbeCapability int

ProbeCapability defines probe capability

type RWMutex added in v0.18.0

type RWMutex struct {
	sync.RWMutex
}

RWMutex is a wrapper around sync.RWMutex

type RawSocket added in v0.12.0

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

RawSocket describes a raw socket C implemenation

func NewRawSocket added in v0.12.0

func NewRawSocket(ifName string, protocol int) (*RawSocket, error)

NewRawSocket creates a raw socket for the network interface ifName

func NewRawSocketInNs added in v0.12.0

func NewRawSocketInNs(nsPath string, ifName string, protocol int) (*RawSocket, error)

NewRawSocketInNs create/open a socket in the namespace nsPath for the network interface ifName

func (*RawSocket) Close added in v0.12.0

func (s *RawSocket) Close() error

Close the file descriptor

func (*RawSocket) GetFd added in v0.12.0

func (s *RawSocket) GetFd() int

GetFd returns the file descriptor

func (*RawSocket) Write added in v0.16.0

func (s *RawSocket) Write(data []byte) (int, error)

Write outputs some bytes to the file

type ServiceAddress added in v0.10.0

type ServiceAddress struct {
	Addr string
	Port int
}

ServiceAddress describes the service listening address and port

func ServiceAddressFromString added in v0.10.0

func ServiceAddressFromString(addressPort string) (ServiceAddress, error)

ServiceAddressFromString returns a service address from a string, could be IPv4 or IPv6

func (ServiceAddress) String added in v0.14.0

func (sa ServiceAddress) String() string

type ServiceType added in v0.10.0

type ServiceType string

ServiceType describes the service type (analyzer or agent)

const (
	// UnknownService for unknown client types
	UnknownService ServiceType = "unknown"
	// AnalyzerService analyzer
	AnalyzerService ServiceType = "analyzer"
	// AgentService agent
	AgentService ServiceType = "agent"
)

func (ServiceType) String added in v0.10.0

func (st ServiceType) String() string

type SortOrder added in v0.10.0

type SortOrder string

SortOrder describes ascending or descending order

const (
	// SortAscending sorting order
	SortAscending SortOrder = "ASC"
	// SortDescending sorting order
	SortDescending SortOrder = "DESC"
)

type TimeSlice added in v0.10.0

type TimeSlice struct {
	Start int64 `json:"Start"`
	Last  int64 `json:"Last"`
}

TimeSlice defines a time boudary values

func NewTimeSlice added in v0.10.0

func NewTimeSlice(s, l int64) *TimeSlice

NewTimeSlice creates a new TimeSlice based on Start and Last

Jump to

Keyboard shortcuts

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