Documentation
¶
Index ¶
- Constants
- func AnyErrorIsRetryable(err error) bool
- func ApplyJitter(input int) (output int)
- func DirExists(directory string) bool
- func ExponentialBackOffDelay(n uint, config *RetryConfig) time.Duration
- func ExponentialJitterBackoffDelay(n uint, config *RetryConfig) time.Duration
- func FileExists(filename string) bool
- func FixedDelay(_ uint, config *RetryConfig) time.Duration
- func GetCommandInDirectoryOutput(ctx context.Context, dir string, command string, args ...interface{}) (string, error)
- func GetCommandOutput(ctx context.Context, command string, args ...interface{}) (string, error)
- func GetCommandWithArgsInDirectoryOutput(ctx context.Context, dir string, command string, args []string) (string, error)
- func GetCommandWithArgsOutput(ctx context.Context, command string, args []string) (string, error)
- func HandleError(err error)
- func HandleGracefulShutdown(gracefulShutdown chan os.Signal, waitGroup *sync.WaitGroup, ...)
- func InitCancellationContext(ctx context.Context) context.Context
- func InitGracefulShutdownHandling() (gracefulShutdown chan os.Signal, waitGroup *sync.WaitGroup)
- func InitLiveness()
- func InitLivenessAndReadiness()
- func InitLivenessAndReadinessWithPort(port int)
- func InitLivenessWithPort(port int)
- func InitLoggingByFormat(applicationInfo ApplicationInfo, logFormat string)
- func InitLoggingByFormatSilent(applicationInfo ApplicationInfo, logFormat string)
- func InitLoggingFromEnv(applicationInfo ApplicationInfo)
- func InitMetrics()
- func InitMetricsWithPort(port int)
- func InitReadiness()
- func InitReadinessWithPort(port int)
- func InitTracingFromEnv(app string) io.Closer
- func IntArrayContains(array []int, search int) bool
- func PathExists(path string) bool
- func Retry(retryableFunc func() error, opts ...RetryOption) error
- func RunCommand(ctx context.Context, command string, args ...interface{})
- func RunCommandExtended(ctx context.Context, command string, args ...interface{}) error
- func RunCommandExtendedCombinedStdErr(ctx context.Context, command string, args ...interface{}) error
- func RunCommandInDirectory(ctx context.Context, dir string, command string, args ...interface{})
- func RunCommandInDirectoryExtended(ctx context.Context, dir string, command string, args ...interface{}) error
- func RunCommandInDirectoryExtendedCombinedStdErr(ctx context.Context, dir string, command string, args ...interface{}) error
- func RunCommandInDirectoryWithArgs(ctx context.Context, dir string, command string, args []string)
- func RunCommandInDirectoryWithArgsExtended(ctx context.Context, dir string, command string, args []string) error
- func RunCommandInDirectoryWithArgsExtendedCombinedStdErr(ctx context.Context, dir string, command string, args []string) error
- func RunCommandWithArgs(ctx context.Context, command string, args []string)
- func RunCommandWithArgsExtended(ctx context.Context, command string, args []string) error
- func RunCommandWithArgsExtendedCombinedStdErr(ctx context.Context, command string, args []string) error
- func RunCommandWithArgsExtendedWithoutLog(ctx context.Context, command string, args []string) error
- func RunCommandWithArgsWithoutLog(ctx context.Context, command string, args []string)
- func SetLoggingLevelFromEnv()
- func StringArrayContains(array []string, search string) bool
- func ToLowerSnakeCase(in string) string
- func ToUpperSnakeCase(in string) string
- func WatchForFileChanges(filePath string, functionOnChange func(fsnotify.Event))
- type ApplicationInfo
- type DelayTypeFunc
- type IsRetryableErrorFunc
- type RetryConfig
- type RetryError
- type RetryOption
- type Semaphore
Constants ¶
const ( // LogFormatPlainText outputs logs in plain text without colorization and with timestamp; is the default if log format isn't specified LogFormatPlainText = "plaintext" // LogFormatConsole outputs logs in plain text with colorization and without timestamp LogFormatConsole = "console" // LogFormatJSON outputs logs in json including appgroup, app, appversion and other metadata LogFormatJSON = "json" // LogFormatStackdriver outputs a format similar to JSON format but with 'severity' instead of 'level' field LogFormatStackdriver = "stackdriver" // LogFormatV3 ouputs an internal format used at Travix in JSON format with nested payload and a specific set of required metadata LogFormatV3 = "v3" )
Variables ¶
This section is empty.
Functions ¶
func AnyErrorIsRetryable ¶
AnyErrorIsRetryable is a IsRetryableErrorFunc which returns whether an error should be retried
func ApplyJitter ¶
ApplyJitter adds +-25% jitter to the input
func ExponentialBackOffDelay ¶
func ExponentialBackOffDelay(n uint, config *RetryConfig) time.Duration
ExponentialBackOffDelay is a DelayType which increases delay between consecutive retries exponentially
func ExponentialJitterBackoffDelay ¶
func ExponentialJitterBackoffDelay(n uint, config *RetryConfig) time.Duration
ExponentialJitterBackoffDelay returns ever increasing backoffs by a power of 2 with +/- 0-25% to prevent sychronized requests.
func FixedDelay ¶
func FixedDelay(_ uint, config *RetryConfig) time.Duration
FixedDelay is a DelayType which keeps delay the same through all iterations
func GetCommandInDirectoryOutput ¶
func GetCommandInDirectoryOutput(ctx context.Context, dir string, command string, args ...interface{}) (string, error)
GetCommandInDirectoryOutput runs a full command string and replaces placeholders with the arguments from the specified directory; it returns the output as a string and an error if command execution failed output, err := GetCommandInDirectoryOutput(ctx, "directory other than working dir", "kubectl logs -l app=%v -n %v", app, namespace)
func GetCommandOutput ¶
GetCommandOutput runs a full command string and replaces placeholders with the arguments; it returns the output as a string and an error if command execution failed output, err := GetCommandOutput(ctx, "kubectl logs -l app=%v -n %v", app, namespace)
func GetCommandWithArgsInDirectoryOutput ¶
func GetCommandWithArgsInDirectoryOutput(ctx context.Context, dir string, command string, args []string) (string, error)
GetCommandWithArgsInDirectoryOutput runs a single command and passes the arguments from the specified directory; it returns the output as a string and an error if command execution failed output, err := GetCommandWithArgsOutput(ctx, "directory other than working dir", "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func GetCommandWithArgsOutput ¶
GetCommandWithArgsOutput runs a single command and passes the arguments; it returns the output as a string and an error if command execution failed output, err := GetCommandWithArgsOutput(ctx, "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func HandleGracefulShutdown ¶
func HandleGracefulShutdown(gracefulShutdown chan os.Signal, waitGroup *sync.WaitGroup, functionsOnShutdown ...func())
HandleGracefulShutdown waits for SIGTERM to unblock gracefulShutdown and waits for the waitgroup to await pending work
func InitCancellationContext ¶
InitCancellationContext adds cancelation to a context and on sigterm triggers the cancel function
func InitGracefulShutdownHandling ¶
InitGracefulShutdownHandling generates the channel that listens to SIGTERM and a waitgroup to use for finishing work when shutting down
func InitLiveness ¶
func InitLiveness()
InitLiveness initializes the /liveness endpoint on port 5000
func InitLivenessAndReadiness ¶
func InitLivenessAndReadiness()
InitLivenessAndReadiness initializes the /liveness and /readiness endpoint on port 5000
func InitLivenessAndReadinessWithPort ¶
func InitLivenessAndReadinessWithPort(port int)
InitLivenessAndReadinessWithPort initializes the /liveness and /readiness endpoint on specified port
func InitLivenessWithPort ¶
func InitLivenessWithPort(port int)
InitLivenessWithPort initializes the /liveness endpoint on specified port
func InitLoggingByFormat ¶
func InitLoggingByFormat(applicationInfo ApplicationInfo, logFormat string)
InitLoggingByFormat initalializes a logger with specified format and outputs a startup message
func InitLoggingByFormatSilent ¶
func InitLoggingByFormatSilent(applicationInfo ApplicationInfo, logFormat string)
InitLoggingByFormatSilent initializes a logger with specified format without outputting a startup message
func InitLoggingFromEnv ¶
func InitLoggingFromEnv(applicationInfo ApplicationInfo)
InitLoggingFromEnv initalializes a logger with format specified in envvar ZIPLINEE_LOG_FORMAT and outputs a startup message
func InitMetrics ¶
func InitMetrics()
InitMetrics initializes the prometheus endpoint /metrics on port 9101
func InitMetricsWithPort ¶
func InitMetricsWithPort(port int)
InitMetricsWithPort initializes the prometheus endpoint /metrics on specified port
func InitReadiness ¶
func InitReadiness()
InitReadiness initializes the /readiness endpoint on port 5000
func InitReadinessWithPort ¶
func InitReadinessWithPort(port int)
InitReadinessWithPort initializes the /readiness endpoint on specified port
func InitTracingFromEnv ¶
InitTracingFromEnv initializes a Jaeger Tracer and returns a closer which can be defer closed in your main routine https://github.com/jaegertracing/jaeger-client-go#environment-variables
func IntArrayContains ¶
IntArrayContains checks if an array contains a specific value
func Retry ¶
func Retry(retryableFunc func() error, opts ...RetryOption) error
Retry retries a function
func RunCommand ¶
RunCommand runs a full command string and replaces placeholders with the arguments; it logs a fatal on error RunCommand(ctx, "kubectl logs -l app=%v -n %v", app, namespace)
func RunCommandExtended ¶
RunCommandExtended runs a full command string and replaces placeholders with the arguments; it returns an error if command execution failed err := RunCommandExtended(ctx, "kubectl logs -l app=%v -n %v", app, namespace)
func RunCommandExtendedCombinedStdErr ¶
func RunCommandExtendedCombinedStdErr(ctx context.Context, command string, args ...interface{}) error
RunCommandExtended runs a full command string and replaces placeholders with the arguments; it returns an error combined stderr if command execution failed err := RunCommandExtended(ctx, "kubectl logs -l app=%v -n %v", app, namespace)
func RunCommandInDirectory ¶
RunCommandInDirectory runs a full command string and replaces placeholders with the arguments from the specified directory; it logs a fatal on error RunCommandInDirectory(ctx, "directory other than working dir", "kubectl logs -l app=%v -n %v", app, namespace)
func RunCommandInDirectoryExtended ¶
func RunCommandInDirectoryExtended(ctx context.Context, dir string, command string, args ...interface{}) error
RunCommandInDirectoryExtended runs a full command string and replaces placeholders with the arguments from the specified directory; it returns an error if command execution failed err := RunCommandInDirectoryExtended(ctx, "directory other than working dir", "kubectl logs -l app=%v -n %v", app, namespace)
func RunCommandInDirectoryExtendedCombinedStdErr ¶
func RunCommandInDirectoryExtendedCombinedStdErr(ctx context.Context, dir string, command string, args ...interface{}) error
RunCommandInDirectoryExtended runs a full command string and replaces placeholders with the arguments from the specified directory; it returns an error combined stderr if command execution failed err := RunCommandInDirectoryExtended(ctx, "directory other than working dir", "kubectl logs -l app=%v -n %v", app, namespace)
func RunCommandInDirectoryWithArgs ¶
RunCommandInDirectoryWithArgs runs a single command and passes the arguments from the specified directory; it logs a fatal on error RunCommandInDirectoryWithArgs(ctx, "directory other than working dir", "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandInDirectoryWithArgsExtended ¶
func RunCommandInDirectoryWithArgsExtended(ctx context.Context, dir string, command string, args []string) error
RunCommandInDirectoryWithArgsExtended runs a single command and passes the arguments from the specified directory; it returns an error if command execution failed err := RunCommandInDirectoryWithArgsExtended(ctx, "directory other than working dir", "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandInDirectoryWithArgsExtendedCombinedStdErr ¶
func RunCommandInDirectoryWithArgsExtendedCombinedStdErr(ctx context.Context, dir string, command string, args []string) error
RunCommandInDirectoryWithArgsExtended runs a single command and passes the arguments from the specified directory; it returns an error combined stderr if command execution failed err := RunCommandInDirectoryWithArgsExtended(ctx, "directory other than working dir", "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandWithArgs ¶
RunCommandWithArgs runs a single command and passes the arguments; it logs a fatal on error RunCommandWithArgs(ctx, "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandWithArgsExtended ¶
RunCommandWithArgsExtended runs a single command and passes the arguments; it returns an error if command execution failed err := RunCommandWithArgsExtended(ctx, "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandWithArgsExtendedCombinedStdErr ¶
func RunCommandWithArgsExtendedCombinedStdErr(ctx context.Context, command string, args []string) error
RunCommandWithArgsExtendedCombinedStdErr runs a single command and passes the arguments; it returns an error combined stderr if command execution failed err := RunCommandWithArgsExtended(ctx, "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandWithArgsExtendedWithoutLog ¶
RunCommandWithArgsExtendedWithoutLog runs a single command and passes the arguments; it returns an error if command execution failed without any log output err := RunCommandWithArgsExtendedWithoutLog(ctx, "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func RunCommandWithArgsWithoutLog ¶
RunCommandWithArgsWithoutLog runs a single command and passes the arguments; it logs a fatal on error without any log output RunCommandWithArgsWithoutLog(ctx, "kubectl", []string{"logs", "-l", "app="+app, "-n", namespace)
func SetLoggingLevelFromEnv ¶
func SetLoggingLevelFromEnv()
SetLoggingLevelFromEnv sets the logging level from which log messages and higher are outputted via envvar ZIPLINEE_LOG_LEVEL
func StringArrayContains ¶
StringArrayContains checks if an array contains a specific value
func ToLowerSnakeCase ¶
ToLowerSnakeCase turns any input string into an lower snake cased string
func ToUpperSnakeCase ¶
ToUpperSnakeCase turns any input string into an upper snake cased string
func WatchForFileChanges ¶
WatchForFileChanges waits for a change to the provided file path and then executes the function
Types ¶
type ApplicationInfo ¶
type ApplicationInfo struct {
AppGroup string
App string
Version string
Branch string
Revision string
BuildDate string
}
ApplicationInfo contains basic information about an application
func NewApplicationInfo ¶
func NewApplicationInfo(appgroup, app, version, branch, revision, buildDate string) ApplicationInfo
NewApplicationInfo returns an ApplicationInfo object
func (*ApplicationInfo) GoVersion ¶
func (ai *ApplicationInfo) GoVersion() string
GoVersion returns the golang version used to build an application
func (*ApplicationInfo) OperatingSystem ¶
func (ai *ApplicationInfo) OperatingSystem() string
OperatingSystem returns the current operating system
type DelayTypeFunc ¶
type DelayTypeFunc func(n uint, config *RetryConfig) time.Duration
DelayTypeFunc allows to override the DelayType
type IsRetryableErrorFunc ¶
IsRetryableErrorFunc allows to apply custom logic to whether an error is retryable
type RetryConfig ¶
type RetryConfig struct {
Attempts uint
DelayMillisecond int
DelayType DelayTypeFunc
LastErrorOnly bool
IsRetryableError IsRetryableErrorFunc
}
RetryConfig is used to configure the Retry function
type RetryError ¶
type RetryError []error
RetryError contains all errors for each failed attempt
func (RetryError) Error ¶
func (e RetryError) Error() string
Error method return string representation of Error It is an implementation of error interface
type RetryOption ¶
type RetryOption func(*RetryConfig)
RetryOption allows to override config
func AnyError ¶
func AnyError() RetryOption
AnyError is sets AnyErrorIsRetryable as IsRetryableError
func DelayMillisecond ¶
func DelayMillisecond(delayMilliSeconds int) RetryOption
DelayMillisecond sets delay between retries default is 100ms
func ExponentialBackOff ¶
func ExponentialBackOff() RetryOption
ExponentialBackOff sets ExponentialBackOffDelay as DelayType
func ExponentialJitterBackoff ¶
func ExponentialJitterBackoff() RetryOption
ExponentialJitterBackoff sets ExponentialJitterBackoffDelay as DelayType
func LastErrorOnly ¶
func LastErrorOnly(value bool) RetryOption
LastErrorOnly sets LastErrorOnly config value
type Semaphore ¶
type Semaphore interface {
// Acquire tries to get a lock and blocks until it does
Acquire()
// GetAcquireChannel returns the inner channel to be used to acquire a lock within a select statement
GetAcquireChannel() chan struct{}
// Release releases a lock
Release()
// Wait until all locks are released
Wait()
}