util

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelToSnake

func CamelToSnake(str string) string

CamelToSnake is a helper function for converting CamelCase to Snake Case

func CompareYAML

func CompareYAML(a, b interface{}) bool

CompareYAML marshals a and b to YAML and ensures that their contents are equal. If either Marshal fails, CompareYAML returns false.

func CompareYAMLWithHook

func CompareYAMLWithHook(a, b interface{}, hook func(in interface{}) (ok bool, out interface{}, err error)) bool

CompareYAMLWithHook marshals both a and b to YAML and checks the results for equality, allowing for a hook to define custom marshaling behavior. If either Marshal fails, CompareYAMLWithHook returns false.

func DefaultConfigFromFlags

func DefaultConfigFromFlags(cfg interface{}) interface{}

DefaultConfigFromFlags will load default values into cfg by retrieving default values that are registered as flags.

cfg must implement either PrefixedConfigFlags or ConfigFlags.

func EnableOtelFeatureGates

func EnableOtelFeatureGates(fgNames ...string) error

Enables a set of feature gates in Otel's Global Feature Gate Registry.

func Eventually

func Eventually(t require.TestingT, check func(t require.TestingT))

Eventually calls the check function several times until it doesn't report an error. Failing the test in the t provided to check does not fail the test until the provided backoff.Config is out of retries.

func EventuallyWithBackoff

func EventuallyWithBackoff(t require.TestingT, check func(t require.TestingT), bc backoff.Config)

func MarshalYAMLMerged

func MarshalYAMLMerged(vv ...interface{}) ([]byte, error)

MarshalYAMLMerged marshals all values from vv into a single object.

func MustRegisterOrGet

MustRegisterOrGet will attempt to register the supplied collector into the register. If it's already registered, it will return that one. In case that the register procedure fails with something other than already registered, this will panic.

func SetupOtelFeatureGates

func SetupOtelFeatureGates() error

Enables a set of feature gates which should always be enabled in Alloy.

func TestAlloyLogger

func TestAlloyLogger(t require.TestingT) *logging.Logger

TestAlloyLogger generates an Alloy-compatible logger for a test.

func TestLogger

func TestLogger(t testing.TB) log.Logger

TestLogger generates a logger for a test.

func UnmarshalYAMLMerged

func UnmarshalYAMLMerged(bb []byte, vv ...interface{}) error

UnmarshalYAMLMerged performs a strict unmarshal of bb into all values from vv.

func Untab

func Untab(s string) string

Untab is a utility function for tests to make it easier to write YAML tests, where some editors will insert tabs into strings by default.

func Untar

func Untar(tarPath string, destPath string) error

Untar untars a tarball to the provided destination path.

Types

type ConfigFlags

type ConfigFlags interface {
	RegisterFlags(f *flag.FlagSet)
}

ConfigFlags is an interface that will register flags that can control some object.

type PrefixedConfigFlags

type PrefixedConfigFlags interface {
	RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)
}

PrefixedConfigFlags is an interface that, given a prefix for flags and a flagset, will register flags that can control some object.

type RawYAML

type RawYAML []byte

RawYAML is similar to json.RawMessage and allows for deferred YAML decoding.

func (RawYAML) Map

func (r RawYAML) Map() (yaml.MapSlice, error)

Map converts the raw YAML into a yaml.MapSlice.

func (RawYAML) MarshalYAML

func (r RawYAML) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler.

func (*RawYAML) UnmarshalYAML

func (r *RawYAML) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler.

type UncheckedCollector

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

UncheckedCollector is a prometheus.Collector which stores a set of unchecked metrics.

func NewUncheckedCollector

func NewUncheckedCollector(inner prometheus.Collector) *UncheckedCollector

NewUncheckedCollector creates a new UncheckedCollector. If inner is nil, UncheckedCollector returns no metrics.

func (*UncheckedCollector) Collect

func (uc *UncheckedCollector) Collect(ch chan<- prometheus.Metric)

Collector implements prometheus.Collector. If the UncheckedCollector has a non-nil inner collector, metrics will be collected from it.

func (*UncheckedCollector) Describe

func (uc *UncheckedCollector) Describe(_ chan<- *prometheus.Desc)

Describe implements prometheus.Collector, but is a no-op to be considered an "unchecked" collector by Prometheus. See prometheus.Collector for more information.

func (*UncheckedCollector) SetCollector

func (uc *UncheckedCollector) SetCollector(inner prometheus.Collector)

SetCollector replaces the inner collector.

type WaitTrigger

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

WaitTrigger allows for waiting for a specific condition to be met. Useful for tests.

func NewWaitTrigger

func NewWaitTrigger() *WaitTrigger

NewWaitTrigger creates a new WaitTrigger.

func (*WaitTrigger) Trigger

func (wt *WaitTrigger) Trigger()

Trigger completes the trigger and alerts all waiting. Calling Trigger again after the first invocation is a no-op.

func (*WaitTrigger) Wait

func (wt *WaitTrigger) Wait(timeout time.Duration) error

Wait waits for trigger to complete up to the specified timeout. Returns an error if the timeout expires.

func (*WaitTrigger) WaitContext

func (wt *WaitTrigger) WaitContext(ctx context.Context) error

WaitContext waits for trigger to complete or for the context to cancel. Returns an error if ctx gets canceled.

Directories

Path Synopsis
Package testappender exposes utilities to test code which writes to Prometheus storage.Appenders.
Package testappender exposes utilities to test code which writes to Prometheus storage.Appenders.
Package zapadapter allows github.com/go-kit/log to be used as a Zap core.
Package zapadapter allows github.com/go-kit/log to be used as a Zap core.

Jump to

Keyboard shortcuts

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