util

package
v0.0.0-...-932836e Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecimalExponentialBuckets

func DecimalExponentialBuckets(lowestPowerOf10 int, powersOf10 int, stepsInBetween int) []float64

DecimalExponentialBuckets generates a series of exponential bucket boundaries that can be used for Prometheus histogram objects. Instead of using powers of 2, this function uses 10^(1/m) as the exponent. This has the advantage of yielding round numbers at every power of ten.

Instead of computing the actual value of 10^(n/m), we first compute values that are up to five digits accurate within a single power of 10. This is done to ensure that the metric label name remains short and unaffected by the precision of math libraries and hardware floating point units.

Under the hood, strconv.ParseFloat() is used. Unlike math.Pow(), it ensures that the resulting floating point value is the one that yields the desired shortest decimal representation.

func NewTLSConfigFromClientConfiguration

func NewTLSConfigFromClientConfiguration(configuration *configuration.ClientConfiguration) (*tls.Config, error)

NewTLSConfigFromClientConfiguration creates a TLS configuration object based on parameters specified in a Protobuf message for use with a TLS client. This Protobuf message is embedded in Buildbarn configuration files.

func NewTLSConfigFromServerConfiguration

func NewTLSConfigFromServerConfiguration(configuration *configuration.ServerConfiguration) (*tls.Config, error)

NewTLSConfigFromServerConfiguration creates a TLS configuration object based on parameters specified in a Protobuf message for use with a TLS server. This Protobuf message is embedded in Buildbarn configuration files.

func RegisterAdministrativeHTTPEndpoints

func RegisterAdministrativeHTTPEndpoints(router *mux.Router)

RegisterAdministrativeHTTPEndpoints registers HTTP endpoints that are used by all Buildbarn services.

func StatusFromContext

func StatusFromContext(ctx context.Context) error

StatusFromContext converts the error associated with a context to a gRPC Status error. This function ensures that errors such as context.DeadlineExceeded are properly converted to Status objects having the code DEADLINE_EXCEEDED.

func StatusWrap

func StatusWrap(err error, msg string) error

StatusWrap prepends a string to the message of an existing error.

func StatusWrapWithCode

func StatusWrapWithCode(err error, code codes.Code, msg string) error

StatusWrapWithCode prepends a string to the message of an existing error, while replacing the error code.

func StatusWrapf

func StatusWrapf(err error, format string, args ...interface{}) error

StatusWrapf prepends a formatted string to the message of an existing error.

func StatusWrapfWithCode

func StatusWrapfWithCode(err error, code codes.Code, format string, args ...interface{}) error

StatusWrapfWithCode prepends a formatted string to the message of an existing error, while replacing the error code.

func UnmarshalConfigurationFromFile

func UnmarshalConfigurationFromFile(path string, configuration proto.Message) error

UnmarshalConfigurationFromFile reads a Jsonnet file, evaluates it and unmarshals the output into a Protobuf message.

Types

type ErrorLogger

type ErrorLogger interface {
	Log(err error)
}

ErrorLogger may be used to report errors. Implementations may decide to log, mutate, redirect and discard them. This interface is used in places where errors are generated asynchronously, meaning they cannot be returned to the caller directly.

var DefaultErrorLogger ErrorLogger = defaultErrorLogger{}

DefaultErrorLogger writes errors using Go's standard logging package.

type UUIDGenerator

type UUIDGenerator func() (uuid.UUID, error)

UUIDGenerator is equal to the signature of the UUID library's UUID generation functions. It is used within this codebase to make the generator injectable as part of unit tests.

Jump to

Keyboard shortcuts

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