utils

package
v0.0.0-...-898015a Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MetricsLineSep is the line separator used by the alerts metric
	MetricsLineSep = []byte{'\n'}
)

Functions

func CountLines

func CountLines(r io.Reader) (int, error)

CountLines reads the remainder of the reader and counts the number of lines.

Inspired by: https://stackoverflow.com/a/24563853/

func ErrorsToStrings

func ErrorsToStrings(errs []error) []string

ErrorsToStrings turns error slice to string slice

func GetAllNamespaces

func GetAllNamespaces(ctx context.Context, coreClient corev1client.CoreV1Interface) (*corev1.NamespaceList, error)

func GetClusterBaseDomain

func GetClusterBaseDomain(ctx context.Context, configClient configv1client.ConfigV1Interface) (string, error)

GetClusterBaseDomain returns a base domain for the cluster. Base domain is the base domain of the cluster. All managed DNS records will be subdomains of this base.

For example, given the base domain `openshift.example.com`, an API server DNS record may be created for `cluster-api.openshift.example.com`.

It uses this API https://docs.openshift.com/container-platform/4.7/rest_api/config_apis/dns-config-openshift-io-v1.html

func MaxInt

func MaxInt(values ...int) int

MaxInt returns maximum value of ints

func MinInt

func MinInt(values ...int) int

MinInt returns minimal value of ints

func NestedInt64Wrapper

func NestedInt64Wrapper(obj map[string]interface{}, fields ...string) (int64, error)

func NestedSliceWrapper

func NestedSliceWrapper(obj map[string]interface{}, fields ...string) ([]interface{}, error)

func NestedStringWrapper

func NestedStringWrapper(obj map[string]interface{}, fields ...string) (string, error)

func NewTestLog

func NewTestLog(t testing.TB) *log.Logger

func ReadAllLinesWithPrefix

func ReadAllLinesWithPrefix(reader io.Reader, prefix []byte, lineFunc func(b []byte) []byte) ([]byte, error)

ReadAllLinesWithPrefix reads lines from the given reader and returns those that begin with the specified prefix.

func ShouldBeProcessedNow

func ShouldBeProcessedNow(lastProcessingTime time.Time, period time.Duration) bool

ShouldBeProcessedNow useful function for gatherers with custom period

func SortAndRemoveDuplicates

func SortAndRemoveDuplicates(slicePtr interface{}, less func(i, j int) bool)

SortAndRemoveDuplicates sorts the slice pointed by the provided pointer given the provided less function and removes repeated elements. The function panics if the provided interface is not a pointer to a slice.

func StringInSlice

func StringInSlice(str string, slice []string) bool

StringInSlice simply checks if the string is present in slice

func StructToMap

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

func SumErrors

func SumErrors(errs []error) error

SumErrors simply sorts the errors and joins them with commas

func TakeLastNItemsFromByteArray

func TakeLastNItemsFromByteArray(array []byte, desiredLength int) []byte

TakeLastNItemsFromByteArray takes last N items from provided byte array or adds zeros to the beginning if there not enough space

func UniqueStrings

func UniqueStrings(list []string) []string

UniqueStrings returns a new string slice where each element exists maximum once, the order of items is preserved (e.g. [9, 4, 9, 8, 1, 2, 2, 4, 3] becomes [9, 4, 8, 1, 2, 3])

Types

type LineLimitedReader

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

A LineLimitedReader reads from R but limits the amount of data returned to just N lines. Each call to Read updates N to reflect the new amount remaining. Read returns EOF when N <= 0 or when the underlying R returns EOF.

func NewLineLimitReader

func NewLineLimitReader(r io.Reader, n int) *LineLimitedReader

NewLineLimitReader returns a Reader that reads from `r` but stops with EOF after `n` lines.

func (*LineLimitedReader) GetTotalLinesRead

func (l *LineLimitedReader) GetTotalLinesRead() int

GetTotalLinesRead return the total number of line separators already read by the underlying reader. This includes lines that have been truncated by the `Read` calls after exceeding the line limit.

func (*LineLimitedReader) Read

func (l *LineLimitedReader) Read(p []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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