Documentation ¶
Overview ¶
Package utils hold miscelaneous utility functions
Index ¶
- func BoolToInt(b bool) int
- func ChunkScanner(output io.ReadCloser) *bufio.Scanner
- func CloneAndExcludeStringMapByKey(in map[string]string, exclude map[string]bool) map[string]string
- func CloneAndFilterStringMapWithFunc(in map[string]string, filter func(string, string) bool) (out map[string]string)
- func CloneInterface(a interface{}) interface{}
- func CloneStringMap(m map[string]string) map[string]string
- func ConvertToMapViaYAML(obj interface{}) (map[string]interface{}, error)
- func DatapointToString(dp *datapoint.Datapoint) string
- func Debounce0(fn func(), duration time.Duration) (func(), chan<- struct{})
- func DecodeValueGenerically(val string) interface{}
- func DuplicateInterfaceMapKeysAsCamelCase(m map[string]interface{}) map[string]interface{}
- func EnsurePrefix(s, prefix string) string
- func FindFieldWithEmbeddedStructs(st interface{}, name string, typ reflect.Type) reflect.Value
- func FirstNonEmpty(s ...string) string
- func FirstNonZero(ns ...int) int
- func GetStructFieldNames(s interface{}) []string
- func IndentLines(ss string, spaces int) string
- func InterfaceMapToStringMap(m map[interface{}]interface{}) map[string]string
- func InterfaceSliceToStringSlice(is []interface{}) []string
- func IsSignalChanClosed(ch <-chan struct{}) bool
- func IsStructOrPointerToStruct(typ reflect.Type) bool
- func LowercaseFirstChar(s string) string
- func MakeRange(min, max int) []int
- func MaxInt(x, y int) int
- func MergeInterfaceMaps(maps ...map[string]interface{}) map[string]interface{}
- func MergeStringMaps(maps ...map[string]string) map[string]string
- func MinInt(x, y int) int
- func NewIDGenerator() func() string
- func ParseLineNumberFromYAMLError(e string) int
- func RegexpGroupMap(re *regexp.Regexp, text string) map[string]string
- func RemoveAllElementsFromStringSlice(inputStrings []string, toRemoveStrings []string) []string
- func RemoveEmptyMapValues(m map[string]string) map[string]string
- func RunOnArrayOfIntervals(ctx context.Context, fn func(), intervals []time.Duration, ...)
- func RunOnInterval(ctx context.Context, fn func(), interval time.Duration)
- func SortMapKeys(m map[string]interface{}) []string
- func StringInterfaceMapToAllInterfaceMap(in map[string]interface{}) map[interface{}]interface{}
- func StringMapToInterfaceMap(m map[string]string) map[string]interface{}
- func StringSetToSlice(set map[string]bool) []string
- func StringSliceToMap(strings []string) map[string]bool
- func StripIndent(s string) string
- func UniqueStrings(strings []string) []string
- func YAMLNameOfField(field reflect.StructField) string
- func YAMLNameOfFieldInStruct(fieldName string, st interface{}) string
- type LogrusGolibShim
- type RepeatPolicy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolToInt ¶
BoolToInt returns 1 if b is true and 0 otherwise. It is useful for datapoints which track a binary value since we don't support boolean datapoint directly.
func ChunkScanner ¶
func ChunkScanner(output io.ReadCloser) *bufio.Scanner
ChunkScanner looks for a line and all subsequent indented lines and returns a scanner that will output that chunk as a single token. This assumes that the entire chunk comes in a single read call, which will not always be the case.
func CloneAndExcludeStringMapByKey ¶
CloneAndExcludeStringMapByKey clones a string map excluding the specified keys
func CloneAndFilterStringMapWithFunc ¶
func CloneAndFilterStringMapWithFunc(in map[string]string, filter func(string, string) bool) (out map[string]string)
CloneAndFilterStringMapWithFunc clones a string map and only includes key/value pairs for which the filter function returns true
func CloneInterface ¶
func CloneInterface(a interface{}) interface{}
CloneInterface takes an object and returns a copy of it regardless of whether it is really a pointer underneath or not. It is roughly equivalent to the following: b = *a (if 'a' is a pointer) b = a (if 'a' is not a pointer)
func CloneStringMap ¶
CloneStringMap makes a shallow copy of a map[string]string
func ConvertToMapViaYAML ¶
ConvertToMapViaYAML takes a struct and converts it to map[string]interface{} by marshalling it to yaml and back to a map. This will return nil if the conversion was not successful.
func DatapointToString ¶
DatapointToString pretty prints a datapoint in a consistent manner for logging purposes. The most important thing here is to sort the dimension dict so it is consistent so that it is easier to visually scan a large list of datapoints.
func DecodeValueGenerically ¶
func DecodeValueGenerically(val string) interface{}
DecodeValueGenerically apply some very basic heuristics to decode string values to the most sensible type for use in config structs.
func DuplicateInterfaceMapKeysAsCamelCase ¶
DuplicateInterfaceMapKeysAsCamelCase takes a map[string]interface{} and camel cases the keys
func EnsurePrefix ¶
EnsurePrefix ensures that string s starts with the given prefix. If it already starts with that prefix, the original string is returned unaltered.
func FindFieldWithEmbeddedStructs ¶
FindFieldWithEmbeddedStructs will look for a field with the given name, recursing down into embedded structs if there are any.
func FirstNonEmpty ¶
FirstNonEmpty returns the first string that is not empty, otherwise ""
func FirstNonZero ¶
FirstNonZero returns the first int in `ns` that is not zero.
func GetStructFieldNames ¶
func GetStructFieldNames(s interface{}) []string
GetStructFieldNames returns a slice with the names of all of the fields in the struct `s`. This will panic if `s` is not a struct.
func IndentLines ¶
IndentLines indents all lines in `ss` by `spaces` number of spaces
func InterfaceMapToStringMap ¶
InterfaceMapToStringMap converts a map[interface{}]interface{} to a map[string]string. Keys and values will be converted with fmt.Sprintf so the original key/values don't have to be strings.
func InterfaceSliceToStringSlice ¶
func InterfaceSliceToStringSlice(is []interface{}) []string
InterfaceSliceToStringSlice returns a new slice that contains the elements of `is` as strings. Returns nil if any of the elements of `is` are not strings.
func IsSignalChanClosed ¶
func IsSignalChanClosed(ch <-chan struct{}) bool
IsSignalChanClosed returns whether a channel is closed that is used only for the sake of sending a single singal. The channel should never be sent any actual values, but should only be closed to tell other goroutines to stop.
func IsStructOrPointerToStruct ¶
IsStructOrPointerToStruct returns true if the given reflect.Type is a struct or pointer to a struct
func LowercaseFirstChar ¶
LowercaseFirstChar make the first character of a string lowercase
func MergeInterfaceMaps ¶
MergeInterfaceMaps merges any number of map[string]interface{} with a later map's keys overriding earlier maps. Nil values do not override earlier values.
func MergeStringMaps ¶
MergeStringMaps merges n maps with a later map's keys overriding earlier maps
func NewIDGenerator ¶
func NewIDGenerator() func() string
NewIDGenerator returns a function that will produce, for any given generator instance, a unique, non-empty, string value each time it is called.
func ParseLineNumberFromYAMLError ¶
ParseLineNumberFromYAMLError takes an error message nested in yaml.TypeError and returns a line number if indicated in the error message. This is pretty hacky but is the only way to actually get at the line number in the standard yaml package.
func RegexpGroupMap ¶
RegexpGroupMap matches text against the given regexp and returns a map of all of the named subgroups to the values found in text. Returns nil if text does not match.
func RemoveAllElementsFromStringSlice ¶
RemoveAllElementsFromStringSlice removes all elements from toRemove that exists in inputStrings
func RemoveEmptyMapValues ¶
RemoveEmptyMapValues will strip a map of any key/value pairs for which the value is the empty string.
func RunOnArrayOfIntervals ¶
func RunOnArrayOfIntervals(ctx context.Context, fn func(), intervals []time.Duration, repeatPolicy RepeatPolicy)
RunOnArrayOfIntervals the given function once on the specified intervals, and repeat according to the supplied RepeatPolicy. Please note the function is executed after the first interval. If you want the function executed immediately, you should specify a duration of 0 as the first element in the intervals array.
func RunOnInterval ¶
RunOnInterval the given fn once every interval, starting at the moment the function is called. Returns a function that can be called to stop running the function.
func SortMapKeys ¶
SortMapKeys returns a slice of all of the keys of a map sorted alphabetically ascending.
func StringInterfaceMapToAllInterfaceMap ¶
func StringInterfaceMapToAllInterfaceMap(in map[string]interface{}) map[interface{}]interface{}
StringInterfaceMapToAllInterfaceMap converts a map[string]interface{} to a map[interface{}]interface{}
func StringMapToInterfaceMap ¶
StringMapToInterfaceMap converts a map[string]string to a map[string]interface{}.
func StringSetToSlice ¶
StringSetToSlice converts a map representing a set into a slice of strings
func StringSliceToMap ¶
StringSliceToMap converts a slice of strings into a map with keys from the slice
func StripIndent ¶
StripIndent looks at the first line in s and strips off whatever whitespace indentation it has from every line in s. If subsequent lines do not start with the same indentation as the first line, results are undefined. If the first line is blank, it will be removed before processing.
func UniqueStrings ¶
UniqueStrings returns a slice with the unique set of strings from the input
func YAMLNameOfField ¶
func YAMLNameOfField(field reflect.StructField) string
YAMLNameOfField returns the YAML key that is used for the given struct field. It does this by actually serializing the field and parsing the output string. If the field has no key (e.g. if the `yaml:"-"` tag is set, this will return an empty string.
func YAMLNameOfFieldInStruct ¶
YAMLNameOfFieldInStruct returns the YAML key that is used for the given struct field, looking up fieldName in the given st struct. If the field has no key (e.g. if the `yaml:"-"` tag is set, this will return an empty string. It uses YAMLNameOfField under the covers. If st is not a struct, this will panic.
Types ¶
type LogrusGolibShim ¶
type LogrusGolibShim struct {
logrus.FieldLogger
}
LogrusGolibShim makes a Logrus logger conform to the golib Log interface
func (*LogrusGolibShim) Log ¶
func (l *LogrusGolibShim) Log(keyvals ...interface{})
Log conforms to the golib Log interface
type RepeatPolicy ¶
type RepeatPolicy int
RepeatPolicy repeat behavior for RunOnIntervals Function
const ( // RepeatAll repeats all intervals RepeatAll RepeatPolicy = iota // RepeatLast repeats only the last interval RepeatLast // RepeatNone does not repeat RepeatNone )
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package filter contains common filtering logic that can be used to filter datapoints or various resources within other agent components, such as monitors.
|
Package filter contains common filtering logic that can be used to filter datapoints or various resources within other agent components, such as monitors. |
network
|
|